Mercurial > almixer_isolated
annotate ALmixer.c @ 7:ee50db043251
Cross-platform fixes.
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Thu, 28 Oct 2010 02:33:05 -0700 |
parents | 4b1048af7e55 |
children | c808684660a7 |
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 |
0 | 17 #include "al.h" /* OpenAL */ |
18 #include "alc.h" /* For creating OpenAL contexts */ | |
19 | |
1 | 20 #ifdef __APPLE__ |
21 /* For performance things like ALC_CONVERT_DATA_UPON_LOADING */ | |
22 /* Note: ALC_CONVERT_DATA_UPON_LOADING used to be in the alc.h header. | |
23 * But in the Tiger OpenAL 1.1 release (10.4.7 and Xcode 2.4), the | |
24 * define was moved to a new header file and renamed to | |
25 * ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING. | |
26 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
27 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
28 #include <TargetConditionals.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
29 #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
|
30 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
31 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
32 #include <OpenAL/MacOSX_OALExtensions.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
33 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
34 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
35 |
1 | 36 #endif |
37 | |
0 | 38 /* For malloc, bsearch, qsort */ |
39 #include <stdlib.h> | |
40 | |
41 /* For memcpy */ | |
42 #include <string.h> | |
43 | |
44 #if 0 | |
45 /* for toupper */ | |
46 #include <ctype.h> | |
47 /* for strrchr */ | |
48 #include <string.h> | |
49 #endif | |
50 | |
51 /* Currently used in the output debug functions */ | |
52 #include <stdio.h> | |
53 | |
54 /* My own CircularQueue implementation needed | |
55 * to work around the Nvidia problem of the | |
56 * lack of a buffer query. | |
57 */ | |
58 #include "CircularQueue.h" | |
59 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
60 #ifdef ENABLE_ALMIXER_THREADS |
0 | 61 /* 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
|
62 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
63 #include "SimpleMutex.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
64 #include "SimpleThread.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
65 typedef struct SimpleMutex SDL_mutex; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
66 typedef struct SimpleThread SDL_Thread; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
67 #define SDL_CreateMutex SimpleMutex_CreateMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
68 #define SDL_DestroyMutex SimpleMutex_DestroyMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
69 #define SDL_LockMutex SimpleMutex_LockMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
70 #define SDL_UnlockMutex SimpleMutex_UnlockMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
71 #define SDL_CreateThread SimpleThread_CreateThread |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
72 #define SDL_WaitThread SimpleThread_WaitThread |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
73 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
74 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
75 #include "SDL_thread.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
76 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
77 #endif |
0 | 78 |
79 /* Because of the API differences between the Loki | |
80 * and Creative distributions, we need to know which | |
81 * version to use. The LOKI distribution currently | |
82 * has AL_BYTE_LOKI defined in altypes.h which | |
83 * I will use as a flag to identify the distributions. | |
84 * If this is ever removed, I might revert back to the | |
85 * if defined(_WIN32) or defined(__APPLE__) test to | |
86 * identify the Creative dist. | |
87 * I'm not sure if or how the Nvidia distribution differs | |
88 * from the Creative distribution. So for | |
89 * now, the Nvidia distribution gets lumped with the | |
90 * 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
|
91 * My alGetString may be the most vulnerable. |
0 | 92 */ |
93 #ifdef AL_BYTE_LOKI | |
94 #define USING_LOKI_AL_DIST | |
95 /* This is a short term fix to get around the | |
96 * queuing problem with non-power of two buffer sizes. | |
97 * Hopefully the maintainers will fix this before | |
98 * we're ready to ship. | |
99 */ | |
100 #define ENABLE_LOKI_QUEUE_FIX_HACK | |
101 | |
102 /* The AL_GAIN in the Loki dist doesn't seem to do | |
103 * what I want/expect it to do. I want to use it for | |
104 * Fading, but it seems to work like an off/on switch. | |
105 * 0 = off, >0 = on. | |
106 * The AL_GAIN_LINEAR_LOKI switch seems to do what | |
107 * I want, so I'll redefine it here so the code is consistent | |
108 */ | |
109 /* Update: I've changed the source volume implementations | |
110 * to use AL_MAX_GAIN, so I don't think I need this block | |
111 * of code anymore. The listener uses AL_GAIN, but I | |
112 * hope they got this one right since there isn't a AL_MAX_GAIN | |
113 * for the listener. | |
114 */ | |
115 /* | |
116 #undef AL_GAIN | |
117 #include "alexttypes.h" | |
118 #define AL_GAIN AL_GAIN_LINEAR_LOKI | |
119 */ | |
120 #else | |
121 /* Might need to run other tests to figure out the DIST */ | |
122 /* I've been told that Nvidia doesn't define constants | |
123 * in the headers like Creative. Instead of | |
124 * #define AL_REFERENCE_DISTANCE 0x1020, | |
125 * Nvidia prefers you query OpenAL for a value. | |
126 * int AL_REFERENCE_DISTANCE = alGetEnumValue(ALubyte*)"AL_REFERNECE_DISTANCE"); | |
127 * So I'm assuming this means the Nvidia lacks this value. | |
128 * If this is the case, | |
129 * I guess we can use it to identify the Nvidia dist | |
130 */ | |
131 #ifdef AL_REFERENCE_DISTANCE | |
132 #define USING_CREATIVE_AL_DIST | |
133 #else | |
134 #define USING_NVIDIA_AL_DIST | |
135 #endif | |
136 #endif | |
137 | |
138 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
139 /* Need memset to zero out data */ | |
140 #include <string.h> | |
141 #endif | |
142 | |
143 | |
144 /* Seek issues for predecoded samples: | |
145 * The problem is that OpenAL makes us copy an | |
146 * entire buffer if we want to use it. This | |
147 * means we potentially have two copies of the | |
148 * same data. For predecoded data, this can be a | |
149 * large amount of memory. However, for seek | |
150 * support, I need to be able to get access to | |
151 * the original data so I can set byte positions. | |
152 * The following flags let you disable seek support | |
153 * if you don't want the memory hit, keep everything, | |
154 * or let you try to minimize the memory wasted by | |
155 * fetching it from the OpenAL buffer if needed | |
156 * and making a copy of it. | |
157 * Update: I don't think I need this flag anymore. I've made the | |
158 * effects of this user customizable by the access_data flag on load. | |
159 * If set to true, then seek and data callbacks work, with the | |
160 * cost of more memory and possibly CPU for copying the data through | |
161 * the callbacks. If false, then the extra memory is freed, but | |
162 * you don't get the features. | |
163 */ | |
164 /* | |
165 #define DISABLE_PREDECODED_SEEK | |
166 */ | |
167 /* Problem: Even though alGetBufferi(., AL_DATA, .) | |
168 * is in the Creative Programmer's reference, | |
169 * it actually isn't in the dist. (Invalid enum | |
170 * in Creative, can't compile in Loki.) | |
171 * So we have to keep it disabled | |
172 */ | |
173 #define DISABLE_SEEK_MEMORY_OPTIMIZATION | |
174 | |
175 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION | |
176 /* Needed for memcpy */ | |
177 #include <string.h> | |
178 #endif | |
179 | |
180 /* Old way of doing things: | |
181 #if defined(_WIN32) || defined(__APPLE__) | |
182 #define USING_CREATIVE_AL_DIST | |
183 #else | |
184 #define USING_LOKI_AL_DIST | |
185 #endif | |
186 */ | |
187 | |
188 /************ REMOVE ME (Don't need anymore) ********/ | |
189 #if 0 | |
190 /* Let's get fancy and see if triple buffering | |
191 * does anything good for us | |
192 * Must be 2 or more or things will probably break | |
193 */ | |
194 #define NUMBER_OF_QUEUE_BUFFERS 5 | |
195 /* This is the number of buffers that are queued up | |
196 * when play first starts up. This should be at least 1 | |
197 * and no more than NUMBER_OF_QUEUE_BUFFERS | |
198 */ | |
199 #define NUMBER_OF_START_UP_BUFFERS 2 | |
200 #endif | |
201 /************ END REMOVE ME (Don't need anymore) ********/ | |
202 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
203 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
204 #include "tErrorLib.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
205 static TErrorPool* s_ALmixerErrorPool = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
206 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
207 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
208 static ALboolean ALmixer_Initialized = 0; |
0 | 209 /* 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
|
210 static ALuint ALmixer_Frequency_global = ALMIXER_DEFAULT_FREQUENCY; |
0 | 211 |
212 /* Will be initialized in Init */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
213 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
|
214 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
|
215 static ALuint Is_Playing_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
216 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
217 #ifdef ENABLE_ALMIXER_THREADS |
0 | 218 /* This is for a simple lock system. It is not meant to be good, |
219 * but just sufficient to minimize/avoid threading issues | |
220 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
221 static SDL_mutex* s_simpleLock; |
0 | 222 static SDL_Thread* Stream_Thread_global = NULL; |
223 #endif | |
224 | |
225 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
226 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
227 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
|
228 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
229 static void (*alcMacOSXMixerOutputRateProcPtr)(const ALdouble) = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
230 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
231 if(NULL == alcMacOSXMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
232 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
233 alcMacOSXMixerOutputRateProcPtr = alGetProcAddress((const ALCchar*) "alcMacOSXMixerOutputRate"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
234 } |
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(sample_rate); |
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 return; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
244 ALdouble Internal_alcMacOSXGetMixerOutputRate() |
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 static ALdouble (*alcMacOSXGetMixerOutputRateProcPtr)(void) = NULL; |
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 if(NULL == alcMacOSXGetMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
249 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
250 alcMacOSXGetMixerOutputRateProcPtr = alGetProcAddress((const ALCchar*) "alcMacOSXGetMixerOutputRate"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
251 } |
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 return alcMacOSXGetMixerOutputRateProcPtr(); |
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 return 0.0; |
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 #endif |
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 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
263 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
264 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
265 #include <QuartzCore/QuartzCore.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
266 #include <unistd.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
267 static CFTimeInterval s_ticksBaseTime = 0.0; |
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 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
270 #define WIN32_LEAN_AND_MEAN |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
271 #include <windows.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
272 #include <winbase.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
273 LARGE_INTEGER s_hiResTicksPerSecond; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
274 double s_hiResSecondsPerTick; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
275 LARGE_INTEGER s_ticksBaseTime; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
276 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
277 #include <unistd.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
278 #include <time.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
279 static struct timespec s_ticksBaseTime; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
280 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
281 static void ALmixer_InitTime() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
282 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
283 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
284 s_ticksBaseTime = CACurrentMediaTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
285 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
286 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
287 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
|
288 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
|
289 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
290 QueryPerformanceCounter(&s_ticksBaseTime); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
291 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
|
292 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
293 else |
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 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
|
296 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
|
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 /* clock_gettime is POSIX.1-2001 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
300 clock_gettime(CLOCK_MONOTONIC, &s_ticksBaseTime); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
301 #endif |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
304 static ALuint ALmixer_GetTicks() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
305 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
306 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
307 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
|
308 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
309 LARGE_INTEGER current_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
310 QueryPerformanceCounter(¤t_time); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
311 return (ALuint)((current_time.QuadPart - s_ticksBaseTime.QuadPart) * 1000 * s_hiResSecondsPerTick); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
312 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
313 #else /* assuming POSIX */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
314 /* clock_gettime is POSIX.1-2001 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
315 struct timespec current_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
316 clock_gettime(CLOCK_MONOTONIC, ¤t_time); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
317 return (ALuint)((current_time.tv_sec - s_ticksBaseTime.tv_sec)*1000.0 + (current_time.tv_nec - s_ticksBaseTime.tv_nsec) / 1000000); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
318 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
319 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
320 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
|
321 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
322 #if defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
323 Sleep(milliseconds_delay); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
324 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
325 usleep(milliseconds_delay); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
326 #endif |
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 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
329 #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
|
330 #define ALmixer_GetTicks SDL_GetTicks |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
331 #define ALmixer_Delay SDL_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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
335 |
0 | 336 /* If ENABLE_PARANOID_SIGNEDNESS_CHECK is used, |
337 * these values will be reset on Init() | |
338 * Consider these values Read-Only. | |
339 */ | |
340 | |
341 #define ALMIXER_SIGNED_VALUE 127 | |
342 #define ALMIXER_UNSIGNED_VALUE 255 | |
343 | |
344 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
345 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
|
346 static ALushort SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; |
0 | 347 #else |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
348 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
|
349 static const ALushort SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; |
0 | 350 #endif |
351 | |
1 | 352 |
353 /* This can be private instead of being in the header now that I moved | |
354 * ALmixer_Data inside here. | |
355 */ | |
356 typedef struct ALmixer_Buffer_Map ALmixer_Buffer_Map; | |
357 | |
358 | |
359 struct ALmixer_Data | |
360 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
361 ALboolean decoded_all; /* dictates different behaviors */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
362 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
|
363 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
364 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
|
365 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
|
366 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
367 ALuint total_bytes; /* For predecoded */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
368 ALuint loaded_bytes; /* For predecoded (for seek) */ |
1 | 369 |
370 Sound_Sample* sample; /* SDL_Sound provides the data */ | |
371 ALuint* buffer; /* array of OpenAL buffers (at least 1 for predecoded) */ | |
372 | |
373 /* Needed for streamed buffers */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
374 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
|
375 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
|
376 ALuint num_buffers_in_use; /* number of buffers in use */ |
1 | 377 |
378 /* This stuff is for streamed buffers that require data access */ | |
379 ALmixer_Buffer_Map* buffer_map_list; /* translate ALbuffer to index | |
380 and holds pointer to copy of data for | |
381 data access */ | |
382 ALuint current_buffer; /* The current playing buffer */ | |
383 | |
384 /* Nvidia distribution refuses to recognize a simple buffer query command | |
385 * unlike all other distributions. It's forcing me to redo the code | |
386 * to accomodate this Nvidia flaw by making me maintain a "best guess" | |
387 * copy of what I think the buffer queue state looks like. | |
388 * A circular queue would a helpful data structure for this task, | |
389 * but I wanted to avoid making an additional header requirement, | |
390 * so I'm making it a void* | |
391 */ | |
392 void* circular_buffer_queue; | |
393 | |
394 | |
395 }; | |
396 | |
0 | 397 static struct ALmixer_Channel |
398 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
399 ALboolean channel_in_use; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
400 ALboolean callback_update; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
401 ALboolean needs_stream; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
402 ALboolean halted; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
403 ALboolean paused; |
0 | 404 ALuint alsource; |
405 ALmixer_Data* almixer_data; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
406 ALint loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
407 ALint expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
408 ALuint start_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
409 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
410 ALboolean fade_enabled; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
411 ALuint fade_expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
412 ALuint fade_start_time; |
0 | 413 ALfloat fade_inv_time; |
414 ALfloat fade_start_volume; | |
415 ALfloat fade_end_volume; | |
416 ALfloat max_volume; | |
417 ALfloat min_volume; | |
418 | |
419 /* Do we need other flags? | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
420 ALbyte *samples; |
0 | 421 int volume; |
422 int looping; | |
423 int tag; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
424 ALuint expire; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
425 ALuint start_time; |
0 | 426 Mix_Fading fading; |
427 int fade_volume; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
428 ALuint fade_length; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
429 ALuint ticks_fade; |
0 | 430 effect_info *effects; |
431 */ | |
432 } *ALmixer_Channel_List = NULL; | |
433 | |
1 | 434 struct ALmixer_Buffer_Map |
435 { | |
436 ALuint albuffer; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
437 ALint index; /* might not need */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
438 ALbyte* data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
439 ALuint num_bytes; |
1 | 440 }; |
441 | |
0 | 442 /* This will be used to find a channel if the user supplies a source */ |
443 typedef struct Source_Map | |
444 { | |
445 ALuint source; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
446 ALint channel; |
0 | 447 } Source_Map; |
448 /* Keep an array of all sources with their associated channel */ | |
449 static Source_Map* Source_Map_List; | |
450 | |
451 static int Compare_Source_Map(const void* a, const void* b) | |
452 { | |
453 return ( ((Source_Map*)a)->source - ((Source_Map*)b)->source ); | |
454 } | |
455 | |
456 /* Sort by channel instead of source */ | |
457 static int Compare_Source_Map_by_channel(const void* a, const void* b) | |
458 { | |
459 return ( ((Source_Map*)a)->channel - ((Source_Map*)b)->channel ); | |
460 } | |
461 | |
462 /* Compare by albuffer */ | |
463 static int Compare_Buffer_Map(const void* a, const void* b) | |
464 { | |
1 | 465 return ( ((ALmixer_Buffer_Map*)a)->albuffer - ((ALmixer_Buffer_Map*)b)->albuffer ); |
0 | 466 } |
467 | |
468 /* This is for the user defined callback via | |
469 * ALmixer_ChannelFinished() | |
470 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
471 static void (*Channel_Done_Callback)(ALint which_channel, ALuint al_source, ALmixer_Data* almixer_data, ALboolean finished_naturally, void* user_data) = NULL; |
0 | 472 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
|
473 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 | 474 static void* Channel_Data_Callback_Userdata = NULL; |
0 | 475 |
476 | |
477 static void PrintQueueStatus(ALuint source) | |
478 { | |
479 ALint buffers_queued = 0; | |
480 ALint buffers_processed = 0; | |
481 ALenum error; | |
482 | |
483 /* Get the number of buffers still queued */ | |
484 alGetSourcei( | |
485 source, | |
486 AL_BUFFERS_QUEUED, | |
487 &buffers_queued | |
488 ); | |
489 | |
490 if((error = alGetError()) != AL_NO_ERROR) | |
491 { | |
492 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
|
493 alGetString(error)); |
0 | 494 } |
495 /* Get the number of buffers processed | |
496 * so we know if we need to refill | |
497 */ | |
498 alGetSourcei( | |
499 source, | |
500 AL_BUFFERS_PROCESSED, | |
501 &buffers_processed | |
502 ); | |
503 if((error = alGetError()) != AL_NO_ERROR) | |
504 { | |
505 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
|
506 alGetString(error)); |
0 | 507 } |
508 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
509 /* |
0 | 510 fprintf(stderr, "For source: %d, buffers_queued=%d, buffers_processed=%d\n", |
511 source, | |
512 buffers_queued, | |
513 buffers_processed); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
514 */ |
0 | 515 } |
516 | |
517 | |
518 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
519 static void Init_Channel(ALint channel) |
0 | 520 { |
521 ALmixer_Channel_List[channel].channel_in_use = 0; | |
522 ALmixer_Channel_List[channel].callback_update = 0; | |
523 ALmixer_Channel_List[channel].needs_stream = 0; | |
524 ALmixer_Channel_List[channel].paused = 0; | |
525 ALmixer_Channel_List[channel].halted = 0; | |
526 ALmixer_Channel_List[channel].loops = 0; | |
527 | |
528 ALmixer_Channel_List[channel].expire_ticks = 0; | |
529 ALmixer_Channel_List[channel].start_time = 0; | |
530 | |
531 ALmixer_Channel_List[channel].fade_enabled = 0; | |
532 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
533 ALmixer_Channel_List[channel].fade_start_time = 0; | |
534 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
535 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
536 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
537 ALmixer_Channel_List[channel].max_volume = 1.0f; | |
538 ALmixer_Channel_List[channel].min_volume = 0.0f; | |
539 | |
540 ALmixer_Channel_List[channel].almixer_data = NULL; | |
541 } | |
542 /* Quick helper function to clean up a channel | |
543 * after it's done playing */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
544 static void Clean_Channel(ALint channel) |
0 | 545 { |
546 ALenum error; | |
547 ALmixer_Channel_List[channel].channel_in_use = 0; | |
548 ALmixer_Channel_List[channel].callback_update = 0; | |
549 ALmixer_Channel_List[channel].needs_stream = 0; | |
550 ALmixer_Channel_List[channel].paused = 0; | |
551 ALmixer_Channel_List[channel].halted = 0; | |
552 ALmixer_Channel_List[channel].loops = 0; | |
553 | |
554 | |
555 ALmixer_Channel_List[channel].expire_ticks = 0; | |
556 ALmixer_Channel_List[channel].start_time = 0; | |
557 | |
558 ALmixer_Channel_List[channel].fade_enabled = 0; | |
559 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
560 ALmixer_Channel_List[channel].fade_start_time = 0; | |
561 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
562 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
563 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
564 | |
565 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MAX_GAIN, | |
566 ALmixer_Channel_List[channel].max_volume); | |
567 | |
568 if((error = alGetError()) != AL_NO_ERROR) | |
569 { | |
570 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
|
571 alGetString(error)); |
0 | 572 } |
573 | |
574 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MIN_GAIN, | |
575 ALmixer_Channel_List[channel].min_volume); | |
576 if((error = alGetError()) != AL_NO_ERROR) | |
577 { | |
578 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
|
579 alGetString(error)); |
0 | 580 } |
581 | |
582 if(ALmixer_Channel_List[channel].almixer_data != NULL) | |
583 { | |
584 if(ALmixer_Channel_List[channel].almixer_data->in_use > 0) | |
585 { | |
586 ALmixer_Channel_List[channel].almixer_data->in_use--; | |
587 } | |
588 } | |
589 /* Needed to determine if rewind is needed, can't reset */ | |
590 /* | |
591 ALmixer_Channel_List[channel].almixer_data->eof = 0; | |
592 */ | |
593 | |
594 ALmixer_Channel_List[channel].almixer_data = NULL; | |
595 } | |
596 | |
597 | |
598 #if 0 | |
599 /* Not needed anymore because not doing any fileext checks. | |
600 * | |
601 * Unfortunately, strcasecmp isn't portable so here's a | |
602 * reimplementation of it (taken from SDL_sound) | |
603 */ | |
604 static int ALmixer_strcasecmp(const char* x, const char* y) | |
605 { | |
606 int ux, uy; | |
607 | |
608 if (x == y) /* same pointer? Both NULL? */ | |
609 return(0); | |
610 | |
611 if (x == NULL) | |
612 return(-1); | |
613 | |
614 if (y == NULL) | |
615 return(1); | |
616 | |
617 do | |
618 { | |
619 ux = toupper((int) *x); | |
620 uy = toupper((int) *y); | |
621 if (ux > uy) | |
622 return(1); | |
623 else if (ux < uy) | |
624 return(-1); | |
625 x++; | |
626 y++; | |
627 } while ((ux) && (uy)); | |
628 | |
629 return(0); | |
630 } | |
631 #endif | |
632 | |
633 | |
634 /* What shoud this return? | |
635 * 127 for signed, 255 for unsigned | |
636 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
637 static ALubyte GetSignednessValue(ALushort format) |
0 | 638 { |
639 switch(format) | |
640 { | |
641 case AUDIO_U8: | |
642 case AUDIO_U16LSB: | |
643 case AUDIO_U16MSB: | |
644 return ALMIXER_UNSIGNED_VALUE; | |
645 break; | |
646 case AUDIO_S8: | |
647 case AUDIO_S16LSB: | |
648 case AUDIO_S16MSB: | |
649 return ALMIXER_SIGNED_VALUE; | |
650 break; | |
651 default: | |
652 return 0; | |
653 } | |
654 return 0; | |
655 } | |
656 | |
657 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
658 static ALubyte GetBitDepth(ALushort format) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
659 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
660 ALubyte bit_depth = 16; |
0 | 661 |
662 switch(format) | |
663 { | |
664 case AUDIO_U8: | |
665 case AUDIO_S8: | |
666 bit_depth = 8; | |
667 break; | |
668 | |
669 case AUDIO_U16LSB: | |
670 /* | |
671 case AUDIO_U16: | |
672 */ | |
673 case AUDIO_S16LSB: | |
674 /* | |
675 case AUDIO_S16: | |
676 */ | |
677 case AUDIO_U16MSB: | |
678 case AUDIO_S16MSB: | |
679 /* | |
680 case AUDIO_U16SYS: | |
681 case AUDIO_S16SYS: | |
682 */ | |
683 bit_depth = 16; | |
684 break; | |
685 default: | |
686 bit_depth = 0; | |
687 } | |
688 return bit_depth; | |
689 } | |
690 | |
691 /* Need to translate between SDL/SDL_Sound audiospec | |
692 * and OpenAL conventions */ | |
693 static ALenum TranslateFormat(Sound_AudioInfo* info) | |
694 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
695 ALubyte bit_depth; |
0 | 696 |
697 bit_depth = GetBitDepth(info->format); | |
698 if(0 == bit_depth) | |
699 { | |
700 fprintf(stderr, "Warning: Unknown bit depth. Setting to 16\n"); | |
701 bit_depth = 16; | |
702 } | |
703 | |
704 if(2 == info->channels) | |
705 { | |
706 if(16 == bit_depth) | |
707 { | |
708 return AL_FORMAT_STEREO16; | |
709 } | |
710 else | |
711 { | |
712 return AL_FORMAT_STEREO8; | |
713 } | |
714 } | |
715 else | |
716 { | |
717 if(16 == bit_depth) | |
718 { | |
719 return AL_FORMAT_MONO16; | |
720 } | |
721 else | |
722 { | |
723 return AL_FORMAT_MONO8; | |
724 } | |
725 } | |
726 /* Make compiler happy. Shouldn't get here */ | |
727 return AL_FORMAT_STEREO16; | |
728 } | |
729 | |
1 | 730 |
731 /* This will compute the total playing time | |
732 * based upon the number of bytes and audio info. | |
733 * (In prinicple, it should compute the time for any given length) | |
734 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
735 static ALuint Compute_Total_Time_Decomposed(ALuint bytes_per_sample, ALuint frequency, ALubyte channels, size_t total_bytes) |
1 | 736 { |
737 double total_sec; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
738 ALuint total_msec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
739 ALuint bytes_per_sec; |
1 | 740 |
741 if(0 == total_bytes) | |
742 { | |
743 return 0; | |
744 } | |
745 /* To compute Bytes per second, do | |
746 * samples_per_sec * bytes_per_sample * number_of_channels | |
747 */ | |
748 bytes_per_sec = frequency * bytes_per_sample * channels; | |
749 | |
750 /* Now to get total time (sec), do | |
751 * total_bytes / bytes_per_sec | |
752 */ | |
753 total_sec = total_bytes / (double)bytes_per_sec; | |
754 | |
755 /* Now convert seconds to milliseconds | |
756 * Add .5 to the float to do rounding before the final cast | |
757 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
758 total_msec = (ALuint) ( (total_sec * 1000) + 0.5 ); |
1 | 759 /* |
760 fprintf(stderr, "freq=%d, bytes_per_sample=%d, channels=%d, total_msec=%d\n", frequency, bytes_per_sample, channels, total_msec); | |
761 */ | |
762 return total_msec; | |
763 } | |
764 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
765 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
|
766 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
767 ALuint bytes_per_sample; |
1 | 768 |
769 if(0 == total_bytes) | |
770 { | |
771 return 0; | |
772 } | |
773 /* 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
|
774 * 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
|
775 * 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
|
776 * 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
|
777 * 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
|
778 * 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
|
779 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
780 bytes_per_sample = (ALuint) ((info->format & 0xFF) / 8); |
1 | 781 |
782 return Compute_Total_Time_Decomposed(bytes_per_sample, info->rate, info->channels, total_bytes); | |
783 } /* End Compute_Total_Time */ | |
784 | |
785 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
786 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
|
787 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
788 double total_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
789 ALuint bytes_per_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
790 size_t total_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
791 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
792 if(0 >= 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 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
795 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
796 /* To compute Bytes per second, do |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
797 * 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
|
798 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
799 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
|
800 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
801 /* convert milliseconds to seconds */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
802 total_sec = total_msec / 1000.0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
803 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
804 /* Now to get total bytes */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
805 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
|
806 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
807 /* 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
|
808 */ |
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 return total_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
811 } |
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 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
|
814 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
815 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
816 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
817 if(0 >= total_msec) |
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 return 0; |
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 /* 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
|
822 * 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
|
823 * 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
|
824 * 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
|
825 * 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
|
826 * 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
|
827 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
828 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
|
829 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
830 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
|
831 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
832 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
833 /* 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
|
834 * 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
|
835 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
836 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
|
837 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
838 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
839 ALuint bytes_per_frame; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
840 size_t evenly_divisible_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
841 size_t remainder_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
842 size_t return_bytes; |
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 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
|
845 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
846 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
|
847 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
848 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
|
849 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
850 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
|
851 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
|
852 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
853 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
|
854 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
855 /* 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
|
856 * 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
|
857 * 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
|
858 * 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
|
859 * 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
|
860 * 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
|
861 * 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
|
862 * 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
|
863 * 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
|
864 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
865 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
866 return_bytes += 64; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
867 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
868 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
869 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
|
870 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
871 return return_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
872 |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
876 |
1 | 877 |
0 | 878 /**************** REMOVED ****************************/ |
879 /* This was removed because I originally thought | |
880 * OpenAL could return a pointer to the buffer data, | |
881 * but I was wrong. If something like that is ever | |
882 * implemented, then this might become useful. | |
883 */ | |
884 #if 0 | |
885 /* Reconstruct_Sound_Sample and Set_AudioInfo only | |
886 * are needed if the Seek memory optimization is | |
887 * used. Also, the Loki dist doesn't seem to support | |
888 * AL_DATA which I need for it. | |
889 */ | |
890 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION | |
891 | |
892 static void Set_AudioInfo(Sound_AudioInfo* info, ALint frequency, ALint bits, ALint channels) | |
893 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
894 info->rate = (ALuint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
895 info->channels = (ALubyte)channels; |
0 | 896 |
897 /* Not sure if it should be signed or unsigned. Hopefully | |
898 * that detail won't be needed. | |
899 */ | |
900 if(8 == bits) | |
901 { | |
902 info->format = AUDIO_U8; | |
903 } | |
904 else | |
905 { | |
906 info->format = AUDIO_U16SYS; | |
907 } | |
908 fprintf(stderr, "Audio info: freq=%d, chan=%d, format=%d\n", | |
909 info->rate, info->channels, info->format); | |
910 | |
911 } | |
912 | |
913 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
914 static ALint Reconstruct_Sound_Sample(ALmixer_Data* data) |
0 | 915 { |
916 ALenum error; | |
917 ALint* data_from_albuffer; | |
918 ALint freq; | |
919 ALint bits; | |
920 ALint channels; | |
921 ALint size; | |
922 | |
923 /* Create memory all initiallized to 0. */ | |
924 data->sample = (Sound_Sample*)calloc(1, sizeof(Sound_Sample)); | |
925 if(NULL == data->sample) | |
926 { | |
927 ALmixer_SetError("Out of memory for Sound_Sample"); | |
928 return -1; | |
929 } | |
930 | |
931 /* Clear errors */ | |
932 alGetError(); | |
933 | |
934 alGetBufferi(data->buffer[0], AL_FREQUENCY, &freq); | |
935 if((error = alGetError()) != AL_NO_ERROR) | |
936 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
937 ALmixer_SetError("alGetBufferi(AL_FREQUENCY): %s", alGetString(error) ); |
0 | 938 free(data->sample); |
939 data->sample = NULL; | |
940 return -1; | |
941 } | |
942 | |
943 alGetBufferi(data->buffer[0], AL_BITS, &bits); | |
944 if((error = alGetError()) != AL_NO_ERROR) | |
945 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
946 ALmixer_SetError("alGetBufferi(AL_BITS): %s", alGetString(error) ); |
0 | 947 free(data->sample); |
948 data->sample = NULL; | |
949 return -1; | |
950 } | |
951 | |
952 alGetBufferi(data->buffer[0], AL_CHANNELS, &channels); | |
953 if((error = alGetError()) != AL_NO_ERROR) | |
954 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
955 ALmixer_SetError("alGetBufferi(AL_CHANNELS): %s", alGetString(error) ); |
0 | 956 free(data->sample); |
957 data->sample = NULL; | |
958 return -1; | |
959 } | |
960 | |
961 alGetBufferi(data->buffer[0], AL_SIZE, &size); | |
962 if((error = alGetError()) != AL_NO_ERROR) | |
963 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
964 ALmixer_SetError("alGetBufferi(AL_SIZE): %s", alGetString(error) ); |
0 | 965 free(data->sample); |
966 data->sample = NULL; | |
967 return -1; | |
968 } | |
969 | |
970 alGetBufferi(data->buffer[0], AL_DATA, data_from_albuffer); | |
971 if((error = alGetError()) != AL_NO_ERROR) | |
972 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
973 ALmixer_SetError("alGetBufferi(AL_DATA): %s", alGetString(error) ); |
0 | 974 free(data->sample); |
975 data->sample = NULL; | |
976 return -1; | |
977 } | |
978 | |
979 if(size <= 0) | |
980 { | |
981 ALmixer_SetError("No data in al buffer"); | |
982 free(data->sample); | |
983 data->sample = NULL; | |
984 return -1; | |
985 } | |
986 | |
987 /* Now that we have all the attributes, we need to | |
988 * allocate memory for the buffer and reconstruct | |
989 * the AudioInfo attributes. | |
990 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
991 data->sample->buffer = malloc(size*sizeof(ALbyte)); |
0 | 992 if(NULL == data->sample->buffer) |
993 { | |
994 ALmixer_SetError("Out of memory for sample->buffer"); | |
995 free(data->sample); | |
996 data->sample = NULL; | |
997 return -1; | |
998 } | |
999 | |
1000 memcpy(data->sample->buffer, data_from_albuffer, size); | |
1001 data->sample->buffer_size = size; | |
1002 | |
1003 /* Fill up the Sound_AudioInfo structures */ | |
1004 Set_AudioInfo(&data->sample->desired, freq, bits, channels); | |
1005 Set_AudioInfo(&data->sample->actual, freq, bits, channels); | |
1006 | |
1007 return 0; | |
1008 } | |
1009 | |
1010 #endif /* End DISABLE_SEEK_MEMORY_OPTIMIZATION */ | |
1011 #endif | |
1012 /*************** END REMOVED *************************/ | |
1013 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1014 static void Invoke_Channel_Done_Callback(ALint which_channel, ALboolean did_finish_naturally) |
0 | 1015 { |
1016 if(NULL == Channel_Done_Callback) | |
1017 { | |
1018 return; | |
1019 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1020 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
|
1021 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1022 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1023 static ALint LookUpBuffer(ALuint buffer, ALmixer_Buffer_Map* buffer_map_list, ALuint num_items_in_list) |
0 | 1024 { |
1025 /* Only the first value is used for the key */ | |
1 | 1026 ALmixer_Buffer_Map key = { 0, 0, NULL, 0 }; |
1027 ALmixer_Buffer_Map* found_item = NULL; | |
0 | 1028 key.albuffer = buffer; |
1029 | |
1030 /* Use the ANSI C binary search feature (yea!) */ | |
1 | 1031 found_item = (ALmixer_Buffer_Map*)bsearch(&key, buffer_map_list, num_items_in_list, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 1032 if(NULL == found_item) |
1033 { | |
1034 ALmixer_SetError("Can't find buffer"); | |
1035 return -1; | |
1036 } | |
1037 return found_item->index; | |
1038 } | |
1039 | |
1040 | |
1041 /* FIXME: Need to pass back additional info to be useful. | |
1042 * Bit rate, stereo/mono (num chans), time in msec? | |
1043 * Precoded/streamed flag so user can plan for future data? | |
1044 */ | |
1 | 1045 /* |
1046 * channels: 1 for mono, 2 for stereo | |
1047 * | |
1048 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1049 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
|
1050 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1051 ALboolean is_unsigned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1052 ALubyte bits_per_sample = GetBitDepth(format); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1053 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1054 ALuint length_in_msec; |
1 | 1055 |
1056 if(GetSignednessValue(format) == ALMIXER_UNSIGNED_VALUE) | |
1057 { | |
1058 is_unsigned = 1; | |
1059 } | |
1060 else | |
1061 { | |
1062 is_unsigned = 0; | |
1063 } | |
1064 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1065 bytes_per_sample = (ALuint) (bits_per_sample / 8); |
1 | 1066 |
1067 length_in_msec = Compute_Total_Time_Decomposed(bytes_per_sample, frequency, channels, num_bytes); | |
1068 | |
0 | 1069 /* |
1070 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); | |
1071 */ | |
1072 if(NULL == Channel_Data_Callback) | |
1073 { | |
1074 return; | |
1075 } | |
1 | 1076 /* |
1077 * Channel_Data_Callback(which_channel, data, num_bytes, frequency, channels, GetBitDepth(format), format, decode_mode_is_predecoded); | |
1078 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1079 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
|
1080 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1081 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1082 static void Invoke_Predecoded_Channel_Data_Callback(ALint channel, ALmixer_Data* data) |
0 | 1083 { |
1084 if(NULL == data->sample) | |
1085 { | |
1086 return; | |
1087 } | |
1088 /* The buffer position is complicated because if the current data was seeked, | |
1089 * we must adjust the buffer to the seek position | |
1090 */ | |
1091 Invoke_Channel_Data_Callback(channel, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1092 (((ALbyte*) data->sample->buffer) + (data->total_bytes - data->loaded_bytes) ), |
0 | 1093 data->loaded_bytes, |
1094 data->sample->desired.rate, | |
1095 data->sample->desired.channels, | |
1096 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1097 AL_TRUE |
0 | 1098 ); |
1099 } | |
1100 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1101 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
|
1102 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1103 ALint index; |
0 | 1104 if(NULL == data->buffer_map_list) |
1105 { | |
1106 return; | |
1107 } | |
1108 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1109 /* This should catch the case where all buffers are unqueued | |
1110 * and the "current" buffer is id: 0 | |
1111 */ | |
1112 if(-1 == index) | |
1113 { | |
1114 return; | |
1115 } | |
1116 Invoke_Channel_Data_Callback(channel, | |
1117 data->buffer_map_list[index].data, | |
1118 data->buffer_map_list[index].num_bytes, | |
1119 data->sample->desired.rate, | |
1120 data->sample->desired.channels, | |
1121 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1122 AL_FALSE |
0 | 1123 ); |
1124 } | |
1125 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1126 /* Converts milliseconds to byte positions. |
0 | 1127 * This is needed for seeking on predecoded samples |
1128 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1129 static ALuint Convert_Msec_To_Byte_Pos(Sound_AudioInfo *info, ALuint ms) |
0 | 1130 { |
1131 float frames_per_ms; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1132 ALuint frame_offset; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1133 ALuint frame_size; |
0 | 1134 if(info == NULL) |
1135 { | |
1136 fprintf(stderr, "Error, info is NULL\n"); | |
1137 } | |
1138 | |
1139 /* "frames" == "sample frames" */ | |
1140 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
|
1141 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
|
1142 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
|
1143 return frame_offset * frame_size; |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1144 } |
0 | 1145 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1146 static ALint Set_Predecoded_Seek_Position(ALmixer_Data* data, ALuint byte_position) |
0 | 1147 { |
1148 ALenum error; | |
1149 /* clear error */ | |
1150 alGetError(); | |
1151 | |
1152 /* Is it greater than, or greater-than or equal to ?? */ | |
1153 if(byte_position > data->total_bytes) | |
1154 { | |
1155 /* 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
|
1156 /* |
0 | 1157 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
|
1158 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1159 |
0 | 1160 /* In case the below thing doesn't work, |
1161 * just rewind the whole thing. | |
1162 * | |
1163 alBufferData(data->buffer[0], | |
1164 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1165 (ALbyte*) data->sample->buffer, |
0 | 1166 data->total_bytes, |
1167 data->sample->desired.rate | |
1168 ); | |
1169 */ | |
1170 | |
1171 /* I was trying to set to the end, (1 byte remaining), | |
1172 * but I was getting freezes. I'm thinking it might be | |
1173 * another Power of 2 bug in the Loki dist. I tried 2, | |
1174 * and it still hung. 4 didn't hang, but I got a clip | |
1175 * artifact. 8 seemed to work okay. | |
1176 */ | |
1177 alBufferData(data->buffer[0], | |
1178 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1179 (((ALbyte*) data->sample->buffer) + (data->total_bytes - 8) ), |
0 | 1180 8, |
1181 data->sample->desired.rate | |
1182 ); | |
1183 if( (error = alGetError()) != AL_NO_ERROR) | |
1184 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1185 ALmixer_SetError("Can't seek past end and alBufferData failed: %s\n", alGetString(error)); |
0 | 1186 return -1; |
1187 } | |
1188 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1189 * query command to work because I don't know if it will mutilate the | |
1190 * size for its own purposes or return the original size | |
1191 */ | |
1192 data->loaded_bytes = 8; | |
1193 | |
1194 /* Not sure if this should be an error or not */ | |
1195 /* | |
1196 ALmixer_SetError("Can't Seek past end"); | |
1197 return -1; | |
1198 */ | |
1199 return 0; | |
1200 } | |
1201 | |
1202 alBufferData(data->buffer[0], | |
1203 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1204 &(((ALbyte*)data->sample->buffer)[byte_position]), |
0 | 1205 data->total_bytes - byte_position, |
1206 data->sample->desired.rate | |
1207 ); | |
1208 if( (error = alGetError()) != AL_NO_ERROR) | |
1209 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1210 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1211 return -1; |
1212 } | |
1213 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1214 * query command to work because I don't know if it will mutilate the | |
1215 * size for its own purposes or return the original size | |
1216 */ | |
1217 data->loaded_bytes = data->total_bytes - byte_position; | |
1218 | |
1219 return 0; | |
1220 } | |
1221 | |
1222 /* Because we have multiple queue buffers and OpenAL won't let | |
1223 * us access them, we need to keep copies of each buffer around | |
1224 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1225 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
|
1226 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1227 ALint index; |
0 | 1228 /* We only want to copy if access_data is true. |
1229 * This is determined by whether memory has been | |
1230 * allocated in the buffer_map_list or not | |
1231 */ | |
1232 if(NULL == data->buffer_map_list) | |
1233 { | |
1234 return -1; | |
1235 } | |
1236 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1237 if(-1 == index) | |
1238 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1239 /* |
0 | 1240 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
|
1241 */ |
0 | 1242 return -1; |
1243 } | |
1244 /* Copy the data to the access buffer */ | |
1245 memcpy(data->buffer_map_list[index].data, data->sample->buffer, num_bytes); | |
1246 data->buffer_map_list[index].num_bytes = data->sample->buffer_size; | |
1247 | |
1248 return 0; | |
1249 } | |
1250 | |
1251 | |
1252 /* For streamed data, gets more data | |
1253 * and prepares it in the active Mix_chunk | |
1254 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1255 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
|
1256 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1257 ALuint bytes_decoded; |
0 | 1258 ALenum error; |
1259 if(NULL == data) | |
1260 { | |
1261 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1262 return 0; | |
1263 } | |
1264 | |
1265 bytes_decoded = Sound_Decode(data->sample); | |
1266 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1267 { | |
1268 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1269 ALmixer_SetError(Sound_GetError()); | |
1270 /* Force cleanup through FreeData | |
1271 Sound_FreeSample(data->sample); | |
1272 */ | |
1273 return 0; | |
1274 } | |
1275 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1276 /* 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
|
1277 |
0 | 1278 /* Don't forget to add check for EOF */ |
1279 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1280 if(0 == bytes_decoded) | |
1281 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1282 data->eof = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1283 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1284 #if 0 |
0 | 1285 fprintf(stderr, "Hit eof while trying to buffer\n"); |
1286 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1287 { | |
1288 fprintf(stderr, "\tEOF flag\n"); | |
1289 } | |
1290 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1291 { | |
1292 fprintf(stderr, "\tCanSeek flag\n"); | |
1293 } | |
1294 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1295 { | |
1296 fprintf(stderr, "\tEAGAIN flag\n"); | |
1297 } | |
1298 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1299 { | |
1300 fprintf(stderr, "\tNONE flag\n"); | |
1301 } | |
1302 #endif | |
1303 return 0; | |
1304 } | |
1305 | |
1306 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
1307 /******* REMOVE ME ********************************/ | |
1308 /***************** ANOTHER EXPERIEMENT *******************/ | |
1309 /* The PROBLEM: It seems that the Loki distribution has problems | |
1310 * with Queuing when the buffer size is not a power of two | |
1311 * and additional buffers must come after it. | |
1312 * The behavior is inconsistent, but one of several things | |
1313 * usually happens: | |
1314 * Playback is normal | |
1315 * Playback immediately stops after the non-pow2 buffer | |
1316 * Playback gets distorted on the non-pow2 buffer | |
1317 * The entire program segfaults. | |
1318 * The workaround is to always specify a power of two buffer size | |
1319 * and hope that SDL_sound always fill it. (By lucky coincidence, | |
1320 * I already submitted the Ogg fix.) However, this won't catch | |
1321 * cases where a loop happens because the read at the end of the | |
1322 * file is typically less than the buffer size. | |
1323 * | |
1324 * This fix addresses this issue, however it may break in | |
1325 * other conditions. Always decode in buffer sizes of powers of 2. | |
1326 * | |
1327 * The HACK: | |
1328 * If the buffer is short, try filling it up with 0's | |
1329 * to meet the user requested buffer_size which | |
1330 * is probably a nice number OpenAL likes, in | |
1331 * hopes to avoid a possible Loki bug with | |
1332 * short buffers. If looping (which is the main | |
1333 * reason for this), the negative side effect is | |
1334 * that it may take longer for the loop to start | |
1335 * because it must play dead silence. Or if the decoder | |
1336 * doesn't guarantee to return the requested bytes | |
1337 * (like Ogg), then you will get breakup in between | |
1338 * packets. | |
1339 */ | |
1340 if( (bytes_decoded) < data->sample->buffer_size) | |
1341 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1342 ALubyte bit_depth; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1343 ALubyte signedness_value; |
0 | 1344 int silence_value; |
1345 /* Crap, memset value needs to be the "silent" value, | |
1346 * but it will differ for signed/unsigned and bit depth | |
1347 */ | |
1348 bit_depth = GetBitDepth(data->sample->desired.format); | |
1349 signedness_value = GetSignednessValue(data->sample->desired.format); | |
1350 if(ALMIXER_SIGNED_VALUE == signedness_value) | |
1351 { | |
1352 /* I'm guessing that if it's signed, then 0 is the | |
1353 * "silent" value */ | |
1354 silence_value = 0; | |
1355 } | |
1356 else | |
1357 { | |
1358 if(8 == bit_depth) | |
1359 { | |
1360 /* If 8 bit, I'm guessing it's (2^7)-1 = 127 */ | |
1361 silence_value = 127; | |
1362 } | |
1363 else | |
1364 { | |
1365 /* For 16 bit, I'm guessing it's (2^15)-1 = 32767 */ | |
1366 silence_value = 32767; | |
1367 } | |
1368 } | |
1369 /* Now fill up the rest of the data buffer with the | |
1370 * silence_value. | |
1371 * I don't think I have to worry about endian issues for | |
1372 * this part since the data is for internal use only | |
1373 * at this point. | |
1374 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1375 memset( &( ((ALbyte*)(data->sample->buffer))[bytes_decoded] ), silence_value, data->sample->buffer_size - bytes_decoded); |
0 | 1376 /* Now reset the bytes_decoded to reflect the entire |
1377 * buffer to tell alBufferData what our full size is. | |
1378 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1379 /* |
0 | 1380 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
|
1381 */ |
0 | 1382 bytes_decoded = data->sample->buffer_size; |
1383 } | |
1384 /*********** END EXPERIMENT ******************************/ | |
1385 /******* END REMOVE ME ********************************/ | |
1386 #endif | |
1387 | |
1388 /* Now copy the data to the OpenAL buffer */ | |
1389 /* We can't just set a pointer because the API needs | |
1390 * its own copy to assist hardware acceleration */ | |
1391 alBufferData(buffer, | |
1392 TranslateFormat(&data->sample->desired), | |
1393 data->sample->buffer, | |
1394 bytes_decoded, | |
1395 data->sample->desired.rate | |
1396 ); | |
1397 if( (error = alGetError()) != AL_NO_ERROR) | |
1398 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1399 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1400 return 0; |
1401 } | |
1402 | |
1403 /* If we need to, copy the data also to the access area | |
1404 * (the function will do the check for us) | |
1405 */ | |
1406 CopyDataToAccessBuffer(data, bytes_decoded, buffer); | |
1407 return bytes_decoded; | |
1408 } | |
1409 | |
1410 | |
1411 | |
1412 | |
1413 /******************** EXPERIEMENT **************************** | |
1414 * Test function to force maximum buffer filling during loops | |
1415 * REMOVE LATER | |
1416 *********************************************/ | |
1417 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1418 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
|
1419 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1420 ALint bytes_decoded; |
0 | 1421 ALenum error; |
1422 if(NULL == data) | |
1423 { | |
1424 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1425 return -1; | |
1426 } | |
1427 | |
1428 if(AL_FALSE == alIsBuffer(buffer)) | |
1429 { | |
1430 fprintf(stderr, "NOT A BUFFER>>>>>>>>>>>>>>>\n"); | |
1431 return -1; | |
1432 } | |
1433 fprintf(stderr, "Entered GetMoreData222222: buffer id is %d\n", buffer); | |
1434 | |
1435 /* | |
1436 fprintf(stderr, "Decode in GetMoreData\n"); | |
1437 */ | |
1438 | |
1439 #if 0 | |
1440 if(buffer%2 == 1) | |
1441 { | |
1442 fprintf(stderr, "Setting buffer size to 16384\n"); | |
1443 Sound_SetBufferSize(data->sample, 16384); | |
1444 } | |
1445 else | |
1446 { | |
1447 fprintf(stderr, "Setting buffer size to 8192\n"); | |
1448 Sound_SetBufferSize(data->sample, 8192); | |
1449 } | |
1450 #endif | |
1451 | |
1452 bytes_decoded = Sound_Decode(data->sample); | |
1453 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1454 { | |
1455 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1456 ALmixer_SetError(Sound_GetError()); | |
1457 /* | |
1458 Sound_FreeSample(data->sample); | |
1459 */ | |
1460 return -1; | |
1461 } | |
1462 /* Don't forget to add check for EOF */ | |
1463 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1464 if(0 == bytes_decoded) | |
1465 { | |
1466 #if 1 | |
1467 fprintf(stderr, "Hit eof while trying to buffer\n"); | |
1468 data->eof = 1; | |
1469 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1470 { | |
1471 fprintf(stderr, "\tEOF flag\n"); | |
1472 } | |
1473 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1474 { | |
1475 fprintf(stderr, "\tCanSeek flag\n"); | |
1476 } | |
1477 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1478 { | |
1479 fprintf(stderr, "\tEAGAIN flag\n"); | |
1480 } | |
1481 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1482 { | |
1483 fprintf(stderr, "\tNONE flag\n"); | |
1484 } | |
1485 #endif | |
1486 return 0; | |
1487 } | |
1488 | |
1489 if(bytes_decoded < 16384) | |
1490 { | |
1491 char* tempbuffer1 = (char*)malloc(16384); | |
1492 char* tempbuffer2 = (char*)malloc(16384); | |
1493 int retval; | |
1494 memcpy(tempbuffer1, data->sample->buffer, bytes_decoded); | |
1495 retval = Sound_SetBufferSize(data->sample, 16384-bytes_decoded); | |
1496 if(retval == 1) | |
1497 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1498 ALuint new_bytes; |
0 | 1499 Sound_Rewind(data->sample); |
1500 new_bytes = Sound_Decode(data->sample); | |
1501 fprintf(stderr, "Orig bytes: %d, Make up bytes_decoded=%d, total=%d\n", bytes_decoded, new_bytes, new_bytes+bytes_decoded); | |
1502 | |
1503 memcpy(tempbuffer2, data->sample->buffer, new_bytes); | |
1504 | |
1505 retval = Sound_SetBufferSize(data->sample, 16384); | |
1506 fprintf(stderr, "Finished reset...now danger copy\n"); | |
1507 memcpy(data->sample->buffer, tempbuffer1,bytes_decoded); | |
1508 | |
1509 fprintf(stderr, "Finished reset...now danger copy2\n"); | |
1510 memcpy( &( ((char*)(data->sample->buffer))[bytes_decoded] ), tempbuffer2, new_bytes); | |
1511 | |
1512 fprintf(stderr, "Finished \n"); | |
1513 | |
1514 free(tempbuffer1); | |
1515 free(tempbuffer2); | |
1516 bytes_decoded += new_bytes; | |
1517 fprintf(stderr, "ASSERT bytes should equal 16384: %d\n", bytes_decoded); | |
1518 } | |
1519 else | |
1520 { | |
1521 fprintf(stderr, "Experiment failed: %s\n", Sound_GetError()); | |
1522 } | |
1523 } | |
1524 | |
1525 /* Now copy the data to the OpenAL buffer */ | |
1526 /* We can't just set a pointer because the API needs | |
1527 * its own copy to assist hardware acceleration */ | |
1528 alBufferData(buffer, | |
1529 TranslateFormat(&data->sample->desired), | |
1530 data->sample->buffer, | |
1531 bytes_decoded, | |
1532 data->sample->desired.rate | |
1533 ); | |
1534 if( (error = alGetError()) != AL_NO_ERROR) | |
1535 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1536 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1537 return -1; |
1538 } | |
1539 | |
1540 fprintf(stderr, "GetMoreData2222 returning %d bytes decoded\n", bytes_decoded); | |
1541 return bytes_decoded; | |
1542 } | |
1543 #endif | |
1544 | |
1545 /************ END EXPERIEMENT - REMOVE ME *************************/ | |
1546 | |
1547 | |
1548 | |
1549 | |
1550 | |
1551 | |
1552 | |
1553 | |
1554 | |
1555 /* This function will look up the source for the corresponding channel */ | |
1556 /* 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
|
1557 static ALuint Internal_GetSource(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1558 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1559 ALint i; |
0 | 1560 /* Make sure channel is in bounds */ |
1561 if(channel >= Number_of_Channels_global) | |
1562 { | |
1563 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); | |
1564 return 0; | |
1565 } | |
1566 /* If the user specified -1, then return the an available source */ | |
1567 if(channel < 0) | |
1568 { | |
1569 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1570 { | |
1571 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1572 { | |
1573 return ALmixer_Channel_List[i].alsource; | |
1574 } | |
1575 } | |
1576 /* If we get here, all sources are in use */ | |
1577 /* Error message seems too harsh | |
1578 ALmixer_SetError("All sources are in use"); | |
1579 */ | |
1580 return 0; | |
1581 } | |
1582 /* Last case: Return the source for the channel */ | |
1583 return ALmixer_Channel_List[channel].alsource; | |
1584 } | |
1585 | |
1586 /* 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
|
1587 static ALint Internal_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1588 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1589 ALint i; |
0 | 1590 /* Only the first value is used for the key */ |
1591 Source_Map key = { 0, 0 }; | |
1592 Source_Map* found_item = NULL; | |
1593 key.source = source; | |
1594 | |
1595 /* If the source is 0, look up the first available channel */ | |
1596 if(0 == source) | |
1597 { | |
1598 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1599 { | |
1600 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1601 { | |
1602 return i; | |
1603 } | |
1604 } | |
1605 /* If we get here, all sources are in use */ | |
1606 /* Error message seems too harsh | |
1607 ALmixer_SetError("All channels are in use"); | |
1608 */ | |
1609 return -1; | |
1610 } | |
1611 | |
1612 | |
1613 /* Else, look up the source and return the channel */ | |
1614 if(AL_FALSE == alIsSource(source)) | |
1615 { | |
1616 ALmixer_SetError("Is not a source"); | |
1617 return -1; | |
1618 } | |
1619 | |
1620 /* Use the ANSI C binary search feature (yea!) */ | |
1621 found_item = (Source_Map*)bsearch(&key, Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
1622 if(NULL == found_item) | |
1623 { | |
1624 ALmixer_SetError("Source is valid but not registered with ALmixer (to a channel)"); | |
1625 return -1; | |
1626 } | |
1627 return found_item->channel; | |
1628 } | |
1629 | |
1630 | |
1631 | |
1632 /* This function will find the first available channel (not in use) | |
1633 * from the specified start channel. Reserved channels to not qualify | |
1634 * as available. | |
1635 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1636 static ALint Internal_FindFreeChannel(ALint start_channel) |
0 | 1637 { |
1638 /* Start at the number of reserved so we skip over | |
1639 * all the reserved channels. | |
1640 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1641 ALint i = Number_of_Reserve_Channels_global; |
0 | 1642 /* Quick check to see if we're out of bounds */ |
1643 if(start_channel >= Number_of_Channels_global) | |
1644 { | |
1645 return -1; | |
1646 } | |
1647 | |
1648 /* If the start channel is even higher than the reserved, | |
1649 * then start at the higher value. | |
1650 */ | |
1651 if(start_channel > Number_of_Reserve_Channels_global) | |
1652 { | |
1653 i = start_channel; | |
1654 } | |
1655 | |
1656 /* i has already been set */ | |
1657 for( ; i<Number_of_Channels_global; i++) | |
1658 { | |
1659 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1660 { | |
1661 return i; | |
1662 } | |
1663 } | |
1664 /* If we get here, all sources are in use */ | |
1665 return -1; | |
1666 } | |
1667 | |
1668 | |
1669 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1670 /* 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
|
1671 * or 0 for error |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1672 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1673 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
|
1674 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1675 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1676 ALint counter = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1677 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1678 ALint buffers_still_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1679 ALint buffers_processed; |
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 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1682 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1683 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
|
1684 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1685 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1686 /* 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
|
1687 if(channel >= 0) |
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 /* 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
|
1690 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
|
1691 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1692 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1693 if((error = alGetError()) != AL_NO_ERROR) |
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 fprintf(stderr, "14Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1696 alGetString(error)); |
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 /* 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
|
1699 * 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
|
1700 * 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
|
1701 * 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
|
1702 * 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
|
1703 * 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
|
1704 * 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
|
1705 * 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
|
1706 * 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
|
1707 * 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
|
1708 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1709 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1710 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1711 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1712 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1713 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1714 if((error = alGetError()) != AL_NO_ERROR) |
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 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
|
1717 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1718 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
|
1719 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1720 retval = -1; |
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 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1723 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1724 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1725 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1726 if((error = alGetError()) != AL_NO_ERROR) |
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 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
|
1729 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1730 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
|
1731 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1732 retval = -1; |
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 /* 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
|
1735 * to clear the source |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1736 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1737 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
|
1738 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1739 alSourcei(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1740 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1741 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1742 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1743 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1744 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
|
1745 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1746 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
|
1747 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1748 retval = -1; |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1751 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1752 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
|
1753 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1754 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1755 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1756 /* Launch callback for consistency? */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1757 Invoke_Channel_Done_Callback(channel, did_finish_naturally); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1758 counter++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1759 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1760 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1761 /* 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
|
1762 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1763 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1764 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1765 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
|
1766 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1767 /* 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
|
1768 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
|
1769 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1770 alSourceStop(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1771 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1772 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1773 fprintf(stderr, "19Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1774 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1775 } |
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 /* 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
|
1778 * 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
|
1779 * 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
|
1780 * 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
|
1781 * 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
|
1782 * 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
|
1783 * 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
|
1784 * 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
|
1785 * 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
|
1786 * 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
|
1787 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1788 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1789 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1790 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1791 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1792 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1793 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1794 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1795 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
|
1796 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1797 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
|
1798 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1799 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1800 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1801 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1802 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1803 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1804 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1805 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1806 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1807 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
|
1808 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1809 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
|
1810 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1811 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1812 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1813 /* 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
|
1814 * to clear the source |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1815 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1816 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
|
1817 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1818 alSourcei(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1819 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1820 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1821 if((error = alGetError()) != AL_NO_ERROR) |
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 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
|
1824 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1825 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
|
1826 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1827 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1828 } |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1831 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
|
1832 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1833 Clean_Channel(i); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1834 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1835 /* Launch callback for consistency? */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1836 Invoke_Channel_Done_Callback(i, did_finish_naturally); |
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 /* Increment the counter */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1839 counter++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1840 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1841 /* 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
|
1842 * are bugs. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1843 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1844 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1845 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1846 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1847 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1848 / * 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
|
1849 * data will get messed up * / |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1850 Clean_Channel(channel); |
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 /* Just in case */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1854 Is_Playing_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1855 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1856 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1857 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1858 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1859 return -1; |
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 return counter; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1862 } |
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 /* 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
|
1866 * 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
|
1867 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1868 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
|
1869 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1870 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1871 if(0 == source) |
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 number of sources halted */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1874 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
|
1875 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1876 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1877 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1878 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1879 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1880 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
|
1881 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1882 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1883 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
|
1884 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1885 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1886 |
0 | 1887 |
1888 /* Note: Behaves, almost like SDL_mixer, but keep in mind | |
1889 * that there is no "music" channel anymore, so 0 | |
1890 * will remove everything. (Note, I no longer allow 0 | |
1891 * so it gets set to the default number.) | |
1892 * Also, callbacks for deleted channels will not be called. | |
1893 * I really need to do error checking, for realloc and | |
1894 * GenSources, but reversing the damage is too painful | |
1895 * for me to think about at the moment, so it's not in here. | |
1896 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1897 static ALint Internal_AllocateChannels(ALint numchans) |
0 | 1898 { |
1899 ALenum error; | |
1900 int i; | |
1901 /* Return info */ | |
1902 if(numchans < 0) | |
1903 { | |
1904 return Number_of_Channels_global; | |
1905 } | |
1906 if(0 == numchans) | |
1907 { | |
1908 numchans = ALMIXER_DEFAULT_NUM_CHANNELS; | |
1909 } | |
1910 /* No change */ | |
1911 if(numchans == Number_of_Channels_global) | |
1912 { | |
1913 return Number_of_Channels_global; | |
1914 } | |
1915 /* We need to increase the number of channels */ | |
1916 if(numchans > Number_of_Channels_global) | |
1917 { | |
1918 /* Not sure how safe this is, but SDL_mixer does it | |
1919 * the same way */ | |
1920 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1921 | |
1922 /* Allocate memory for the list of sources that map to the channels */ | |
1923 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
1924 | |
1925 for(i=Number_of_Channels_global; i<numchans; i++) | |
1926 { | |
1927 Init_Channel(i); | |
1928 /* Generate a new source and associate it with the channel */ | |
1929 alGenSources(1, &ALmixer_Channel_List[i].alsource); | |
1930 if((error = alGetError()) != AL_NO_ERROR) | |
1931 { | |
1932 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
|
1933 alGetString(error)); |
0 | 1934 } |
1935 /* Copy the source so the SourceMap has it too */ | |
1936 Source_Map_List[i].source = ALmixer_Channel_List[i].alsource; | |
1937 Source_Map_List[i].channel = i; | |
1938 /* Clean the channel because there are some things that need to | |
1939 * be done that can't happen until the source is set | |
1940 */ | |
1941 Clean_Channel(i); | |
1942 } | |
1943 | |
1944 /* The Source_Map_List must be sorted by source for binary searches | |
1945 */ | |
1946 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
1947 | |
1948 Number_of_Channels_global = numchans; | |
1949 return numchans; | |
1950 } | |
1951 /* Need to remove channels. This might be dangerous */ | |
1952 if(numchans < Number_of_Channels_global) | |
1953 { | |
1954 for(i=numchans; i<Number_of_Channels_global; i++) | |
1955 { | |
1956 /* Halt the channel */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1957 Internal_HaltChannel(i, AL_FALSE); |
0 | 1958 |
1959 /* Delete source associated with the channel */ | |
1960 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
1961 if((error = alGetError()) != AL_NO_ERROR) | |
1962 { | |
1963 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
|
1964 alGetString(error)); |
0 | 1965 } |
1966 } | |
1967 | |
1968 | |
1969 /* Not sure how safe this is, but SDL_mixer does it | |
1970 * the same way */ | |
1971 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1972 | |
1973 /* The tricky part is that we must remove the entries | |
1974 * in the source map that correspond to the deleted channels. | |
1975 * We'll resort the map by channels so we can pick them off | |
1976 * in order. | |
1977 */ | |
1978 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map_by_channel); | |
1979 | |
1980 /* Deallocate memory for the list of sources that map to the channels */ | |
1981 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
1982 | |
1983 /* Now resort the map by source and the correct num of chans */ | |
1984 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
1985 | |
1986 /* Reset the number of channels */ | |
1987 Number_of_Channels_global = numchans; | |
1988 return numchans; | |
1989 } | |
1990 /* Shouldn't ever reach here */ | |
1991 return -1; | |
1992 | |
1993 } | |
1994 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1995 static ALint Internal_ReserveChannels(ALint num) |
0 | 1996 { |
1997 /* Can't reserve more than the max num of channels */ | |
1998 /* Actually, I'll allow it for people who just want to | |
1999 * set the value really high to effectively disable | |
2000 * auto-assignment | |
2001 */ | |
2002 | |
2003 /* Return the current number of reserved channels */ | |
2004 if(num < 0) | |
2005 { | |
2006 return Number_of_Reserve_Channels_global; | |
2007 } | |
2008 Number_of_Reserve_Channels_global = num; | |
2009 return Number_of_Reserve_Channels_global; | |
2010 } | |
2011 | |
2012 | |
2013 /* This will rewind the SDL_Sound sample for streamed | |
2014 * samples and start buffering up the data for the next | |
2015 * playback. This may require samples to be halted | |
2016 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2017 static ALint Internal_RewindData(ALmixer_Data* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2018 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2019 ALint retval = 0; |
0 | 2020 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2021 ALint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2022 ALint i; |
0 | 2023 */ |
2024 if(NULL == data) | |
2025 { | |
2026 ALmixer_SetError("Cannot rewind because data is NULL\n"); | |
2027 return -1; | |
2028 } | |
2029 | |
2030 | |
2031 /* Might have to require Halt */ | |
2032 /* Okay, we assume Halt or natural stop has already | |
2033 * cleared the data buffers | |
2034 */ | |
2035 if(data->in_use) | |
2036 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2037 /* |
0 | 2038 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
|
2039 */ |
0 | 2040 /* |
2041 ALmixer_SetError("Data is in use. Cannot rewind unless all sources using the data are halted\n"); | |
2042 return -1; | |
2043 */ | |
2044 } | |
2045 | |
2046 | |
2047 /* Because Seek can alter things even in predecoded data, | |
2048 * decoded data must also be rewound | |
2049 */ | |
2050 if(data->decoded_all) | |
2051 { | |
2052 data->eof = 0; | |
2053 | |
2054 #if 0 | |
2055 #if defined(DISABLE_PREDECODED_SEEK) | |
2056 /* Since we can't seek predecoded stuff, it should be rewound */ | |
2057 return 0; | |
2058 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
2059 /* This case is if the Sound_Sample has been deleted. | |
2060 * It assumes the data is already at the beginning. | |
2061 */ | |
2062 if(NULL == data->sample) | |
2063 { | |
2064 return 0; | |
2065 } | |
2066 /* Else, the sample has already been reallocated, | |
2067 * and we can fall to normal behavior | |
2068 */ | |
2069 #endif | |
2070 #endif | |
2071 /* If access_data, was enabled, the sound sample | |
2072 * still exists and we can do stuff. | |
2073 * If it's NULL, we can't do anything, but | |
2074 * it should already be "rewound". | |
2075 */ | |
2076 if(NULL == data->sample) | |
2077 { | |
2078 return 0; | |
2079 } | |
2080 /* Else, the sample has already been reallocated, | |
2081 * and we can fall to normal behavior | |
2082 */ | |
2083 | |
2084 Set_Predecoded_Seek_Position(data, 0); | |
2085 /* | |
2086 return data->total_bytes; | |
2087 */ | |
2088 return 0; | |
2089 } | |
2090 | |
2091 /* Remaining stuff for streamed data */ | |
2092 | |
2093 data->eof = 0; | |
2094 retval = Sound_Rewind(data->sample); | |
2095 if(0 == retval) | |
2096 { | |
2097 ALmixer_SetError( Sound_GetError() ); | |
2098 return -1; | |
2099 } | |
2100 #if 0 | |
2101 /* Clear error */ | |
2102 alGetError(); | |
2103 for(i=0; i<data->num_buffers; i++) | |
2104 { | |
2105 bytes_returned = GetMoreData(data, data->buffer[i]); | |
2106 if(-1 == bytes_returned) | |
2107 { | |
2108 return -1; | |
2109 } | |
2110 else if(0 == bytes_returned) | |
2111 { | |
2112 return -1; | |
2113 } | |
2114 retval += bytes_returned; | |
2115 | |
2116 } | |
2117 #endif | |
2118 | |
2119 | |
2120 | |
2121 return retval; | |
2122 } | |
2123 | |
2124 | |
2125 | |
2126 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2127 static ALint Internal_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2128 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2129 ALint retval = 0; |
0 | 2130 ALenum error; |
2131 ALint state; | |
2132 | |
2133 if(channel >= Number_of_Channels_global) | |
2134 { | |
2135 ALmixer_SetError("Cannot rewind channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2136 return -1; | |
2137 } | |
2138 | |
2139 if((error = alGetError()) != AL_NO_ERROR) | |
2140 { | |
2141 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
|
2142 alGetString(error)); |
0 | 2143 } |
2144 /* Clear error */ | |
2145 alGetError(); | |
2146 | |
2147 /* If the user specified a specific channel */ | |
2148 if(channel >= 0) | |
2149 { | |
2150 /* only need to process channel if in use */ | |
2151 if(ALmixer_Channel_List[channel].channel_in_use) | |
2152 { | |
2153 | |
2154 /* What should I do? Do I just rewind the channel | |
2155 * or also rewind the data? Since the data is | |
2156 * shared, let's make it the user's responsibility | |
2157 * to rewind the data. | |
2158 */ | |
2159 if(ALmixer_Channel_List[channel].almixer_data->decoded_all) | |
2160 { | |
2161 alGetSourcei( | |
2162 ALmixer_Channel_List[channel].alsource, | |
2163 AL_SOURCE_STATE, &state | |
2164 ); | |
2165 if((error = alGetError()) != AL_NO_ERROR) | |
2166 { | |
2167 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
|
2168 alGetString(error)); |
0 | 2169 } |
2170 alSourceRewind(ALmixer_Channel_List[channel].alsource); | |
2171 if((error = alGetError()) != AL_NO_ERROR) | |
2172 { | |
2173 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2174 alGetString(error) ); |
0 | 2175 retval = -1; |
2176 } | |
2177 /* Need to resume playback if it was originally playing */ | |
2178 if(AL_PLAYING == state) | |
2179 { | |
2180 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2181 if((error = alGetError()) != AL_NO_ERROR) | |
2182 { | |
2183 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2184 alGetString(error) ); |
0 | 2185 retval = -1; |
2186 } | |
2187 } | |
2188 else if(AL_PAUSED == state) | |
2189 { | |
2190 /* HACK: The problem is that when paused, after | |
2191 * the Rewind, I can't get it off the INITIAL | |
2192 * state without restarting | |
2193 */ | |
2194 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2195 if((error = alGetError()) != AL_NO_ERROR) | |
2196 { | |
2197 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
|
2198 alGetString(error)); |
0 | 2199 } |
2200 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2201 if((error = alGetError()) != AL_NO_ERROR) | |
2202 { | |
2203 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2204 alGetString(error) ); |
0 | 2205 retval = -1; |
2206 } | |
2207 } | |
2208 } | |
2209 else | |
2210 { | |
2211 /* Streamed data is different. Rewinding the channel | |
2212 * does no good. Rewinding the data will have an | |
2213 * effect, but it will be lagged based on how | |
2214 * much data is queued. Recommend users call Halt | |
2215 * before rewind if they want immediate results. | |
2216 */ | |
2217 retval = Internal_RewindData(ALmixer_Channel_List[channel].almixer_data); | |
2218 } | |
2219 } | |
2220 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2221 /* The user wants to rewind all channels */ |
0 | 2222 else |
2223 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2224 ALint i; |
0 | 2225 for(i=0; i<Number_of_Channels_global; i++) |
2226 { | |
2227 /* only need to process channel if in use */ | |
2228 if(ALmixer_Channel_List[i].channel_in_use) | |
2229 { | |
2230 /* What should I do? Do I just rewind the channel | |
2231 * or also rewind the data? Since the data is | |
2232 * shared, let's make it the user's responsibility | |
2233 * to rewind the data. | |
2234 */ | |
2235 if(ALmixer_Channel_List[i].almixer_data->decoded_all) | |
2236 { | |
2237 alGetSourcei( | |
2238 ALmixer_Channel_List[i].alsource, | |
2239 AL_SOURCE_STATE, &state | |
2240 ); | |
2241 if((error = alGetError()) != AL_NO_ERROR) | |
2242 { | |
2243 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
|
2244 alGetString(error)); |
0 | 2245 } |
2246 alSourceRewind(ALmixer_Channel_List[i].alsource); | |
2247 if((error = alGetError()) != AL_NO_ERROR) | |
2248 { | |
2249 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2250 alGetString(error) ); |
0 | 2251 retval = -1; |
2252 } | |
2253 /* Need to resume playback if it was originally playing */ | |
2254 if(AL_PLAYING == state) | |
2255 { | |
2256 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2257 if((error = alGetError()) != AL_NO_ERROR) | |
2258 { | |
2259 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2260 alGetString(error) ); |
0 | 2261 retval = -1; |
2262 } | |
2263 } | |
2264 else if(AL_PAUSED == state) | |
2265 { | |
2266 /* HACK: The problem is that when paused, after | |
2267 * the Rewind, I can't get it off the INITIAL | |
2268 * state without restarting | |
2269 */ | |
2270 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2271 if((error = alGetError()) != AL_NO_ERROR) | |
2272 { | |
2273 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
|
2274 alGetString(error)); |
0 | 2275 } |
2276 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2277 if((error = alGetError()) != AL_NO_ERROR) | |
2278 { | |
2279 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2280 alGetString(error) ); |
0 | 2281 retval = -1; |
2282 } | |
2283 } | |
2284 } | |
2285 else | |
2286 { | |
2287 /* Streamed data is different. Rewinding the channel | |
2288 * does no good. Rewinding the data will have an | |
2289 * effect, but it will be lagged based on how | |
2290 * much data is queued. Recommend users call Halt | |
2291 * before rewind if they want immediate results. | |
2292 */ | |
2293 retval = Internal_RewindData(ALmixer_Channel_List[i].almixer_data); | |
2294 } | |
2295 } | |
2296 } | |
2297 } | |
2298 return retval; | |
2299 } | |
2300 | |
2301 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2302 static ALint Internal_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2303 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2304 ALint channel; |
0 | 2305 if(0 == source) |
2306 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2307 return Internal_RewindChannel(-1) + 1; |
0 | 2308 } |
2309 | |
2310 channel = Internal_GetChannel(source); | |
2311 if(-1 == channel) | |
2312 { | |
2313 ALmixer_SetError("Cannot rewind source: %s", ALmixer_GetError()); | |
2314 return 0; | |
2315 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2316 return Internal_RewindChannel(channel) + 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2317 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2318 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2319 |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2322 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2323 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
|
2324 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2325 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2326 int ret_flag = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2327 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2328 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2329 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
|
2330 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2331 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2332 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2333 /* 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
|
2334 * 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
|
2335 * 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
|
2336 * 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
|
2337 * 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
|
2338 * to prevent sharing |
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 if(0 == data->decoded_all) |
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 if(data->in_use) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2343 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2344 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
|
2345 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2346 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2347 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2348 /* 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
|
2349 * This mainly affects streamed files, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2350 * so the check is placed here |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2351 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2352 if(data->eof) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2353 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2354 if( -1 == Internal_RewindData(data) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2355 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2356 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
|
2357 return -1; |
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 } |
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 /* 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
|
2362 if(-1 == channel) |
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 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2365 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
|
2366 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2367 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
|
2368 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2369 channel = i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2370 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2371 } |
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 /* 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
|
2374 if(i == Number_of_Channels_global) |
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 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
|
2377 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2378 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2379 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2380 /* 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
|
2381 * out of bounds or in use */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2382 else |
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(channel >= Number_of_Channels_global) |
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 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
|
2387 return -1; |
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 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
|
2390 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2391 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
|
2392 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2393 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2394 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2395 /* 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
|
2396 if(loops < -1) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2397 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2398 loops = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2399 } |
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 /* 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
|
2402 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2403 /* 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
|
2404 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
|
2405 data->in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2406 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2407 /* 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
|
2408 * (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
|
2409 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2410 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
|
2411 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
|
2412 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
|
2413 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2414 /* 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
|
2415 if(ticks < 0) |
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 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
|
2418 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2419 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2420 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2421 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
|
2422 } |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2425 ALmixer_Channel_List[channel].halted = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2426 ALmixer_Channel_List[channel].paused = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2427 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2428 /* 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
|
2429 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2430 if( (-1 == loops) && (data->decoded_all) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2431 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2432 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
|
2433 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2434 else |
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 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
|
2437 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2438 if((error = alGetError()) != AL_NO_ERROR) |
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 fprintf(stderr, "13Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2441 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2442 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2443 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2444 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2445 /* Because of the corner case, predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2446 * 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
|
2447 * Streams do not have this problem |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2448 * 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
|
2449 * avoid the conflict. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2450 * 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
|
2451 * Since streams, cannot share, only predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2452 * files are affected |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2453 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2454 if(data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2455 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2456 /* 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
|
2457 * 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
|
2458 * 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
|
2459 * must be +1 |
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(-1 == loops) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2462 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2463 /* -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
|
2464 * to add +1 to it */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2465 ALmixer_Channel_List[channel].loops = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2466 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
|
2467 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2468 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2469 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2470 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
|
2471 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
|
2472 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2473 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2474 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2475 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2476 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2477 /* 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
|
2478 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
|
2479 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2480 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2481 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2482 /* 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
|
2483 /* 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
|
2484 * 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
|
2485 * 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
|
2486 * 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
|
2487 * 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
|
2488 * 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
|
2489 * easier to maintain. |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2492 /* Clear the error flag */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2493 alGetError(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2494 if(data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2495 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2496 /* Bind the data to the source */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2497 alSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2498 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2499 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2500 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2501 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2502 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2503 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
|
2504 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2505 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2506 return -1; |
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 /* 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
|
2510 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
|
2511 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2512 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2513 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2514 /* 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
|
2515 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2516 ALuint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2517 ALuint j; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2518 data->num_buffers_in_use=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2519 /****** MODIFICATION must go here *********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2520 /* 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
|
2521 * 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
|
2522 * 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
|
2523 * 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
|
2524 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2525 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2526 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2527 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2528 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2529 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2530 /* No data or error */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2531 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
|
2532 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2533 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2534 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2535 /* 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
|
2536 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2537 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2538 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2539 /* 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
|
2540 * 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
|
2541 * before the last buffer is filled. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2542 * 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
|
2543 * 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
|
2544 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2545 |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2546 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2547 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
|
2548 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2549 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
|
2550 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2551 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2552 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
|
2553 fprintf(stderr, ">>>>>>>>>>>>>>>>>>HACK for GetMoreData2\n"); |
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 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2556 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2557 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2558 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2559 * 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
|
2560 * 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
|
2561 * 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
|
2562 * 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
|
2563 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2564 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2565 if(bytes_returned < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2566 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2567 /* Error found */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2568 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
|
2569 /* 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
|
2570 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2571 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2572 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2573 else if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2574 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2575 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2576 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2577 /* No more data to buffer */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2578 /* Check for loops */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2579 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
|
2580 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2581 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2582 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
|
2583 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2584 if(0 == Sound_Rewind(data->sample)) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2585 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2586 fprintf(stderr, "error in rewind\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2587 ALmixer_SetError( Sound_GetError() ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2588 ALmixer_Channel_List[channel].loops = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2589 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2590 /* 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
|
2591 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2592 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2593 /* 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
|
2594 data->eof = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2595 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
|
2596 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2597 ALmixer_Channel_List[channel].loops--; |
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, "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
|
2600 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2601 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2602 /* 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
|
2603 * 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
|
2604 * into an infinite loop |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2605 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2606 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2607 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2608 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2609 if(bytes_returned <= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2610 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2611 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
|
2612 /* 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
|
2613 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2614 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2615 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2616 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2617 else |
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 /* 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
|
2620 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2621 } |
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 /* 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
|
2624 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2625 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2626 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2627 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
|
2628 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2629 data->num_buffers_in_use); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2630 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2631 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2632 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2633 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2634 data->num_buffers_in_use, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2635 data->buffer); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2636 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2637 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2638 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
|
2639 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2640 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2641 return -1; |
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 /* 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
|
2644 * 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
|
2645 * 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
|
2646 * 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
|
2647 * "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
|
2648 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2649 if(data->circular_buffer_queue != NULL) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2650 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2651 ALuint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2652 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2653 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
|
2654 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2655 // fprintf(stderr, "56c: CircularQueue_PushBack.\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2656 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
|
2657 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2658 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2659 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
|
2660 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
|
2661 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2662 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2663 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2664 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2665 fprintf(stderr, "Queue in PlayTimed\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2666 CircularQueueUnsignedInt_Print(data->circular_buffer_queue); |
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 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2669 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2670 } |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2673 /****** END **********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2674 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2675 /* 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
|
2676 * so now we can play |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2677 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2678 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2679 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2680 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2681 ALmixer_SetError("Play failed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2682 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2683 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2684 return -1; |
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 /* 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
|
2688 Is_Playing_global++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2689 if(-1 == ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2690 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2691 fprintf(stderr, "BACKDOOR ERROR >>>>>>>>>>>>>>>>>>\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2692 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2693 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2694 return channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2695 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2696 |
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 /* 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
|
2699 * 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
|
2700 * 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
|
2701 * PlayChannelTimed() function call. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2702 * 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
|
2703 * 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
|
2704 * 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
|
2705 * 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
|
2706 * 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
|
2707 * 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
|
2708 * 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
|
2709 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2710 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
|
2711 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2712 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2713 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2714 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2715 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2716 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
|
2717 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2718 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2719 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2720 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2721 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2722 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2723 return Internal_GetSource(retval); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2724 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2725 } |
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 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2728 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2729 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2730 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
|
2731 return 0; |
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(channel, 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 source; |
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 /* make compiler happy */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2743 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2744 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2745 |
0 | 2746 |
2747 | |
2748 | |
2749 /* Returns the channel or number of channels actually paused */ | |
2750 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2751 static ALint Internal_PauseChannel(ALint channel) |
0 | 2752 { |
2753 ALenum error; | |
2754 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2755 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2756 ALint counter = 0; |
0 | 2757 |
2758 if(channel >= Number_of_Channels_global) | |
2759 { | |
2760 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2761 return -1; | |
2762 } | |
2763 | |
2764 if((error = alGetError()) != AL_NO_ERROR) | |
2765 { | |
2766 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
|
2767 alGetString(error)); |
0 | 2768 } |
2769 /* Clear error */ | |
2770 alGetError(); | |
2771 | |
2772 /* If the user specified a specific channel */ | |
2773 if(channel >= 0) | |
2774 { | |
2775 /* only need to process channel if in use */ | |
2776 if(ALmixer_Channel_List[channel].channel_in_use) | |
2777 { | |
2778 /* We don't want to repause if already | |
2779 * paused because the fadeout/expire | |
2780 * timing will get messed up | |
2781 */ | |
2782 alGetSourcei( | |
2783 ALmixer_Channel_List[channel].alsource, | |
2784 AL_SOURCE_STATE, &state | |
2785 ); | |
2786 if((error = alGetError()) != AL_NO_ERROR) | |
2787 { | |
2788 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
|
2789 alGetString(error)); |
0 | 2790 } |
2791 if(AL_PLAYING == state) | |
2792 { | |
2793 /* Count the actual number of channels being paused */ | |
2794 counter++; | |
2795 | |
2796 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2797 if((error = alGetError()) != AL_NO_ERROR) | |
2798 { | |
2799 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2800 alGetString(error) ); |
0 | 2801 retval = -1; |
2802 } | |
2803 /* We need to pause the expire time count down */ | |
2804 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
2805 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2806 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2807 ALuint diff_time; |
0 | 2808 diff_time = current_time - |
2809 ALmixer_Channel_List[channel].start_time; | |
2810 /* When we unpause, we will want to reset | |
2811 * the start time so we can continue | |
2812 * to base calculations off GetTicks(). | |
2813 * This means we need to subtract the amount | |
2814 * of time already used up from expire_ticks. | |
2815 */ | |
2816 ALmixer_Channel_List[channel].expire_ticks = | |
2817 ALmixer_Channel_List[channel].expire_ticks - | |
2818 diff_time; | |
2819 /* Because -1 is a special value, we can't | |
2820 * allow the time to go negative | |
2821 */ | |
2822 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2823 { | |
2824 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2825 } | |
2826 } | |
2827 /* Do the same as expire time for fading */ | |
2828 if(ALmixer_Channel_List[channel].fade_enabled) | |
2829 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2830 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2831 ALuint diff_time; |
0 | 2832 diff_time = current_time - |
2833 ALmixer_Channel_List[channel].fade_start_time; | |
2834 /* When we unpause, we will want to reset | |
2835 * the start time so we can continue | |
2836 * to base calculations off GetTicks(). | |
2837 * This means we need to subtract the amount | |
2838 * of time already used up from expire_ticks. | |
2839 */ | |
2840 ALmixer_Channel_List[channel].fade_expire_ticks = | |
2841 ALmixer_Channel_List[channel].fade_expire_ticks - | |
2842 diff_time; | |
2843 /* Don't allow the time to go negative */ | |
2844 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2845 { | |
2846 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2847 } | |
2848 } /* End fade check */ | |
2849 } /* End if PLAYING */ | |
2850 } /* End If in use */ | |
2851 } /* End specific channel */ | |
2852 /* The user wants to halt all channels */ | |
2853 else | |
2854 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2855 ALint i; |
0 | 2856 for(i=0; i<Number_of_Channels_global; i++) |
2857 { | |
2858 /* only need to process channel if in use */ | |
2859 if(ALmixer_Channel_List[i].channel_in_use) | |
2860 { | |
2861 /* We don't want to repause if already | |
2862 * paused because the fadeout/expire | |
2863 * timing will get messed up | |
2864 */ | |
2865 alGetSourcei( | |
2866 ALmixer_Channel_List[i].alsource, | |
2867 AL_SOURCE_STATE, &state | |
2868 ); | |
2869 if((error = alGetError()) != AL_NO_ERROR) | |
2870 { | |
2871 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
|
2872 alGetString(error)); |
0 | 2873 } |
2874 if(AL_PLAYING == state) | |
2875 { | |
2876 /* Count the actual number of channels being paused */ | |
2877 counter++; | |
2878 | |
2879 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2880 if((error = alGetError()) != AL_NO_ERROR) | |
2881 { | |
2882 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2883 alGetString(error) ); |
0 | 2884 retval = -1; |
2885 } | |
2886 /* We need to pause the expire time count down */ | |
2887 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
2888 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2889 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2890 ALuint diff_time; |
0 | 2891 diff_time = current_time - |
2892 ALmixer_Channel_List[i].start_time; | |
2893 /* When we unpause, we will want to reset | |
2894 * the start time so we can continue | |
2895 * to base calculations off GetTicks(). | |
2896 * This means we need to subtract the amount | |
2897 * of time already used up from expire_ticks. | |
2898 */ | |
2899 ALmixer_Channel_List[i].expire_ticks = | |
2900 ALmixer_Channel_List[i].expire_ticks - | |
2901 diff_time; | |
2902 /* Because -1 is a special value, we can't | |
2903 * allow the time to go negative | |
2904 */ | |
2905 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2906 { | |
2907 ALmixer_Channel_List[i].expire_ticks = 0; | |
2908 } | |
2909 } | |
2910 /* Do the same as expire time for fading */ | |
2911 if(ALmixer_Channel_List[i].fade_enabled) | |
2912 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2913 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2914 ALuint diff_time; |
0 | 2915 diff_time = current_time - |
2916 ALmixer_Channel_List[i].fade_start_time; | |
2917 /* When we unpause, we will want to reset | |
2918 * the start time so we can continue | |
2919 * to base calculations off GetTicks(). | |
2920 * This means we need to subtract the amount | |
2921 * of time already used up from expire_ticks. | |
2922 */ | |
2923 ALmixer_Channel_List[i].fade_expire_ticks = | |
2924 ALmixer_Channel_List[i].fade_expire_ticks - | |
2925 diff_time; | |
2926 /* Don't allow the time to go negative */ | |
2927 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2928 { | |
2929 ALmixer_Channel_List[i].expire_ticks = 0; | |
2930 } | |
2931 } /* End fade check */ | |
2932 } /* End if PLAYING */ | |
2933 } /* End channel in use */ | |
2934 } /* End for-loop */ | |
2935 } | |
2936 if(-1 == retval) | |
2937 { | |
2938 return -1; | |
2939 } | |
2940 return counter; | |
2941 } | |
2942 | |
2943 /* 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
|
2944 static ALint Internal_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2945 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2946 ALint channel; |
0 | 2947 if(0 == source) |
2948 { | |
2949 return Internal_PauseChannel(-1); | |
2950 } | |
2951 | |
2952 channel = Internal_GetChannel(source); | |
2953 if(-1 == channel) | |
2954 { | |
2955 ALmixer_SetError("Cannot pause source: %s", ALmixer_GetError()); | |
2956 return -1; | |
2957 } | |
2958 return Internal_PauseChannel(channel); | |
2959 } | |
2960 | |
2961 | |
2962 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2963 static ALint Internal_ResumeChannel(ALint channel) |
0 | 2964 { |
2965 ALint state; | |
2966 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2967 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2968 ALint counter = 0; |
0 | 2969 |
2970 if(channel >= Number_of_Channels_global) | |
2971 { | |
2972 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2973 return -1; | |
2974 } | |
2975 | |
2976 if((error = alGetError()) != AL_NO_ERROR) | |
2977 { | |
2978 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
|
2979 alGetString(error)); |
0 | 2980 } |
2981 /* Clear error */ | |
2982 alGetError(); | |
2983 | |
2984 /* If the user specified a specific channel */ | |
2985 if(channel >= 0) | |
2986 { | |
2987 /* only need to process channel if in use */ | |
2988 if(ALmixer_Channel_List[channel].channel_in_use) | |
2989 { | |
2990 alGetSourcei( | |
2991 ALmixer_Channel_List[channel].alsource, | |
2992 AL_SOURCE_STATE, &state | |
2993 ); | |
2994 if((error = alGetError()) != AL_NO_ERROR) | |
2995 { | |
2996 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
|
2997 alGetString(error)); |
0 | 2998 } |
2999 if(AL_PAUSED == state) | |
3000 { | |
3001 /* Count the actual number of channels resumed */ | |
3002 counter++; | |
3003 | |
3004 /* We need to resume the expire time count down */ | |
3005 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
3006 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3007 ALmixer_Channel_List[channel].start_time = ALmixer_GetTicks(); |
0 | 3008 } |
3009 /* Do the same as expire time for fading */ | |
3010 if(ALmixer_Channel_List[channel].fade_enabled) | |
3011 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3012 ALmixer_Channel_List[channel].fade_start_time = ALmixer_GetTicks(); |
0 | 3013 } |
3014 | |
3015 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
3016 if((error = alGetError()) != AL_NO_ERROR) | |
3017 { | |
3018 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3019 alGetString(error) ); |
0 | 3020 retval = -1; |
3021 } | |
3022 } | |
3023 } | |
3024 } | |
3025 /* The user wants to halt all channels */ | |
3026 else | |
3027 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3028 ALint i; |
0 | 3029 for(i=0; i<Number_of_Channels_global; i++) |
3030 { | |
3031 /* only need to process channel if in use */ | |
3032 if(ALmixer_Channel_List[i].channel_in_use) | |
3033 { | |
3034 alGetSourcei( | |
3035 ALmixer_Channel_List[i].alsource, | |
3036 AL_SOURCE_STATE, &state | |
3037 ); | |
3038 if((error = alGetError()) != AL_NO_ERROR) | |
3039 { | |
3040 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
|
3041 alGetString(error)); |
0 | 3042 } |
3043 if(AL_PAUSED == state) | |
3044 { | |
3045 /* Count the actual number of channels resumed */ | |
3046 counter++; | |
3047 | |
3048 /* We need to resume the expire time count down */ | |
3049 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
3050 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3051 ALmixer_Channel_List[i].start_time = ALmixer_GetTicks(); |
0 | 3052 } |
3053 /* Do the same as expire time for fading */ | |
3054 if(ALmixer_Channel_List[i].fade_enabled) | |
3055 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3056 ALmixer_Channel_List[i].fade_start_time = ALmixer_GetTicks(); |
0 | 3057 } |
3058 | |
3059 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
3060 if((error = alGetError()) != AL_NO_ERROR) | |
3061 { | |
3062 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3063 alGetString(error) ); |
0 | 3064 retval = -1; |
3065 } | |
3066 } | |
3067 } | |
3068 } | |
3069 } | |
3070 if(-1 == retval) | |
3071 { | |
3072 return -1; | |
3073 } | |
3074 return counter; | |
3075 } | |
3076 | |
3077 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3078 static ALint Internal_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3079 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3080 ALint channel; |
0 | 3081 if(0 == source) |
3082 { | |
3083 return Internal_ResumeChannel(-1); | |
3084 } | |
3085 | |
3086 channel = Internal_GetChannel(source); | |
3087 if(-1 == channel) | |
3088 { | |
3089 ALmixer_SetError("Cannot resume source: %s", ALmixer_GetError()); | |
3090 return -1; | |
3091 } | |
3092 return Internal_ResumeChannel(channel); | |
3093 } | |
3094 | |
3095 | |
3096 /* Might consider setting eof to 0 as a "feature" | |
3097 * This will allow seek to end to stay there because | |
3098 * Play automatically rewinds if at the end */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3099 static ALint Internal_SeekData(ALmixer_Data* data, ALuint msec) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3100 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3101 ALint retval; |
0 | 3102 |
3103 if(NULL == data) | |
3104 { | |
3105 ALmixer_SetError("Cannot Seek because data is NULL"); | |
3106 return -1; | |
3107 } | |
3108 | |
3109 /* Seek for predecoded files involves moving the chunk pointer around */ | |
3110 if(data->decoded_all) | |
3111 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3112 ALuint byte_position; |
0 | 3113 |
3114 /* OpenAL doesn't seem to like it if I change the buffer | |
3115 * while playing (crashes), so I must require that Seek only | |
3116 * be done when the data is not in use. | |
3117 * Since data may be shared among multiple sources, | |
3118 * I can't shut them down myself, so I have to return an error. | |
3119 */ | |
3120 if(data->in_use) | |
3121 { | |
3122 ALmixer_SetError("Cannot seek on predecoded data while instances are playing"); | |
3123 return -1; | |
3124 } | |
3125 #if 0 | |
3126 #if defined(DISABLE_PREDECODED_SEEK) | |
3127 ALmixer_SetError("Seek support for predecoded samples was not compiled in"); | |
3128 return -1; | |
3129 | |
3130 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
3131 /* By default, ALmixer frees the Sound_Sample for predecoded | |
3132 * samples because of the potential memory waste. | |
3133 * However, to seek a sample, we need to have a full | |
3134 * copy of the data around. So the strategy is to | |
3135 * recreate a hackish Sound_Sample to be used for seeking | |
3136 * purposes. If Sound_Sample is NULL, we will reallocate | |
3137 * memory for it and then procede as if everything | |
3138 * was normal. | |
3139 */ | |
3140 if(NULL == data->sample) | |
3141 { | |
3142 if( -1 == Reconstruct_Sound_Sample(data) ) | |
3143 { | |
3144 return -1; | |
3145 } | |
3146 } | |
3147 #endif | |
3148 #endif | |
3149 /* If access_data was set, then we still have the | |
3150 * Sound_Sample and we can move around in the data. | |
3151 * If it was not set, the data has been freed and we | |
3152 * cannot do anything because there is no way to | |
3153 * recover the data because OpenAL won't let us | |
3154 * get access to the buffers | |
3155 */ | |
3156 if(NULL == data->sample) | |
3157 { | |
3158 ALmixer_SetError("Cannot seek because access_data flag was set false when data was initialized"); | |
3159 return -1; | |
3160 } | |
3161 | |
3162 byte_position = Convert_Msec_To_Byte_Pos(&data->sample->desired, msec); | |
3163 return( Set_Predecoded_Seek_Position(data, byte_position) ); | |
3164 } | |
3165 else | |
3166 { | |
3167 /* Reset eof flag?? */ | |
3168 data->eof = 0; | |
3169 retval = Sound_Seek(data->sample, msec); | |
3170 if(0 == retval) | |
3171 { | |
3172 ALmixer_SetError(Sound_GetError()); | |
3173 | |
3174 fprintf(stderr, "Sound seek error: %s\n", ALmixer_GetError()); | |
3175 /* Try rewinding to clean up? */ | |
3176 /* | |
3177 Internal_RewindData(data); | |
3178 */ | |
3179 return -1; | |
3180 } | |
3181 return 0; | |
3182 } | |
3183 | |
3184 return 0; | |
3185 } | |
3186 | |
3187 | |
3188 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3189 static ALint Internal_FadeInChannelTimed(ALint channel, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 3190 { |
3191 ALfloat value; | |
3192 ALenum error; | |
3193 ALfloat original_value; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3194 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3195 ALint retval; |
0 | 3196 |
3197 | |
3198 | |
3199 if(channel >= Number_of_Channels_global) | |
3200 { | |
3201 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); | |
3202 return -1; | |
3203 } | |
3204 /* Let's call PlayChannelTimed to do the job. | |
3205 * There are two catches: | |
3206 * First is that we must set the volumes before the play call(s). | |
3207 * Second is that we must initialize the channel values | |
3208 */ | |
3209 | |
3210 if(channel < 0) | |
3211 { | |
3212 /* This might cause a problem for threads/race conditions. | |
3213 * We need to set the volume on an unknown channel, | |
3214 * so we need to request a channel first. Remember | |
3215 * that requesting a channel doesn't lock and it | |
3216 * could be surrendered to somebody else before we claim it. | |
3217 */ | |
3218 channel = Internal_GetChannel(0); | |
3219 if(-1 == channel) | |
3220 { | |
3221 return -1; | |
3222 } | |
3223 } | |
3224 else if(ALmixer_Channel_List[channel].channel_in_use) | |
3225 { | |
3226 ALmixer_SetError("Channel %d is already in use", channel); | |
3227 return -1; | |
3228 } | |
3229 | |
3230 | |
3231 /* Get the original volume in case of a problem */ | |
3232 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
|
3233 AL_GAIN, &original_value); |
0 | 3234 |
3235 if((error = alGetError()) != AL_NO_ERROR) | |
3236 { | |
3237 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
|
3238 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3239 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3240 ALmixer_Channel_List[channel].fade_end_volume = original_value; |
0 | 3241 |
3242 /* Get the Min volume */ | |
3243 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3244 AL_MIN_GAIN, &value); | |
3245 if((error = alGetError()) != AL_NO_ERROR) | |
3246 { | |
3247 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
|
3248 alGetString(error)); |
0 | 3249 } |
3250 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3251 | |
3252 /* Set the actual volume */ | |
3253 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
|
3254 AL_GAIN, value); |
0 | 3255 if((error = alGetError()) != AL_NO_ERROR) |
3256 { | |
3257 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
|
3258 alGetString(error)); |
0 | 3259 } |
3260 | |
3261 | |
3262 /* Now call PlayChannelTimed */ | |
3263 retval = Internal_PlayChannelTimed(channel, data, loops, expire_ticks); | |
3264 if(-1 == retval) | |
3265 { | |
3266 /* Chance of failure is actually pretty high since | |
3267 * a channel might already be in use or streamed | |
3268 * data can be shared | |
3269 */ | |
3270 /* Restore the original value to avoid accidental | |
3271 * distruption of playback | |
3272 */ | |
3273 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
|
3274 AL_GAIN, original_value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3275 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3276 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3277 fprintf(stderr, "38Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3278 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3279 } |
0 | 3280 return retval; |
3281 } | |
3282 | |
3283 /* We can't accept 0 as a value because of div-by-zero. | |
3284 * If zero, just call PlayChannelTimed at normal | |
3285 * volume | |
3286 */ | |
3287 if(0 == fade_ticks) | |
3288 { | |
3289 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
|
3290 AL_GAIN, |
0 | 3291 ALmixer_Channel_List[channel].fade_end_volume |
3292 ); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3293 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3294 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3295 fprintf(stderr, "39Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3296 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3297 } |
0 | 3298 |
3299 return retval; | |
3300 } | |
3301 | |
3302 /* Enable fading effects via the flag */ | |
3303 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3304 /* Set fade start time */ | |
3305 ALmixer_Channel_List[channel].fade_start_time | |
3306 = ALmixer_Channel_List[channel].start_time; | |
3307 /* Set the fade expire ticks */ | |
3308 ALmixer_Channel_List[channel].fade_expire_ticks = fade_ticks; | |
3309 | |
3310 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3311 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / fade_ticks; | |
3312 | |
3313 return retval; | |
3314 | |
3315 } | |
3316 | |
3317 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3318 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
|
3319 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3320 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3321 ALint retval; |
0 | 3322 if(0 == source) |
3323 { | |
3324 retval = Internal_FadeInChannelTimed(-1, data, loops, fade_ticks, expire_ticks); | |
3325 if(-1 == retval) | |
3326 { | |
3327 return 0; | |
3328 } | |
3329 else | |
3330 { | |
3331 return Internal_GetSource(retval); | |
3332 } | |
3333 } | |
3334 | |
3335 channel = Internal_GetChannel(source); | |
3336 if(-1 == channel) | |
3337 { | |
3338 ALmixer_SetError("Cannot FadeIn source: %s", ALmixer_GetError()); | |
3339 return 0; | |
3340 } | |
3341 retval = Internal_FadeInChannelTimed(channel, data, loops, fade_ticks, expire_ticks); | |
3342 if(-1 == retval) | |
3343 { | |
3344 return 0; | |
3345 } | |
3346 else | |
3347 { | |
3348 return source; | |
3349 } | |
3350 /* make compiler happy */ | |
3351 return 0; | |
3352 } | |
3353 | |
3354 | |
3355 | |
3356 | |
3357 /* Will fade out currently playing channels. | |
3358 * 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
|
3359 static ALint Internal_FadeOutChannel(ALint channel, ALuint ticks) |
0 | 3360 { |
3361 ALfloat value; | |
3362 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3363 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3364 ALuint counter = 0; |
0 | 3365 |
3366 /* We can't accept 0 as a value because of div-by-zero. | |
3367 * If zero, just call Halt at normal | |
3368 * volume | |
3369 */ | |
3370 if(0 == ticks) | |
3371 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3372 return Internal_HaltChannel(channel, AL_TRUE); |
0 | 3373 } |
3374 | |
3375 | |
3376 if(channel >= Number_of_Channels_global) | |
3377 { | |
3378 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); | |
3379 return -1; | |
3380 } | |
3381 | |
3382 if(channel >= 0) | |
3383 { | |
3384 if(ALmixer_Channel_List[channel].channel_in_use) | |
3385 { | |
3386 /* Get the current volume */ | |
3387 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
|
3388 AL_GAIN, &value); |
0 | 3389 ALmixer_Channel_List[channel].fade_start_volume = value; |
3390 if((error = alGetError()) != AL_NO_ERROR) | |
3391 { | |
3392 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
|
3393 alGetString(error)); |
0 | 3394 } |
3395 | |
3396 /* Get the Min volume */ | |
3397 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3398 AL_MIN_GAIN, &value); | |
3399 if((error = alGetError()) != AL_NO_ERROR) | |
3400 { | |
3401 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
|
3402 alGetString(error)); |
0 | 3403 } |
3404 ALmixer_Channel_List[channel].fade_end_volume = value; | |
3405 | |
3406 /* Set expire start time */ | |
3407 ALmixer_Channel_List[channel].start_time = current_time; | |
3408 /* Set the expire ticks */ | |
3409 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
3410 /* Set fade start time */ | |
3411 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3412 /* Set the fade expire ticks */ | |
3413 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3414 /* Enable fading effects via the flag */ | |
3415 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3416 | |
3417 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3418 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3419 | |
3420 counter++; | |
3421 } | |
3422 } | |
3423 /* Else need to fade out all channels */ | |
3424 else | |
3425 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3426 ALint i; |
0 | 3427 for(i=0; i<Number_of_Channels_global; i++) |
3428 { | |
3429 if(ALmixer_Channel_List[i].channel_in_use) | |
3430 { | |
3431 /* Get the current volume */ | |
3432 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
|
3433 AL_GAIN, &value); |
0 | 3434 ALmixer_Channel_List[i].fade_start_volume = value; |
3435 if((error = alGetError()) != AL_NO_ERROR) | |
3436 { | |
3437 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
|
3438 alGetString(error)); |
0 | 3439 } |
3440 | |
3441 /* Get the Min volume */ | |
3442 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
3443 AL_MIN_GAIN, &value); | |
3444 if((error = alGetError()) != AL_NO_ERROR) | |
3445 { | |
3446 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
|
3447 alGetString(error)); |
0 | 3448 } |
3449 ALmixer_Channel_List[i].fade_end_volume = value; | |
3450 | |
3451 /* Set expire start time */ | |
3452 ALmixer_Channel_List[i].start_time = current_time; | |
3453 /* Set the expire ticks */ | |
3454 ALmixer_Channel_List[i].expire_ticks = ticks; | |
3455 /* Set fade start time */ | |
3456 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3457 /* Set the fade expire ticks */ | |
3458 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3459 /* Enable fading effects via the flag */ | |
3460 ALmixer_Channel_List[i].fade_enabled = 1; | |
3461 | |
3462 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3463 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3464 | |
3465 counter++; | |
3466 } | |
3467 } /* End for loop */ | |
3468 } | |
3469 return counter; | |
3470 } | |
3471 | |
3472 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3473 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
|
3474 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3475 ALint channel; |
0 | 3476 if(0 == source) |
3477 { | |
3478 return Internal_FadeOutChannel(-1, ticks); | |
3479 } | |
3480 | |
3481 channel = Internal_GetChannel(source); | |
3482 if(-1 == channel) | |
3483 { | |
3484 ALmixer_SetError("Cannot FadeOut source: %s", ALmixer_GetError()); | |
3485 return -1; | |
3486 } | |
3487 return Internal_FadeOutChannel(channel, ticks); | |
3488 } | |
3489 | |
3490 | |
3491 /* Will fade currently playing channels. | |
3492 * It starts at the current volume level and go to target | |
3493 * Only affects channels that are playing | |
3494 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3495 static ALint Internal_FadeChannel(ALint channel, ALuint ticks, ALfloat volume) |
0 | 3496 { |
3497 ALfloat value; | |
3498 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3499 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3500 ALuint counter = 0; |
0 | 3501 |
3502 if(channel >= Number_of_Channels_global) | |
3503 { | |
3504 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); | |
3505 return -1; | |
3506 } | |
3507 | |
3508 if(channel >= 0) | |
3509 { | |
3510 if(volume < ALmixer_Channel_List[channel].min_volume) | |
3511 { | |
3512 volume = ALmixer_Channel_List[channel].min_volume; | |
3513 } | |
3514 else if(volume > ALmixer_Channel_List[channel].max_volume) | |
3515 { | |
3516 volume = ALmixer_Channel_List[channel].max_volume; | |
3517 } | |
3518 | |
3519 if(ALmixer_Channel_List[channel].channel_in_use) | |
3520 { | |
3521 if(ticks > 0) | |
3522 { | |
3523 /* Get the current volume */ | |
3524 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
|
3525 AL_GAIN, &value); |
0 | 3526 if((error = alGetError()) != AL_NO_ERROR) |
3527 { | |
3528 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
|
3529 alGetString(error)); |
0 | 3530 } |
3531 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3532 | |
3533 /* Set the target volume */ | |
3534 ALmixer_Channel_List[channel].fade_end_volume = volume; | |
3535 | |
3536 /* Set fade start time */ | |
3537 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3538 /* Set the fade expire ticks */ | |
3539 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3540 /* Enable fading effects via the flag */ | |
3541 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3542 | |
3543 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3544 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3545 } | |
3546 else | |
3547 { | |
3548 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
|
3549 AL_GAIN, volume); |
0 | 3550 if((error = alGetError()) != AL_NO_ERROR) |
3551 { | |
3552 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
|
3553 alGetString(error)); |
0 | 3554 } |
3555 } | |
3556 counter++; | |
3557 } | |
3558 } | |
3559 /* Else need to fade out all channels */ | |
3560 else | |
3561 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3562 ALint i; |
0 | 3563 for(i=0; i<Number_of_Channels_global; i++) |
3564 { | |
3565 if(volume < ALmixer_Channel_List[i].min_volume) | |
3566 { | |
3567 volume = ALmixer_Channel_List[i].min_volume; | |
3568 } | |
3569 else if(volume > ALmixer_Channel_List[i].max_volume) | |
3570 { | |
3571 volume = ALmixer_Channel_List[i].max_volume; | |
3572 } | |
3573 | |
3574 if(ALmixer_Channel_List[i].channel_in_use) | |
3575 { | |
3576 if(ticks > 0) | |
3577 { | |
3578 /* Get the current volume */ | |
3579 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
|
3580 AL_GAIN, &value); |
0 | 3581 if((error = alGetError()) != AL_NO_ERROR) |
3582 { | |
3583 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
|
3584 alGetString(error)); |
0 | 3585 } |
3586 ALmixer_Channel_List[i].fade_start_volume = value; | |
3587 | |
3588 /* Set target volume */ | |
3589 ALmixer_Channel_List[i].fade_end_volume = volume; | |
3590 | |
3591 /* Set fade start time */ | |
3592 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3593 /* Set the fade expire ticks */ | |
3594 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3595 /* Enable fading effects via the flag */ | |
3596 ALmixer_Channel_List[i].fade_enabled = 1; | |
3597 | |
3598 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3599 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3600 } | |
3601 else | |
3602 { | |
3603 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
|
3604 AL_GAIN, volume); |
0 | 3605 if((error = alGetError()) != AL_NO_ERROR) |
3606 { | |
3607 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
|
3608 alGetString(error)); |
0 | 3609 } |
3610 } | |
3611 counter++; | |
3612 } | |
3613 } /* End for loop */ | |
3614 } | |
3615 return counter; | |
3616 } | |
3617 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3618 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
|
3619 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3620 ALint channel; |
0 | 3621 if(0 == source) |
3622 { | |
3623 return Internal_FadeChannel(-1, ticks, volume); | |
3624 } | |
3625 | |
3626 channel = Internal_GetChannel(source); | |
3627 if(-1 == channel) | |
3628 { | |
3629 ALmixer_SetError("Cannot Fade source: %s", ALmixer_GetError()); | |
3630 return -1; | |
3631 } | |
3632 return Internal_FadeChannel(channel, ticks, volume); | |
3633 } | |
3634 | |
3635 | |
3636 | |
3637 | |
3638 /* Set a volume regardless if it's in use or not. | |
3639 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3640 static ALboolean Internal_SetVolumeChannel(ALint channel, ALfloat volume) |
0 | 3641 { |
3642 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3643 ALboolean retval = AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3644 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3645 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3646 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3647 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
|
3648 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3649 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3650 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3651 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3652 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3653 if(volume < 0.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3654 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3655 volume = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3656 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3657 else if(volume > 1.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3658 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3659 volume = 1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3660 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3661 alSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3662 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3663 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3664 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3665 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3666 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3667 retval = AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3668 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3669 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3670 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3671 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3672 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3673 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
|
3674 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3675 if(volume < 0.0f) |
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 volume = 0.0f; |
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 else if(volume > 1.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 = 1.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 alSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3684 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3685 if((error = alGetError()) != AL_NO_ERROR) |
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 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3688 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3689 retval = AL_FALSE; |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3692 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3693 return retval; |
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 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
|
3697 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3698 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3699 if(0 == source) |
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 return Internal_SetVolumeChannel(-1, volume); |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3704 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3705 if(-1 == channel) |
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 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
|
3708 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3709 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3710 return Internal_SetVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3711 } |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3714 static ALfloat Internal_GetVolumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3715 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3716 ALfloat value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3717 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3718 ALfloat running_total = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3719 ALfloat retval = 0.0f; |
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 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3722 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3723 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
|
3724 return -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3725 } |
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 if(channel >= 0) |
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 alGetSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3730 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3731 if((error = alGetError()) != AL_NO_ERROR) |
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("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3734 retval = -1.0f; |
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 else |
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 retval = value; |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3741 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3742 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3743 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3744 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
|
3745 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3746 alGetSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3747 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3748 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3749 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3750 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3751 retval = -1; |
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 else |
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 running_total += value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3756 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3757 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3758 if(0 == Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3759 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3760 ALmixer_SetError("No channels are allocated"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3761 retval = -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3762 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3763 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3764 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3765 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
|
3766 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3767 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3768 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3769 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3770 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3771 static ALfloat Internal_GetVolumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3772 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3773 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3774 if(0 == source) |
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 return Internal_GetVolumeChannel(-1); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3777 } |
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 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3780 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3781 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3782 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
|
3783 return -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3784 } |
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 return Internal_GetVolumeChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3787 } |
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 |
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 /* 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
|
3792 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3793 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
|
3794 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3795 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3796 ALboolean retval = AL_TRUE; |
0 | 3797 |
3798 if(channel >= Number_of_Channels_global) | |
3799 { | |
3800 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
|
3801 return AL_FALSE; |
0 | 3802 } |
3803 | |
3804 if(channel >= 0) | |
3805 { | |
3806 if(volume < 0.0f) | |
3807 { | |
3808 volume = 0.0f; | |
3809 } | |
3810 else if(volume > 1.0f) | |
3811 { | |
3812 volume = 1.0f; | |
3813 } | |
3814 ALmixer_Channel_List[channel].max_volume = volume; | |
3815 alSourcef(ALmixer_Channel_List[channel].alsource, | |
3816 AL_MAX_GAIN, volume); | |
3817 if((error = alGetError()) != AL_NO_ERROR) | |
3818 { | |
3819 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3820 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3821 retval = AL_FALSE; |
0 | 3822 } |
3823 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
3824 { | |
3825 ALmixer_Channel_List[channel].min_volume = volume; | |
3826 alSourcef(ALmixer_Channel_List[channel].alsource, | |
3827 AL_MIN_GAIN, volume); | |
3828 if((error = alGetError()) != AL_NO_ERROR) | |
3829 { | |
3830 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3831 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3832 retval = AL_FALSE; |
0 | 3833 } |
3834 } | |
3835 } | |
3836 else | |
3837 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3838 ALint i; |
0 | 3839 for(i=0; i<Number_of_Channels_global; i++) |
3840 { | |
3841 if(volume < 0.0f) | |
3842 { | |
3843 volume = 0.0f; | |
3844 } | |
3845 else if(volume > 1.0f) | |
3846 { | |
3847 volume = 1.0f; | |
3848 } | |
3849 ALmixer_Channel_List[i].max_volume = volume; | |
3850 alSourcef(ALmixer_Channel_List[i].alsource, | |
3851 AL_MAX_GAIN, volume); | |
3852 if((error = alGetError()) != AL_NO_ERROR) | |
3853 { | |
3854 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3855 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3856 retval = AL_FALSE; |
0 | 3857 } |
3858 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
3859 { | |
3860 ALmixer_Channel_List[i].min_volume = volume; | |
3861 alSourcef(ALmixer_Channel_List[i].alsource, | |
3862 AL_MIN_GAIN, volume); | |
3863 if((error = alGetError()) != AL_NO_ERROR) | |
3864 { | |
3865 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3866 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3867 retval = AL_FALSE; |
0 | 3868 } |
3869 } | |
3870 } | |
3871 } | |
3872 return retval; | |
3873 } | |
3874 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3875 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
|
3876 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3877 ALint channel; |
0 | 3878 if(0 == source) |
3879 { | |
3880 return Internal_SetMaxVolumeChannel(-1, volume); | |
3881 } | |
3882 | |
3883 channel = Internal_GetChannel(source); | |
3884 if(-1 == channel) | |
3885 { | |
3886 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
|
3887 return AL_FALSE; |
0 | 3888 } |
3889 return Internal_SetMaxVolumeChannel(channel, volume); | |
3890 } | |
3891 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3892 static ALfloat Internal_GetMaxVolumeChannel(ALint channel) |
0 | 3893 { |
3894 /* | |
3895 ALfloat value; | |
3896 ALenum error; | |
3897 */ | |
3898 ALfloat running_total = 0.0f; | |
3899 ALfloat retval = 0.0f; | |
3900 | |
3901 if(channel >= Number_of_Channels_global) | |
3902 { | |
3903 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); | |
3904 return -1.0f; | |
3905 } | |
3906 | |
3907 if(channel >= 0) | |
3908 { | |
3909 /* | |
3910 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3911 AL_GAIN, &value); | |
3912 if((error = alGetError()) != AL_NO_ERROR) | |
3913 { | |
3914 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3915 alGetString(error) ); |
0 | 3916 retval = -1.0f; |
3917 } | |
3918 else | |
3919 { | |
3920 retval = value; | |
3921 } | |
3922 */ | |
3923 retval = ALmixer_Channel_List[channel].max_volume; | |
3924 | |
3925 } | |
3926 else | |
3927 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3928 ALint i; |
0 | 3929 for(i=0; i<Number_of_Channels_global; i++) |
3930 { | |
3931 /* | |
3932 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
3933 AL_GAIN, &value); | |
3934 if((error = alGetError()) != AL_NO_ERROR) | |
3935 { | |
3936 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3937 alGetString(error) ); |
0 | 3938 retval = -1; |
3939 } | |
3940 else | |
3941 { | |
3942 running_total += value; | |
3943 } | |
3944 */ | |
3945 running_total += ALmixer_Channel_List[i].max_volume; | |
3946 } | |
3947 if(0 == Number_of_Channels_global) | |
3948 { | |
3949 ALmixer_SetError("No channels are allocated"); | |
3950 retval = -1.0f; | |
3951 } | |
3952 else | |
3953 { | |
3954 retval = running_total / Number_of_Channels_global; | |
3955 } | |
3956 } | |
3957 return retval; | |
3958 } | |
3959 | |
3960 static ALfloat Internal_GetMaxVolumeSource(ALuint source) | |
3961 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3962 ALint channel; |
0 | 3963 if(0 == source) |
3964 { | |
3965 return Internal_GetMaxVolumeChannel(-1); | |
3966 } | |
3967 | |
3968 channel = Internal_GetChannel(source); | |
3969 if(-1 == channel) | |
3970 { | |
3971 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
3972 return -1.0f; | |
3973 } | |
3974 | |
3975 return Internal_GetMaxVolumeChannel(channel); | |
3976 } | |
3977 | |
3978 | |
3979 /* Set a volume regardless if it's in use or not. | |
3980 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3981 static ALboolean Internal_SetMinVolumeChannel(ALint channel, ALfloat volume) |
0 | 3982 { |
3983 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3984 ALboolean retval = AL_TRUE; |
0 | 3985 |
3986 if(channel >= Number_of_Channels_global) | |
3987 { | |
3988 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
|
3989 return AL_FALSE; |
0 | 3990 } |
3991 | |
3992 if(channel >= 0) | |
3993 { | |
3994 if(volume < 0.0f) | |
3995 { | |
3996 volume = 0.0f; | |
3997 } | |
3998 else if(volume > 1.0f) | |
3999 { | |
4000 volume = 1.0f; | |
4001 } | |
4002 ALmixer_Channel_List[channel].min_volume = volume; | |
4003 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4004 AL_MIN_GAIN, volume); | |
4005 if((error = alGetError()) != AL_NO_ERROR) | |
4006 { | |
4007 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4008 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4009 retval = AL_FALSE; |
0 | 4010 } |
4011 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
4012 { | |
4013 ALmixer_Channel_List[channel].max_volume = volume; | |
4014 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4015 AL_MAX_GAIN, volume); | |
4016 if((error = alGetError()) != AL_NO_ERROR) | |
4017 { | |
4018 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4019 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4020 retval = AL_FALSE; |
0 | 4021 } |
4022 } | |
4023 } | |
4024 else | |
4025 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4026 ALint i; |
0 | 4027 for(i=0; i<Number_of_Channels_global; i++) |
4028 { | |
4029 if(volume < 0.0f) | |
4030 { | |
4031 volume = 0.0f; | |
4032 } | |
4033 else if(volume > 1.0f) | |
4034 { | |
4035 volume = 1.0f; | |
4036 } | |
4037 ALmixer_Channel_List[i].min_volume = volume; | |
4038 alSourcef(ALmixer_Channel_List[i].alsource, | |
4039 AL_MIN_GAIN, volume); | |
4040 if((error = alGetError()) != AL_NO_ERROR) | |
4041 { | |
4042 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4043 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4044 retval = AL_FALSE; |
0 | 4045 } |
4046 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
4047 { | |
4048 ALmixer_Channel_List[i].max_volume = volume; | |
4049 alSourcef(ALmixer_Channel_List[i].alsource, | |
4050 AL_MAX_GAIN, volume); | |
4051 if((error = alGetError()) != AL_NO_ERROR) | |
4052 { | |
4053 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4054 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4055 retval = AL_FALSE; |
0 | 4056 } |
4057 } | |
4058 } | |
4059 } | |
4060 return retval; | |
4061 } | |
4062 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4063 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
|
4064 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4065 ALint channel; |
0 | 4066 if(0 == source) |
4067 { | |
4068 return Internal_SetMinVolumeChannel(-1, volume); | |
4069 } | |
4070 | |
4071 channel = Internal_GetChannel(source); | |
4072 if(-1 == channel) | |
4073 { | |
4074 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
|
4075 return AL_FALSE; |
0 | 4076 } |
4077 return Internal_SetMinVolumeChannel(channel, volume); | |
4078 } | |
4079 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4080 static ALfloat Internal_GetMinVolumeChannel(ALint channel) |
0 | 4081 { |
4082 /* | |
4083 ALfloat value; | |
4084 ALenum error; | |
4085 */ | |
4086 ALfloat running_total = 0.0f; | |
4087 ALfloat retval = 0.0f; | |
4088 | |
4089 if(channel >= Number_of_Channels_global) | |
4090 { | |
4091 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); | |
4092 return -1.0f; | |
4093 } | |
4094 | |
4095 if(channel >= 0) | |
4096 { | |
4097 /* | |
4098 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
4099 AL_GAIN, &value); | |
4100 if((error = alGetError()) != AL_NO_ERROR) | |
4101 { | |
4102 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4103 alGetString(error) ); |
0 | 4104 retval = -1.0f; |
4105 } | |
4106 else | |
4107 { | |
4108 retval = value; | |
4109 } | |
4110 */ | |
4111 retval = ALmixer_Channel_List[channel].min_volume; | |
4112 | |
4113 } | |
4114 else | |
4115 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4116 ALint i; |
0 | 4117 for(i=0; i<Number_of_Channels_global; i++) |
4118 { | |
4119 /* | |
4120 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
4121 AL_GAIN, &value); | |
4122 if((error = alGetError()) != AL_NO_ERROR) | |
4123 { | |
4124 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4125 alGetString(error) ); |
0 | 4126 retval = -1; |
4127 } | |
4128 else | |
4129 { | |
4130 running_total += value; | |
4131 } | |
4132 */ | |
4133 running_total += ALmixer_Channel_List[i].min_volume; | |
4134 } | |
4135 if(0 == Number_of_Channels_global) | |
4136 { | |
4137 ALmixer_SetError("No channels are allocated"); | |
4138 retval = -1.0f; | |
4139 } | |
4140 else | |
4141 { | |
4142 retval = running_total / Number_of_Channels_global; | |
4143 } | |
4144 } | |
4145 return retval; | |
4146 } | |
4147 | |
4148 static ALfloat Internal_GetMinVolumeSource(ALuint source) | |
4149 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4150 ALint channel; |
0 | 4151 if(0 == source) |
4152 { | |
4153 return Internal_GetMinVolumeChannel(-1); | |
4154 } | |
4155 | |
4156 channel = Internal_GetChannel(source); | |
4157 if(-1 == channel) | |
4158 { | |
4159 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
4160 return -1.0f; | |
4161 } | |
4162 | |
4163 return Internal_GetMinVolumeChannel(channel); | |
4164 } | |
4165 | |
4166 | |
4167 /* Changes the listener volume */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4168 static ALboolean Internal_SetMasterVolume(ALfloat volume) |
0 | 4169 { |
4170 ALenum error; | |
4171 alListenerf(AL_GAIN, volume); | |
4172 if((error = alGetError()) != AL_NO_ERROR) | |
4173 { | |
4174 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4175 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4176 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4177 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4178 return AL_TRUE; |
0 | 4179 } |
4180 | |
4181 static ALfloat Internal_GetMasterVolume() | |
4182 { | |
4183 ALenum error; | |
4184 ALfloat volume; | |
4185 alGetListenerf(AL_GAIN, &volume); | |
4186 if((error = alGetError()) != AL_NO_ERROR) | |
4187 { | |
4188 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4189 alGetString(error) ); |
0 | 4190 return -1.0f; |
4191 } | |
4192 return volume; | |
4193 } | |
4194 | |
4195 | |
4196 | |
4197 | |
4198 /* Will fade out currently playing channels. | |
4199 * 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
|
4200 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
|
4201 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4202 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4203 ALuint counter = 0; |
0 | 4204 |
4205 /* We can't accept 0 as a value because of div-by-zero. | |
4206 * If zero, just call Halt at normal | |
4207 * volume | |
4208 */ | |
4209 if(0 == ticks) | |
4210 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4211 return Internal_HaltChannel(channel, AL_TRUE); |
0 | 4212 } |
4213 if(ticks < -1) | |
4214 { | |
4215 ticks = -1; | |
4216 } | |
4217 | |
4218 | |
4219 if(channel >= Number_of_Channels_global) | |
4220 { | |
4221 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); | |
4222 return -1; | |
4223 } | |
4224 | |
4225 if(channel >= 0) | |
4226 { | |
4227 if(ALmixer_Channel_List[channel].channel_in_use) | |
4228 { | |
4229 /* Set expire start time */ | |
4230 ALmixer_Channel_List[channel].start_time = current_time; | |
4231 /* Set the expire ticks */ | |
4232 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
4233 | |
4234 counter++; | |
4235 } | |
4236 } | |
4237 /* Else need to fade out all channels */ | |
4238 else | |
4239 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4240 ALint i; |
0 | 4241 for(i=0; i<Number_of_Channels_global; i++) |
4242 { | |
4243 if(ALmixer_Channel_List[i].channel_in_use) | |
4244 { | |
4245 /* Set expire start time */ | |
4246 ALmixer_Channel_List[i].start_time = current_time; | |
4247 /* Set the expire ticks */ | |
4248 ALmixer_Channel_List[i].expire_ticks = ticks; | |
4249 | |
4250 counter++; | |
4251 } | |
4252 } /* End for loop */ | |
4253 } | |
4254 return counter; | |
4255 } | |
4256 | |
4257 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4258 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
|
4259 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4260 ALint channel; |
0 | 4261 if(0 == source) |
4262 { | |
4263 return Internal_ExpireChannel(-1, ticks); | |
4264 } | |
4265 | |
4266 channel = Internal_GetChannel(source); | |
4267 if(-1 == channel) | |
4268 { | |
4269 ALmixer_SetError("Cannot Expire source: %s", ALmixer_GetError()); | |
4270 return -1; | |
4271 } | |
4272 return Internal_ExpireChannel(channel, ticks); | |
4273 } | |
4274 | |
4275 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4276 static ALint Internal_QueryChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4277 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4278 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4279 ALint counter = 0; |
0 | 4280 if(channel >= Number_of_Channels_global) |
4281 { | |
4282 ALmixer_SetError("Invalid channel: %d", channel); | |
4283 return -1; | |
4284 } | |
4285 | |
4286 if(channel >= 0) | |
4287 { | |
4288 return ALmixer_Channel_List[channel].channel_in_use; | |
4289 } | |
4290 | |
4291 /* Else, return the number of channels in use */ | |
4292 for(i=0; i<Number_of_Channels_global; i++) | |
4293 { | |
4294 if(ALmixer_Channel_List[i].channel_in_use) | |
4295 { | |
4296 counter++; | |
4297 } | |
4298 } | |
4299 return counter; | |
4300 } | |
4301 | |
4302 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4303 static ALint Internal_QuerySource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4304 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4305 ALint channel; |
0 | 4306 if(0 == source) |
4307 { | |
4308 return Internal_QueryChannel(-1); | |
4309 } | |
4310 | |
4311 channel = Internal_GetChannel(source); | |
4312 if(-1 == channel) | |
4313 { | |
4314 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4315 return -1; | |
4316 } | |
4317 | |
4318 return Internal_QueryChannel(channel); | |
4319 } | |
4320 | |
4321 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4322 static ALuint Internal_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4323 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4324 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4325 ALuint counter = 0; |
0 | 4326 |
4327 | |
4328 /* Else, return the number of channels in use */ | |
4329 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4330 { | |
4331 if(ALmixer_Channel_List[i].channel_in_use) | |
4332 { | |
4333 counter++; | |
4334 } | |
4335 } | |
4336 return counter; | |
4337 } | |
4338 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4339 static ALuint Internal_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4340 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4341 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4342 ALuint counter = 0; |
0 | 4343 |
4344 | |
4345 /* Else, return the number of channels in use */ | |
4346 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4347 { | |
4348 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4349 { | |
4350 counter++; | |
4351 } | |
4352 } | |
4353 return counter; | |
4354 } | |
4355 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4356 static ALuint Internal_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4357 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4358 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4359 ALuint counter = 0; |
0 | 4360 |
4361 | |
4362 /* Else, return the number of channels in use */ | |
4363 for(i=0; i<Number_of_Channels_global; i++) | |
4364 { | |
4365 if(ALmixer_Channel_List[i].channel_in_use) | |
4366 { | |
4367 counter++; | |
4368 } | |
4369 } | |
4370 return counter; | |
4371 } | |
4372 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4373 static ALuint Internal_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4374 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4375 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4376 ALuint counter = 0; |
0 | 4377 |
4378 | |
4379 /* Else, return the number of channels in use */ | |
4380 for(i=0; i<Number_of_Channels_global; i++) | |
4381 { | |
4382 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4383 { | |
4384 counter++; | |
4385 } | |
4386 } | |
4387 return counter; | |
4388 } | |
4389 | |
4390 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4391 static ALint Internal_PlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4392 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4393 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4394 ALint counter = 0; |
0 | 4395 ALint state; |
4396 | |
4397 if(channel >= Number_of_Channels_global) | |
4398 { | |
4399 ALmixer_SetError("Invalid channel: %d", channel); | |
4400 return -1; | |
4401 } | |
4402 | |
4403 if(channel >= 0) | |
4404 { | |
4405 if(ALmixer_Channel_List[channel].channel_in_use) | |
4406 { | |
4407 alGetSourcei( | |
4408 ALmixer_Channel_List[channel].alsource, | |
4409 AL_SOURCE_STATE, &state | |
4410 ); | |
4411 if(AL_PLAYING == state) | |
4412 { | |
4413 return 1; | |
4414 } | |
4415 } | |
4416 return 0; | |
4417 } | |
4418 | |
4419 /* Else, return the number of channels in use */ | |
4420 for(i=0; i<Number_of_Channels_global; i++) | |
4421 { | |
4422 if(ALmixer_Channel_List[i].channel_in_use) | |
4423 { | |
4424 alGetSourcei( | |
4425 ALmixer_Channel_List[i].alsource, | |
4426 AL_SOURCE_STATE, &state | |
4427 ); | |
4428 if(AL_PLAYING == state) | |
4429 { | |
4430 counter++; | |
4431 } | |
4432 } | |
4433 } | |
4434 return counter; | |
4435 } | |
4436 | |
4437 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4438 static ALint Internal_PlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4439 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4440 ALint channel; |
0 | 4441 if(0 == source) |
4442 { | |
4443 return Internal_PlayingChannel(-1); | |
4444 } | |
4445 | |
4446 channel = Internal_GetChannel(source); | |
4447 if(-1 == channel) | |
4448 { | |
4449 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4450 return -1; | |
4451 } | |
4452 | |
4453 return Internal_PlayingChannel(channel); | |
4454 } | |
4455 | |
4456 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4457 static ALint Internal_PausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4458 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4459 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4460 ALint counter = 0; |
0 | 4461 ALint state; |
4462 | |
4463 if(channel >= Number_of_Channels_global) | |
4464 { | |
4465 ALmixer_SetError("Invalid channel: %d", channel); | |
4466 return -1; | |
4467 } | |
4468 | |
4469 if(channel >= 0) | |
4470 { | |
4471 if(ALmixer_Channel_List[channel].channel_in_use) | |
4472 { | |
4473 alGetSourcei( | |
4474 ALmixer_Channel_List[channel].alsource, | |
4475 AL_SOURCE_STATE, &state | |
4476 ); | |
4477 if(AL_PAUSED == state) | |
4478 { | |
4479 return 1; | |
4480 } | |
4481 } | |
4482 return 0; | |
4483 } | |
4484 | |
4485 /* Else, return the number of channels in use */ | |
4486 for(i=0; i<Number_of_Channels_global; i++) | |
4487 { | |
4488 if(ALmixer_Channel_List[i].channel_in_use) | |
4489 { | |
4490 alGetSourcei( | |
4491 ALmixer_Channel_List[i].alsource, | |
4492 AL_SOURCE_STATE, &state | |
4493 ); | |
4494 if(AL_PAUSED == state) | |
4495 { | |
4496 counter++; | |
4497 } | |
4498 } | |
4499 } | |
4500 return counter; | |
4501 } | |
4502 | |
4503 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4504 static ALint Internal_PausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4505 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4506 ALint channel; |
0 | 4507 if(0 == source) |
4508 { | |
4509 return Internal_PausedChannel(-1); | |
4510 } | |
4511 | |
4512 channel = Internal_GetChannel(source); | |
4513 if(-1 == channel) | |
4514 { | |
4515 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4516 return -1; | |
4517 } | |
4518 | |
4519 return Internal_PausedChannel(channel); | |
4520 } | |
4521 | |
4522 | |
4523 | |
4524 | |
4525 | |
4526 | |
4527 /* Private function for Updating ALmixer. | |
4528 * This is a very big and ugly function. | |
4529 * It should return the number of buffers that were | |
4530 * queued during the call. The value might be | |
4531 * used to guage how long you might wait to | |
4532 * call the next update loop in case you are worried | |
4533 * about preserving CPU cycles. The idea is that | |
4534 * when a buffer is queued, there was probably some | |
4535 * CPU intensive looping which took awhile. | |
4536 * 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
|
4537 * Timing the call with ALmixer_GetTicks() would produce |
0 | 4538 * more accurate information. |
4539 * Returns a negative value if there was an error, | |
4540 * the value being the number of errors. | |
4541 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4542 static ALint Update_ALmixer(void* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4543 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4544 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4545 ALint error_flag = 0; |
0 | 4546 ALenum error; |
4547 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4548 ALint i=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4549 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4550 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4551 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4552 #endif |
0 | 4553 if(0 == ALmixer_Initialized) |
4554 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4555 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4556 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4557 #endif |
0 | 4558 return 0; |
4559 } | |
4560 | |
4561 /* Check the quick flag to see if anything needs updating */ | |
4562 /* If anything is playing, then we have to do work */ | |
4563 if( 0 == Is_Playing_global) | |
4564 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4565 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4566 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4567 #endif |
0 | 4568 return 0; |
4569 } | |
4570 /* Clear error */ | |
4571 if((error = alGetError()) != AL_NO_ERROR) | |
4572 { | |
4573 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
|
4574 alGetString(error)); |
0 | 4575 } |
4576 alGetError(); | |
4577 | |
4578 for(i=0; i<Number_of_Channels_global; i++) | |
4579 { | |
4580 if( ALmixer_Channel_List[i].channel_in_use ) | |
4581 { | |
4582 | |
4583 /* For simplicity, before we do anything else, | |
4584 * we can check the timeout and fading values | |
4585 * and do the appropriate things | |
4586 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4587 ALuint current_time = ALmixer_GetTicks(); |
0 | 4588 |
4589 /* Check to see if we need to halt due to Timed play */ | |
4590 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
4591 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4592 ALuint target_time = (ALuint)ALmixer_Channel_List[i].expire_ticks |
0 | 4593 + ALmixer_Channel_List[i].start_time; |
4594 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4595 AL_SOURCE_STATE, &state); | |
4596 if((error = alGetError()) != AL_NO_ERROR) | |
4597 { | |
4598 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
|
4599 alGetString(error)); |
0 | 4600 } |
4601 | |
4602 /* Check the time, and also make sure that it is not | |
4603 * paused (if paused, we don't want to make the | |
4604 * evaluation because when resumed, we will adjust | |
4605 * the times to compensate for the pause). | |
4606 */ | |
4607 if( (current_time >= target_time) | |
4608 && (state != AL_PAUSED) ) | |
4609 { | |
4610 /* Stop the playback */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4611 Internal_HaltChannel(i, AL_TRUE); |
0 | 4612 if((error = alGetError()) != AL_NO_ERROR) |
4613 { | |
4614 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
|
4615 alGetString(error)); |
0 | 4616 } |
4617 | |
4618 /* Everything should be done so go on to the next loop */ | |
4619 continue; | |
4620 } | |
4621 } /* End if time expired check */ | |
4622 | |
4623 /* Check to see if we need to adjust the volume for fading */ | |
4624 if( ALmixer_Channel_List[i].fade_enabled ) | |
4625 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4626 ALuint target_time = ALmixer_Channel_List[i].fade_expire_ticks |
0 | 4627 + ALmixer_Channel_List[i].fade_start_time; |
4628 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4629 AL_SOURCE_STATE, &state); | |
4630 if((error = alGetError()) != AL_NO_ERROR) | |
4631 { | |
4632 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
|
4633 alGetString(error)); |
0 | 4634 } |
4635 | |
4636 /* Check the time, and also make sure that it is not | |
4637 * paused (if paused, we don't want to make the | |
4638 * evaluation because when resumed, we will adjust | |
4639 * the times to compensate for the pause). | |
4640 */ | |
4641 if(state != AL_PAUSED) | |
4642 { | |
4643 ALfloat t; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4644 ALuint delta_time; |
0 | 4645 ALfloat current_volume; |
4646 if(current_time >= target_time) | |
4647 { | |
4648 /* Need to constrain value to the end time | |
4649 * (can't go pass the value for calculations) | |
4650 */ | |
4651 current_time = target_time; | |
4652 /* We can disable the fade flag now */ | |
4653 ALmixer_Channel_List[i].fade_enabled = 0; | |
4654 } | |
4655 /* Use the linear interpolation formula: | |
4656 * X = (1-t)x0 + tx1 | |
4657 * where x0 would be the start value | |
4658 * and x1 is the final value | |
4659 * and t is delta_time*inv_time (adjusts 0 <= time <= 1) | |
4660 * delta_time = current_time-start_time | |
4661 * inv_time = 1/ (end_time-start_time) | |
4662 * so t = current_time-start_time / (end_time-start_time) | |
4663 * | |
4664 */ | |
4665 delta_time = current_time - ALmixer_Channel_List[i].fade_start_time; | |
4666 t = (ALfloat) delta_time * ALmixer_Channel_List[i].fade_inv_time; | |
4667 | |
4668 current_volume = (1.0f-t) * ALmixer_Channel_List[i].fade_start_volume | |
4669 + t * ALmixer_Channel_List[i].fade_end_volume; | |
4670 | |
4671 /* Set the volume */ | |
4672 alSourcef(ALmixer_Channel_List[i].alsource, | |
4673 AL_MAX_GAIN, current_volume); | |
4674 if((error = alGetError()) != AL_NO_ERROR) | |
4675 { | |
4676 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
|
4677 alGetString(error)); |
0 | 4678 } |
4679 | |
4680 /* | |
4681 fprintf(stderr, "Current time =%d\n", current_time); | |
4682 fprintf(stderr, "Current vol=%f on channel %d\n", current_volume, i); | |
4683 */ | |
4684 } /* End if not PAUSED */ | |
4685 } /* End if fade_enabled */ | |
4686 | |
4687 | |
4688 /* Okay, now that the time expired and fading stuff | |
4689 * is done, do the rest of the hard stuff | |
4690 */ | |
4691 | |
4692 | |
4693 /* For predecoded, check to see if done */ | |
4694 if( ALmixer_Channel_List[i].almixer_data->decoded_all ) | |
4695 { | |
4696 | |
4697 #if 0 | |
4698 /********* Remove this **********/ | |
4699 ALint buffers_processed; | |
4700 ALint buffers_still_queued; | |
4701 fprintf(stderr, "For Predecoded\n"); | |
4702 | |
4703 alGetSourcei( | |
4704 ALmixer_Channel_List[i].alsource, | |
4705 AL_SOURCE_STATE, &state | |
4706 ); | |
4707 switch(state) { | |
4708 case AL_PLAYING: | |
4709 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
4710 break; | |
4711 case AL_PAUSED: | |
4712 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
4713 break; | |
4714 case AL_STOPPED: | |
4715 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
4716 break; | |
4717 case AL_INITIAL: | |
4718 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
4719 break; | |
4720 default: | |
4721 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
4722 break; | |
4723 } | |
4724 | |
4725 alGetSourcei( | |
4726 ALmixer_Channel_List[i].alsource, | |
4727 AL_BUFFERS_PROCESSED, &buffers_processed | |
4728 ); | |
4729 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
4730 | |
4731 alGetSourcei( | |
4732 ALmixer_Channel_List[i].alsource, | |
4733 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4734 ); | |
4735 | |
4736 /******** END REMOVE *******/ | |
4737 #endif | |
4738 /* FIXME: Ugh! Somewhere an alError is being thrown ("Invalid Enum Value"), but I can't | |
4739 * find it. It only seems to be thrown for OS X. I placed error messages after every al* | |
4740 * command I could find in the above loops, but the error doesn't seem to show | |
4741 * up until around here. I mistook it for a get queued buffers | |
4742 * error in OS X. I don't think there's an error down there. | |
4743 * For now, I'm clearing the error here. | |
4744 */ | |
4745 | |
4746 if((error = alGetError()) != AL_NO_ERROR) | |
4747 { | |
4748 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
|
4749 alGetString(error)); |
0 | 4750 } |
4751 | |
4752 | |
4753 alGetSourcei( | |
4754 ALmixer_Channel_List[i].alsource, | |
4755 AL_SOURCE_STATE, &state | |
4756 ); | |
4757 if((error = alGetError()) != AL_NO_ERROR) | |
4758 { | |
4759 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
|
4760 alGetString(error)); |
0 | 4761 } |
4762 | |
4763 | |
4764 if(AL_STOPPED == state) | |
4765 { | |
4766 /* Playback has ended. | |
4767 * Loop if necessary, or launch callback | |
4768 * and clear channel (or clear channel and | |
4769 * then launch callback?) | |
4770 */ | |
4771 | |
4772 | |
4773 /* Need to check for loops */ | |
4774 if(ALmixer_Channel_List[i].loops != 0) | |
4775 { | |
4776 /* Corner Case: If the buffer has | |
4777 * been modified using Seek, | |
4778 * the loop will start at the seek | |
4779 * position. | |
4780 */ | |
4781 if(ALmixer_Channel_List[i].loops != -1) | |
4782 { | |
4783 ALmixer_Channel_List[i].loops--; | |
4784 } | |
4785 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
4786 if((error = alGetError()) != AL_NO_ERROR) | |
4787 { | |
4788 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
|
4789 alGetString(error)); |
0 | 4790 } |
4791 continue; | |
4792 } | |
4793 /* No loops. End play. */ | |
4794 else | |
4795 { | |
4796 /* Problem: It seems that when mixing | |
4797 * streamed and predecoded sources, | |
4798 * the previous instance lingers, | |
4799 * so we need to force remove | |
4800 * the data from the source. | |
4801 * The sharing problem | |
4802 * occurs when a previous predecoded buffer is played on | |
4803 * a source, and then a streamed source is played later | |
4804 * on that same source. OpenAL isn't consistently | |
4805 * removing the previous buffer so both get played. | |
4806 * (Different dists seem to have different quirks. | |
4807 * The problem might lead to crashes in the worst case.) | |
4808 */ | |
4809 /* Additional problem: There is another | |
4810 * inconsistency among OpenAL distributions. | |
4811 * Both Loki and Creative Windows seem to keep | |
4812 * the buffer queued which requires removing. | |
4813 * But the Creative Macintosh version does | |
4814 * not have any buffer queued after play | |
4815 * and it returns the error: Invalid Enum Value | |
4816 * if I try to unqueue it. | |
4817 * So I'm going to put in a check to see if I | |
4818 * can detect any buffers queued first | |
4819 * and then unqueue them if I can see them. | |
4820 * Additional note: The new CoreAudio based | |
4821 * implementation leaves it's buffer queued | |
4822 * like Loki and Creative Windows. But | |
4823 * considering all the problems I'm having | |
4824 * with the different distributions, this | |
4825 * check seems reasonable. | |
4826 */ | |
4827 ALint buffers_still_queued; | |
4828 if((error = alGetError()) != AL_NO_ERROR) | |
4829 { | |
4830 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
|
4831 alGetString(error)); |
0 | 4832 } |
4833 | |
4834 alGetSourcei( | |
4835 ALmixer_Channel_List[i].alsource, | |
4836 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4837 ); | |
4838 if((error = alGetError()) != AL_NO_ERROR) | |
4839 { | |
4840 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
|
4841 alGetString(error)); |
0 | 4842 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
|
4843 alGetString(error) ); |
0 | 4844 error_flag--; |
4845 } | |
4846 if(buffers_still_queued > 0) | |
4847 { | |
1 | 4848 |
4849 #if 0 /* This triggers an error in OS X Core Audio. */ | |
4850 alSourceUnqueueBuffers( | |
4851 ALmixer_Channel_List[i].alsource, | |
4852 1, | |
4853 ALmixer_Channel_List[i].almixer_data->buffer | |
4854 ); | |
4855 #else | |
4856 /* fprintf(stderr, "In the Bob Aron section...about to clear source\n"); | |
0 | 4857 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 4858 */ |
0 | 4859 /* Rather than force unqueuing the buffer, let's see if |
4860 * setting the buffer to none works (the OpenAL 1.0 | |
4861 * Reference Annotation suggests this should work). | |
4862 */ | |
4863 alSourcei(ALmixer_Channel_List[i].alsource, | |
4864 AL_BUFFER, AL_NONE); | |
4865 /* | |
4866 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
4867 */ | |
1 | 4868 #endif |
0 | 4869 if((error = alGetError()) != AL_NO_ERROR) |
4870 { | |
4871 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
|
4872 alGetString(error)); |
0 | 4873 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
|
4874 alGetString(error) ); |
0 | 4875 error_flag--; |
4876 } | |
4877 | |
4878 } | |
4879 | |
4880 Clean_Channel(i); | |
4881 /* Subtract counter */ | |
4882 Is_Playing_global--; | |
4883 | |
4884 /* Launch callback */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4885 Invoke_Channel_Done_Callback(i, AL_TRUE); |
0 | 4886 |
4887 /* We're done for this loop. | |
4888 * Go to next channel | |
4889 */ | |
4890 continue; | |
4891 } | |
4892 continue; | |
4893 } | |
4894 } /* End if decoded_all */ | |
4895 /* For streamed */ | |
4896 else | |
4897 { | |
4898 ALint buffers_processed; | |
4899 ALint buffers_still_queued; | |
4900 ALint current_buffer_id; | |
4901 | |
4902 ALuint unqueued_buffer_id; | |
4903 #if 0 | |
4904 /********* Remove this **********/ | |
4905 fprintf(stderr, "For Streamed\n"); | |
4906 | |
4907 alGetSourcei( | |
4908 ALmixer_Channel_List[i].alsource, | |
4909 AL_SOURCE_STATE, &state | |
4910 ); | |
4911 switch(state) { | |
4912 case AL_PLAYING: | |
4913 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
4914 break; | |
4915 case AL_PAUSED: | |
4916 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
4917 break; | |
4918 case AL_STOPPED: | |
4919 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
4920 break; | |
4921 case AL_INITIAL: | |
4922 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
4923 break; | |
4924 default: | |
4925 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
4926 break; | |
4927 } | |
4928 /******** END REMOVE *******/ | |
4929 #endif | |
4930 /* Get the number of buffers still queued */ | |
4931 alGetSourcei( | |
4932 ALmixer_Channel_List[i].alsource, | |
4933 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4934 ); | |
4935 if((error = alGetError()) != AL_NO_ERROR) | |
4936 { | |
4937 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
|
4938 alGetString(error)); |
0 | 4939 } |
4940 /* Get the number of buffers processed | |
4941 * so we know if we need to refill | |
4942 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4943 /* 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
|
4944 * 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
|
4945 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4946 // fprintf(stderr, "calling AL_BUFFERS_PROCESSED on source:%d", ALmixer_Channel_List[i].alsource); |
0 | 4947 alGetSourcei( |
4948 ALmixer_Channel_List[i].alsource, | |
4949 AL_BUFFERS_PROCESSED, &buffers_processed | |
4950 ); | |
4951 if((error = alGetError()) != AL_NO_ERROR) | |
4952 { | |
4953 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
|
4954 alGetString(error)); |
0 | 4955 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4956 // fprintf(stderr, "finished AL_BUFFERS_PROCESSED, buffers_processed=%d", buffers_processed); |
0 | 4957 |
4958 /* WTF!!! The Nvidia distribution is failing on the alGetSourcei(source, AL_BUFFER, buf_id) call. | |
4959 * I need this call to figure out which buffer OpenAL is currently playing. | |
4960 * It keeps returning an "Invalid Enum" error. | |
4961 * This is totally inane! It's a basic query. | |
4962 * By the spec, this functionality is not explicitly defined so Nvidia refuses to | |
4963 * fix this behavior, even though all other distributions work fine with this. | |
4964 * The only workaround for this is for | |
4965 * a significant rewrite of my code which requires me to | |
4966 * duplicate the OpenAL queued buffers state with my own | |
4967 * code and try to derive what the current playing buffer is by indirect observation of | |
4968 * looking at buffers_processed. But of course this has a ton of downsides since my | |
4969 * queries do not give me perfect timing of what OpenAL is actually doing and | |
4970 * the fact that some of the distributions seem to have buffer queuing problems | |
4971 * with their query results (CoreAudio). This also means a ton of extra code | |
4972 * on my side. The lack of support of a 1 line call has required me to | |
4973 * implement yet another entire state machine. <sigh> | |
4974 */ | |
4975 #if 0 /* This code will not work until possibly OpenAL 1.1 because of Nvidia */ | |
4976 /* Get the id to the current buffer playing */ | |
4977 alGetSourcei( | |
4978 ALmixer_Channel_List[i].alsource, | |
4979 AL_BUFFER, ¤t_buffer_id | |
4980 ); | |
4981 if((error = alGetError()) != AL_NO_ERROR) | |
4982 { | |
4983 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
|
4984 alGetString(error)); |
0 | 4985 } |
4986 | |
4987 /* Before the hard stuff, check to see if the | |
4988 * current queued AL buffer has changed. | |
4989 * If it has, we should launch a data callback if | |
4990 * necessary | |
4991 */ | |
4992 if( ((ALuint)current_buffer_id) != | |
4993 ALmixer_Channel_List[i].almixer_data->current_buffer) | |
4994 { | |
4995 ALmixer_Channel_List[i].almixer_data->current_buffer | |
4996 = (ALuint)current_buffer_id; | |
4997 | |
4998 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
4999 } | |
5000 #else | |
5001 /* Only do this if "access_data" was requested (i.e. the circular_buffer!=NULL) | |
5002 * And if one of the two are true: | |
5003 * Either buffers_processed > 0 (because the current_buffer might have changed) | |
5004 * or if the current_buffer==0 (because we are in an initial state or recovering from | |
5005 * a buffer underrun) | |
5006 */ | |
5007 if((ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5008 && ( | |
5009 (buffers_processed > 0) || (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5010 ) | |
5011 ) | |
5012 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5013 ALint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5014 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5015 ALubyte is_out_of_sync = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5016 ALuint my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
1 | 5017 /* Ugh, I have to deal with signed/unsigned mismatch here. */ |
5018 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
|
5019 ALuint unplayed_buffers; |
1 | 5020 if(buffers_unplayed_int < 0) |
5021 { | |
5022 unplayed_buffers = 0; | |
5023 } | |
5024 else | |
5025 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5026 unplayed_buffers = (ALuint)buffers_unplayed_int; |
1 | 5027 } |
0 | 5028 /* |
5029 fprintf(stderr, "Queue in processed check, before pop, buffers_processed=%d\n", buffers_processed); | |
5030 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5031 */ | |
5032 /* We can't make any determinations solely based on the number of buffers_processed | |
5033 * because currently, we only unqueue 1 buffer per loop. That means if 2 or more | |
5034 * buffers became processed in one loop, the following loop, we would have | |
5035 * at least that_many-1 buffers_processed (plus possible new processed). | |
5036 * If we tried to just remove 1 buffer from our queue, we would be incorrect | |
5037 * because we would not actually reflect the current playing buffer. | |
5038 * So the solution seems to be to make sure our queue is the same size | |
5039 * as the number of buffers_queued-buffers_processed, and return the head of our queue | |
5040 * as the current playing buffer. | |
5041 */ | |
5042 /* Also, we have a corner case. When we first start playing or if we have | |
5043 * a buffer underrun, we have not done a data callback. | |
5044 * In this case, we need to see if there is any new data in our queue | |
5045 * and if so, launch that data callback. | |
5046 */ | |
5047 /* Warning, this code risks the possibility of no data callback being fired if | |
5048 * the system is really late (or skipped buffers). | |
5049 */ | |
5050 | |
5051 /* First, let's syncronize our queue with the OpenAL queue */ | |
5052 #if 0 | |
5053 fprintf(stderr, "inside, Buffers processed=%d, Buffers queued=%d, my queue=%d\n", | |
5054 buffers_processed, buffers_still_queued, my_queue_size); | |
1 | 5055 #endif |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5056 is_out_of_sync = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5057 for(k=0; k<buffers_processed; k++) |
0 | 5058 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5059 queue_ret_flag = CircularQueueUnsignedInt_PopFront( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5060 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
|
5061 if(0 == queue_ret_flag) |
0 | 5062 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5063 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
|
5064 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5065 } |
0 | 5066 my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
5067 /* We have several possibilities we need to handle: | |
5068 * 1) We are in an initial state or underrun and need to do a data callback on the head. | |
5069 * 2) We were out of sync and need to do a new data callback on the new head. | |
5070 * 3) We were not out of sync but just had left over processed buffers which caused us to | |
5071 * fall in this block of code. (Don't do anything.) | |
5072 */ | |
5073 if( (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) || (1 == is_out_of_sync) ) | |
5074 { | |
5075 if(my_queue_size > 0) | |
5076 { | |
5077 current_buffer_id = CircularQueueUnsignedInt_Front( | |
5078 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5079 if(0 == current_buffer_id) | |
5080 { | |
5081 fprintf(stderr, "53a Internal Error, current_buffer_id=0 when it shouldn't be 0\n"); | |
5082 } | |
5083 /* | |
5084 else | |
5085 { | |
5086 fprintf(stderr, "Queue in processed check, after pop\n"); | |
5087 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5088 } | |
5089 */ | |
5090 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5091 = (ALuint)current_buffer_id; | |
5092 | |
5093 #if 0 | |
5094 /* Remove me...only for checking...doesn't work on Nvidia */ | |
5095 { | |
5096 ALuint real_id; | |
5097 alGetSourcei( | |
5098 ALmixer_Channel_List[i].alsource, | |
5099 AL_BUFFER, &real_id | |
5100 ); | |
5101 alGetError(); | |
5102 fprintf(stderr, "Callback fired on data buffer=%d, real_id shoud be=%d\n", current_buffer_id, real_id); | |
5103 } | |
5104 #endif | |
5105 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5106 } | |
5107 else | |
5108 { | |
1 | 5109 /* |
0 | 5110 fprintf(stderr, "53b, Notice/Warning:, OpenAL queue has been depleted.\n"); |
1 | 5111 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
5112 */ | |
0 | 5113 /* In this case, we might either be in an underrun or finished with playback */ |
5114 ALmixer_Channel_List[i].almixer_data->current_buffer = 0; | |
5115 } | |
5116 } | |
5117 } | |
5118 #endif | |
5119 | |
5120 | |
5121 | |
5122 /* Just a test - remove | |
5123 if( ALmixer_Channel_List[i].loops > 0) | |
5124 { | |
5125 fprintf(stderr, ">>>>>>>>>>>>>>>Loops = %d\n", | |
5126 ALmixer_Channel_List[i].loops); | |
5127 } | |
5128 */ | |
5129 #if 0 | |
5130 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
5131 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5132 #endif | |
5133 /* We've used up a buffer so we need to unqueue and replace */ | |
5134 /* Okay, it gets more complicated here: | |
5135 * We need to Queue more data | |
5136 * if buffers_processed > 0 or | |
5137 * if num_of_buffers_in_use < NUMBER_OF_QUEUE_BUFFERS | |
5138 * but we don't do this if at EOF, | |
5139 * except when there is looping | |
5140 */ | |
5141 /* For this to work, we must rely on EVERYTHING | |
5142 * else to unset the EOF if there is looping. | |
5143 * Remember, even Play() must do this | |
5144 */ | |
5145 | |
5146 /* If not EOF, then we are still playing. | |
5147 * Inside, we might find num_of_buffers < NUM...QUEUE_BUF.. | |
5148 * or buffers_process > 0 | |
5149 * in which case we queue up. | |
5150 * We also might find no buffers we need to fill, | |
5151 * in which case we just keep going | |
5152 */ | |
5153 if( ! ALmixer_Channel_List[i].almixer_data->eof) | |
5154 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5155 ALuint bytes_returned; |
0 | 5156 /* We have a priority. We first must assign |
5157 * unused buffers in reserve. If there is nothing | |
5158 * left, then we may unqueue buffers. We can't | |
5159 * do it the other way around because we will | |
5160 * lose the pointer to the unqueued buffer | |
5161 */ | |
5162 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5163 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5164 { | |
1 | 5165 #if 0 |
0 | 5166 fprintf(stderr, "Getting more data in NOT_EOF and num_buffers_in_use (%d) < max_queue (%d)\n", |
5167 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5168 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5169 #endif |
0 | 5170 /* Going to add an unused packet. |
5171 * Grab next packet */ | |
5172 bytes_returned = GetMoreData( | |
5173 ALmixer_Channel_List[i].almixer_data, | |
5174 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5175 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5176 ); | |
5177 } | |
5178 /* For processed > 0 */ | |
5179 else if(buffers_processed > 0) | |
5180 { | |
5181 /* Unqueue only 1 buffer for now. | |
5182 * If there are more than one, | |
5183 * let the next Update pass deal with it | |
5184 * so we don't stall the program for too long. | |
5185 */ | |
5186 #if 0 | |
5187 fprintf(stderr, "About to Unqueue, Buffers processed = %d\n", buffers_processed); | |
5188 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5189 fprintf(stderr, "Unqueuing a buffer\n"); | |
5190 #endif | |
5191 alSourceUnqueueBuffers( | |
5192 ALmixer_Channel_List[i].alsource, | |
5193 1, &unqueued_buffer_id | |
5194 ); | |
5195 if((error = alGetError()) != AL_NO_ERROR) | |
5196 { | |
5197 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
|
5198 alGetString(error)); |
0 | 5199 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
|
5200 alGetString(error) ); |
0 | 5201 error_flag--; |
5202 } | |
5203 /* | |
5204 fprintf(stderr, "Right after unqueue..."); | |
5205 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5206 fprintf(stderr, "Getting more data for NOT_EOF, max_buffers filled\n"); | |
5207 */ | |
5208 /* Grab unqueued packet */ | |
5209 bytes_returned = GetMoreData( | |
5210 ALmixer_Channel_List[i].almixer_data, | |
5211 unqueued_buffer_id); | |
5212 } | |
5213 /* We are still streaming, but currently | |
5214 * don't need to fill any buffers */ | |
5215 else | |
5216 { | |
5217 /* Might want to check state */ | |
5218 /* In case the playback stopped, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5219 * we need to resume |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5220 * a.k.a. buffer underrun |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5221 */ |
1 | 5222 #if 1 |
5223 /* Try not refetching the state here because I'm getting a duplicate | |
5224 buffer playback (hiccup) */ | |
0 | 5225 alGetSourcei( |
5226 ALmixer_Channel_List[i].alsource, | |
5227 AL_SOURCE_STATE, &state | |
5228 ); | |
1 | 5229 if((error = alGetError()) != AL_NO_ERROR) |
5230 { | |
5231 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
|
5232 alGetString(error)); |
1 | 5233 } |
5234 /* Get the number of buffers processed | |
5235 */ | |
5236 alGetSourcei( | |
5237 ALmixer_Channel_List[i].alsource, | |
5238 AL_BUFFERS_PROCESSED, | |
5239 &buffers_processed | |
5240 ); | |
5241 if((error = alGetError()) != AL_NO_ERROR) | |
5242 { | |
5243 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
|
5244 alGetString(error)); |
1 | 5245 } |
5246 #endif | |
0 | 5247 if(AL_STOPPED == state) |
5248 { | |
5249 /* Resuming in not eof, but nothing to buffer */ | |
1 | 5250 |
5251 /* Okay, here's another lately discovered problem: | |
5252 * I can't find it in the spec, but for at least some of the | |
5253 * implementations, if I call play on a stopped source that | |
5254 * has processed buffers, all those buffers get marked as unprocessed | |
5255 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5256 * processed, on resume, the earlier 24 buffers will get replayed, | |
5257 * causing a "hiccup" like sound in the playback. | |
5258 * To avoid this, I must unqueue all processed buffers before | |
5259 * calling play. But to complicate things, I need to worry about resyncing | |
5260 * the circular queue with this since I designed this thing | |
5261 * with some correlation between the two. However, I might | |
5262 * have already handled this, so I will try writing this code without | |
5263 * syncing for now. | |
5264 * There is currently an assumption that a buffer | |
5265 * was queued above so I actually have something | |
5266 * to play. | |
5267 */ | |
5268 ALint temp_count; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5269 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5270 fprintf(stderr, "STOPPED1, need to clear processed=%d, status is:\n", buffers_processed); |
1 | 5271 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
|
5272 #endif |
1 | 5273 for(temp_count=0; temp_count<buffers_processed; temp_count++) |
5274 { | |
5275 alSourceUnqueueBuffers( | |
5276 ALmixer_Channel_List[i].alsource, | |
5277 1, &unqueued_buffer_id | |
5278 ); | |
5279 if((error = alGetError()) != AL_NO_ERROR) | |
5280 { | |
5281 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
|
5282 alGetString(error)); |
1 | 5283 error_flag--; |
5284 } | |
5285 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5286 #if 0 |
1 | 5287 fprintf(stderr, "After unqueue clear...:\n"); |
5288 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
|
5289 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5290 /* 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
|
5291 * 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
|
5292 * 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
|
5293 * 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
|
5294 * no buffers in queue. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5295 * 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
|
5296 * Then we need to resume playing. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5297 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5298 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5299 int buffers_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5300 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5301 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5302 AL_BUFFERS_QUEUED, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5303 &buffers_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5304 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5305 |
1 | 5306 if((error = alGetError()) != AL_NO_ERROR) |
5307 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5308 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
|
5309 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5310 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5311 assert(buffers_queued == 0); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5312 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
|
5313 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5314 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5315 /* 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
|
5316 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
|
5317 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5318 /* 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
|
5319 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5320 ALmixer_Channel_List[i].almixer_data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5321 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
|
5322 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5323 /* 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
|
5324 * 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
|
5325 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5326 if(bytes_returned > 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5327 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5328 /* Queue up the new data */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5329 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5330 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5331 1, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5332 &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
|
5333 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5334 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5335 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5336 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
|
5337 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5338 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5339 /* 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
|
5340 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
|
5341 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5342 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5343 /* 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
|
5344 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
|
5345 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5346 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5347 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
|
5348 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5349 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
|
5350 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
|
5351 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5352 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5353 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5354 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
|
5355 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
|
5356 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5357 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5358 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5359 |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5362 /* Resume playback from underrun */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5363 alSourcePlay(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5364 if((error = alGetError()) != AL_NO_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 fprintf(stderr, "55Tbesting error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5367 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5368 } |
1 | 5369 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5370 |
0 | 5371 } |
5372 /* Let's escape to the next loop. | |
5373 * All code below this point is for queuing up | |
5374 */ | |
5375 /* | |
1 | 5376 fprintf(stderr, "Entry: Nothing to do...continue\n\n"); |
5377 */ | |
0 | 5378 continue; |
5379 } | |
5380 /* We now know we have to fill an available | |
5381 * buffer. | |
5382 */ | |
5383 | |
5384 /* In the previous branch, we just grabbed more data. | |
5385 * Let's check it to make sure it's okay, | |
5386 * and then queue it up | |
5387 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5388 /* This check doesn't work anymore because it is now ALuint */ |
0 | 5389 #if 0 |
5390 if(-1 == bytes_returned) | |
5391 { | |
5392 /* Problem occurred...not sure what to do */ | |
5393 /* Go to next loop? */ | |
5394 error_flag--; | |
5395 /* Set the eof flag to force a quit so | |
5396 * we don't get stuck in an infinite loop | |
5397 */ | |
5398 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5399 continue; | |
5400 } | |
5401 #endif | |
5402 /* This is a special case where we've run | |
5403 * out of data. We should check for loops | |
5404 * and get more data. If there is no loop, | |
5405 * then do nothing and wait for future | |
5406 * update passes to handle the EOF. | |
5407 * The advantage of handling the loop here | |
5408 * instead of waiting for play to stop is | |
5409 * that we should be able to keep the buffer | |
5410 * filled. | |
5411 */ | |
5412 #if 0 | |
5413 else if(0 == bytes_returned) | |
5414 #endif | |
5415 if(0 == bytes_returned) | |
5416 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5417 /* |
0 | 5418 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
|
5419 */ |
0 | 5420 /* Check for loops */ |
5421 if( ALmixer_Channel_List[i].loops != 0 ) | |
5422 { | |
5423 /* We have to loop, so rewind | |
5424 * and fetch more data | |
5425 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5426 /* |
0 | 5427 fprintf(stderr, "Rewinding data\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5428 */ |
0 | 5429 if(0 == Sound_Rewind( |
5430 ALmixer_Channel_List[i].almixer_data->sample)) | |
5431 { | |
5432 fprintf(stderr, "Rewinding failed\n"); | |
5433 ALmixer_SetError( Sound_GetError() ); | |
5434 ALmixer_Channel_List[i].loops = 0; | |
5435 error_flag--; | |
5436 /* We'll continue on because we do have some valid data */ | |
5437 continue; | |
5438 } | |
5439 /* Remember to reset the data->eof flag */ | |
5440 ALmixer_Channel_List[i].almixer_data->eof = 0; | |
5441 if(ALmixer_Channel_List[i].loops > 0) | |
5442 { | |
5443 ALmixer_Channel_List[i].loops--; | |
5444 } | |
5445 /* Try grabbing another packet now. | |
5446 * Since we may have already unqueued a | |
5447 * buffer, we don't want to lose it. | |
5448 */ | |
5449 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5450 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5451 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5452 /* |
0 | 5453 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
|
5454 */ |
0 | 5455 /* Grab next packet */ |
5456 bytes_returned = GetMoreData( | |
5457 ALmixer_Channel_List[i].almixer_data, | |
5458 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5459 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5460 ); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5461 /* |
0 | 5462 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
|
5463 */ |
0 | 5464 } |
5465 /* Refilling unqueued packet */ | |
5466 else | |
5467 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5468 /* |
0 | 5469 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
|
5470 */ |
0 | 5471 /* Grab next packet */ |
5472 bytes_returned = GetMoreData( | |
5473 ALmixer_Channel_List[i].almixer_data, | |
5474 unqueued_buffer_id); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5475 /* |
0 | 5476 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
|
5477 */ |
0 | 5478 } |
5479 /* Another error check */ | |
5480 /* | |
5481 if(bytes_returned <= 0) | |
5482 */ | |
5483 if(0 == bytes_returned) | |
5484 { | |
5485 fprintf(stderr, "??????????ERROR\n"); | |
5486 ALmixer_SetError("Could not loop because after rewind, no data could be retrieved"); | |
5487 /* Problem occurred...not sure what to do */ | |
5488 /* Go to next loop? */ | |
5489 error_flag--; | |
5490 /* Set the eof flag to force a quit so | |
5491 * we don't get stuck in an infinite loop | |
5492 */ | |
5493 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5494 continue; | |
5495 } | |
5496 /* We made it to the end. We still need | |
5497 * to BufferData, so let this branch | |
5498 * fall into the next piece of | |
5499 * code below which will handle that | |
5500 */ | |
5501 | |
5502 | |
5503 } /* END loop check */ | |
5504 else | |
5505 { | |
5506 /* No more loops to do. | |
5507 * EOF flag should be set. | |
5508 * Just go to next loop and | |
5509 * let things be handled correctly | |
5510 * in future update calls | |
5511 */ | |
1 | 5512 /* |
0 | 5513 fprintf(stderr, "SHOULD BE EOF\n"); |
5514 | |
5515 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
1 | 5516 */ |
0 | 5517 continue; |
5518 } | |
5519 } /* END if bytes_returned == 0 */ | |
5520 /********* Possible trouble point. I might be queueing empty buffers on the mac. | |
5521 * This check doesn't say if the buffer is valid. Only the EOF assumption is a clue at this point | |
5522 */ | |
5523 /* Fall here */ | |
5524 /* Everything is normal. We aren't | |
5525 * at an EOF, but need to simply | |
5526 * queue more data. The data is already checked for good, | |
5527 * so queue it up */ | |
5528 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5529 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5530 { | |
5531 /* Keep count of how many buffers we have | |
5532 * to queue so we can return the value | |
5533 */ | |
5534 retval++; | |
1 | 5535 /* |
0 | 5536 fprintf(stderr, "NOT_EOF???, about to Queue more data for num_buffers (%d) < max_queue (%d)\n", |
5537 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5538 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5539 */ |
0 | 5540 alSourceQueueBuffers( |
5541 ALmixer_Channel_List[i].alsource, | |
5542 1, | |
5543 &ALmixer_Channel_List[i].almixer_data->buffer[ | |
5544 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5545 ); | |
5546 if((error = alGetError()) != AL_NO_ERROR) | |
5547 { | |
5548 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
|
5549 alGetString(error)); |
0 | 5550 } |
5551 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5552 * which buffer to show during callbacks (for things like | |
5553 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5554 * data structure. This code will be called only if | |
5555 * "access_data" was set, indicated by whether the queue is NULL. | |
5556 */ | |
5557 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5558 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5559 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5560 // fprintf(stderr, "56d: CircularQueue_PushBack.\n"); |
0 | 5561 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5562 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5563 ALmixer_Channel_List[i].almixer_data->buffer[ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5564 ); | |
5565 if(0 == queue_ret_flag) | |
5566 { | |
5567 fprintf(stderr, "56aSerious internal error: CircularQueue could not push into queue.\n"); | |
5568 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5569 } | |
5570 /* | |
5571 else | |
5572 { | |
5573 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5574 } | |
5575 */ | |
5576 } | |
5577 } | |
5578 /* for processed > 0 */ | |
5579 else | |
5580 { | |
5581 /* Keep count of how many buffers we have | |
5582 * to queue so we can return the value | |
5583 */ | |
5584 retval++; | |
5585 /* | |
5586 fprintf(stderr, "NOT_EOF, about to Queue more data for filled max_queue (%d)\n", | |
5587 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
5588 */ | |
5589 alSourceQueueBuffers( | |
5590 ALmixer_Channel_List[i].alsource, | |
5591 1, &unqueued_buffer_id); | |
5592 if((error = alGetError()) != AL_NO_ERROR) | |
5593 { | |
5594 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
|
5595 alGetString(error) ); |
0 | 5596 error_flag--; |
5597 continue; | |
5598 } | |
5599 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5600 * which buffer to show during callbacks (for things like | |
5601 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5602 * data structure. This code will be called only if | |
5603 * "access_data" was set, indicated by whether the queue is NULL. | |
5604 */ | |
5605 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5606 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5607 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5608 // fprintf(stderr, "56e: CircularQueue_PushBack.\n"); |
0 | 5609 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5610 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5611 unqueued_buffer_id | |
5612 ); | |
5613 if(0 == queue_ret_flag) | |
5614 { | |
5615 fprintf(stderr, "56bSerious internal error: CircularQueue could not push into queue.\n"); | |
5616 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5617 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5618 #if 0 |
0 | 5619 else |
5620 { | |
5621 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5622 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5623 #endif |
0 | 5624 } |
5625 } | |
5626 /* If we used an available buffer queue, | |
5627 * then we need to update the number of them in use | |
5628 */ | |
5629 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5630 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5631 { | |
5632 /* Increment the number of buffers in use */ | |
5633 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use++; | |
5634 } | |
5635 /* Might want to check state */ | |
5636 /* In case the playback stopped, | |
5637 * we need to resume */ | |
1 | 5638 #if 1 |
5639 /* Try not refetching the state here because I'm getting a duplicate | |
5640 buffer playback (hiccup) */ | |
0 | 5641 alGetSourcei( |
5642 ALmixer_Channel_List[i].alsource, | |
5643 AL_SOURCE_STATE, &state | |
5644 ); | |
1 | 5645 if((error = alGetError()) != AL_NO_ERROR) |
5646 { | |
5647 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
|
5648 alGetString(error)); |
1 | 5649 } |
5650 /* Get the number of buffers processed | |
5651 */ | |
5652 alGetSourcei( | |
5653 ALmixer_Channel_List[i].alsource, | |
5654 AL_BUFFERS_PROCESSED, | |
5655 &buffers_processed | |
5656 ); | |
5657 if((error = alGetError()) != AL_NO_ERROR) | |
5658 { | |
5659 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
|
5660 alGetString(error)); |
1 | 5661 } |
5662 #endif | |
0 | 5663 if(AL_STOPPED == state) |
5664 { | |
1 | 5665 /* |
0 | 5666 fprintf(stderr, "Resuming in not eof\n"); |
1 | 5667 */ |
5668 /* Okay, here's another lately discovered problem: | |
5669 * I can't find it in the spec, but for at least some of the | |
5670 * implementations, if I call play on a stopped source that | |
5671 * has processed buffers, all those buffers get marked as unprocessed | |
5672 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5673 * processed, on resume, the earlier 24 buffers will get replayed, | |
5674 * causing a "hiccup" like sound in the playback. | |
5675 * To avoid this, I must unqueue all processed buffers before | |
5676 * calling play. But to complicate things, I need to worry about resyncing | |
5677 * the circular queue with this since I designed this thing | |
5678 * with some correlation between the two. However, I might | |
5679 * have already handled this, so I will try writing this code without | |
5680 * syncing for now. | |
5681 * There is currently an assumption that a buffer | |
5682 * was queued above so I actually have something | |
5683 * to play. | |
5684 */ | |
5685 ALint temp_count; | |
5686 /* | |
5687 fprintf(stderr, "STOPPED2, need to clear processed, status is:\n"); | |
5688 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5689 */ | |
5690 | |
5691 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5692 { | |
5693 alSourceUnqueueBuffers( | |
5694 ALmixer_Channel_List[i].alsource, | |
5695 1, &unqueued_buffer_id | |
5696 ); | |
5697 if((error = alGetError()) != AL_NO_ERROR) | |
5698 { | |
5699 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
|
5700 alGetString(error)); |
1 | 5701 error_flag--; |
5702 } | |
5703 } | |
5704 /* | |
5705 fprintf(stderr, "After unqueue clear...:\n"); | |
5706 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5707 */ | |
5708 | |
5709 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5710 if((error = alGetError()) != AL_NO_ERROR) | |
5711 { | |
5712 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
|
5713 alGetString(error)); |
1 | 5714 } |
0 | 5715 } |
5716 continue; | |
5717 } /* END if( ! eof) */ | |
5718 /* We have hit EOF in the SDL_Sound sample and there | |
5719 * are no more loops. However, there may still be | |
5720 * buffers in the OpenAL queue which still need to | |
5721 * be played out. The following body of code will | |
5722 * determine if play is still happening or | |
5723 * initiate the stop/cleanup sequenece. | |
5724 */ | |
5725 else | |
5726 { | |
5727 /* Let's continue to remove the used up | |
5728 * buffers as they come in. */ | |
5729 if(buffers_processed > 0) | |
5730 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5731 ALint temp_count; |
0 | 5732 /* Do as a for-loop because I don't want |
5733 * to have to create an array for the | |
5734 * unqueued_buffer_id's | |
5735 */ | |
5736 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5737 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5738 /* |
0 | 5739 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
|
5740 */ |
0 | 5741 alSourceUnqueueBuffers( |
5742 ALmixer_Channel_List[i].alsource, | |
5743 1, &unqueued_buffer_id | |
5744 ); | |
5745 if((error = alGetError()) != AL_NO_ERROR) | |
5746 { | |
5747 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
|
5748 alGetString(error)); |
0 | 5749 } |
5750 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5751 /* |
0 | 5752 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
|
5753 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5754 |
0 | 5755 /* Need to update counts since we removed everything. |
5756 * If we don't update the counts here, we end up in the | |
5757 * "Shouldn't be here section, but maybe it's okay due to race conditions" | |
5758 */ | |
5759 alGetSourcei( | |
5760 ALmixer_Channel_List[i].alsource, | |
5761 AL_BUFFERS_QUEUED, &buffers_still_queued | |
5762 ); | |
5763 if((error = alGetError()) != AL_NO_ERROR) | |
5764 { | |
5765 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
|
5766 alGetString(error)); |
0 | 5767 } |
5768 /* Get the number of buffers processed | |
5769 * so we know if we need to refill | |
5770 */ | |
5771 alGetSourcei( | |
5772 ALmixer_Channel_List[i].alsource, | |
5773 AL_BUFFERS_PROCESSED, &buffers_processed | |
5774 ); | |
5775 if((error = alGetError()) != AL_NO_ERROR) | |
5776 { | |
5777 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
|
5778 alGetString(error)); |
0 | 5779 } |
5780 } | |
5781 | |
5782 | |
5783 /* Else if buffers_processed == 0 | |
5784 * and buffers_still_queued == 0. | |
5785 * then we check to see if the source | |
5786 * is still playing. Quit if stopped | |
5787 * We shouldn't need to worry about | |
5788 * looping because that should have | |
5789 * been handled above. | |
5790 */ | |
5791 if(0 == buffers_still_queued) | |
5792 { | |
5793 /* Make sure playback has stopped before | |
5794 * we shutdown. | |
5795 */ | |
5796 alGetSourcei( | |
5797 ALmixer_Channel_List[i].alsource, | |
5798 AL_SOURCE_STATE, &state | |
5799 ); | |
5800 if((error = alGetError()) != AL_NO_ERROR) | |
5801 { | |
5802 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
|
5803 alGetString(error)); |
0 | 5804 } |
5805 if(AL_STOPPED == state) | |
5806 { | |
5807 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use = 0; | |
5808 /* Playback has ended. | |
5809 * Loop if necessary, or launch callback | |
5810 * and clear channel (or clear channel and | |
5811 * then launch callback?) | |
5812 */ | |
5813 Clean_Channel(i); | |
5814 /* Subtract counter */ | |
5815 Is_Playing_global--; | |
5816 | |
5817 /* Launch callback */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5818 Invoke_Channel_Done_Callback(i, AL_TRUE); |
0 | 5819 |
5820 /* We're done for this loop. | |
5821 * Go to next channel | |
5822 */ | |
5823 continue; | |
5824 } | |
5825 } /* End end-playback */ | |
5826 else | |
5827 { | |
5828 /* Need to run out buffer */ | |
5829 #if 1 | |
5830 /* Might want to check state */ | |
5831 /* In case the playback stopped, | |
5832 * we need to resume */ | |
5833 alGetSourcei( | |
5834 ALmixer_Channel_List[i].alsource, | |
5835 AL_SOURCE_STATE, &state | |
5836 ); | |
5837 if((error = alGetError()) != AL_NO_ERROR) | |
5838 { | |
5839 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
|
5840 alGetString(error)); |
0 | 5841 } |
5842 if(AL_STOPPED == state) | |
5843 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5844 /* |
0 | 5845 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
|
5846 */ |
1 | 5847 /* |
0 | 5848 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 5849 */ |
0 | 5850 /* Rather than force unqueuing the buffer, let's see if |
5851 * setting the buffer to none works (the OpenAL 1.0 | |
5852 * Reference Annotation suggests this should work). | |
5853 */ | |
5854 alSourcei(ALmixer_Channel_List[i].alsource, | |
5855 AL_BUFFER, AL_NONE); | |
5856 /* | |
5857 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5858 */ | |
5859 /* This doesn't work because in some cases, I think | |
5860 * it causes the sound to be replayed | |
5861 */ | |
5862 /* | |
5863 fprintf(stderr, "Resuming in eof (trying to run out buffers\n"); | |
5864 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5865 */ | |
5866 } | |
5867 #endif | |
5868 } /* End trap section */ | |
5869 } /* End POST-EOF use-up buffer section */ | |
5870 } /* END Streamed section */ | |
5871 } /* END channel in use */ | |
5872 } /* END for-loop for each channel */ | |
5873 | |
5874 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
5875 alcProcessContext(alcGetCurrentContext()); | |
5876 if((error = alGetError()) != AL_NO_ERROR) | |
5877 { | |
5878 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
|
5879 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5880 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5881 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5882 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5883 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5884 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5885 #endif |
0 | 5886 /* Return the number of errors */ |
5887 if(error_flag < 0) | |
5888 { | |
5889 return error_flag; | |
5890 } | |
5891 /* Return the number of buffers that were queued */ | |
5892 return retval; | |
5893 } | |
5894 | |
5895 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
5896 /* 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
|
5897 static void my_dummy_audio_callback(void* userdata, ALbyte* stream, int len) |
0 | 5898 { |
5899 } | |
5900 #endif | |
5901 | |
5902 | |
5903 | |
5904 | |
5905 #ifdef ENABLE_ALMIXER_THREADS | |
5906 /* We might need threads. We | |
5907 * must constantly poll OpenAL to find out | |
5908 * if sound is being streamed, if play has | |
5909 * ended, etc. Without threads, this must | |
5910 * be explicitly done by the user. | |
5911 * We could try to do it for them if we | |
5912 * finish the threads. | |
5913 */ | |
5914 | |
5915 static int Stream_Data_Thread_Callback(void* data) | |
5916 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5917 ALint retval; |
0 | 5918 |
5919 while(ALmixer_Initialized) | |
5920 { | |
5921 retval = Update_ALmixer(data); | |
5922 /* 0 means that nothing needed updating and | |
5923 * the function returned quickly | |
5924 */ | |
5925 if(0 == retval) | |
5926 { | |
5927 /* Let's be nice and make the thread sleep since | |
5928 * little work was done in update | |
5929 */ | |
5930 /* Make sure times are multiples of 10 | |
5931 * for optimal performance and accuracy in Linux | |
5932 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5933 ALmixer_Delay(10); |
0 | 5934 } |
5935 else | |
5936 { | |
5937 /* 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
|
5938 ALmixer_Delay(0); |
0 | 5939 } |
5940 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5941 /* |
0 | 5942 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
|
5943 */ |
0 | 5944 return 0; |
5945 } | |
5946 #endif /* End of ENABLE_ALMIXER_THREADS */ | |
5947 | |
5948 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5949 /* 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
|
5950 * 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
|
5951 * so SDL_mixer porting people beware. |
0 | 5952 * Warning: SDL_QuitSubSystem(SDL_INIT_AUDIO) is called which |
5953 * means the SDL audio system will be disabled. It will not | |
5954 * be restored (in case SDL is not actually being used) so | |
5955 * the user will need to restart it if they need it after | |
5956 * OpenAL shuts down. | |
5957 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5958 ALboolean ALmixer_Init(ALuint frequency, ALint num_sources, ALuint refresh) |
0 | 5959 { |
5960 ALCdevice* dev; | |
5961 ALCcontext* context; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5962 ALint i; |
0 | 5963 ALenum error; |
5964 ALuint* source; | |
5965 | |
5966 #ifdef USING_LOKI_AL_DIST | |
5967 /* The Loki dist requires that I set both the | |
5968 * device and context frequency values separately | |
5969 */ | |
5970 /* Hope this won't overflow */ | |
5971 char device_string[256]; | |
5972 #endif | |
5973 | |
5974 /* (Venting frustration) Damn it! Nobody bothered | |
5975 * documenting how you're supposed to use an attribute | |
5976 * list. In fact, the not even the Loki test program | |
5977 * writers seem to know because they use it inconsistently. | |
5978 * For example, how do you terminate that attribute list? | |
5979 * The Loki test code does it 3 different ways. They | |
5980 * set the last value to 0, or they set it to ALC_INVALID, | |
5981 * or they set two final values: ALC_INVALID, 0 | |
5982 * In Loki, 0 and ALC_INVALID happen to be the same, | |
5983 * but with Creative Labs ALC_INVALID is -1. | |
5984 * So something's going to break. Loki's source | |
5985 * code says to terminate with ALC_INVALID. But I | |
5986 * don't know if that's really true, or it happens | |
5987 * to be a coinicidence because it's defined to 0. | |
5988 * Creative provides no source code, so I can't look at how | |
5989 * they terminate it. | |
5990 * So this is really, really ticking me off... | |
5991 * For now, I'm going to use ALC_INVALID. | |
5992 * (Update...after further review of the API spec, | |
5993 * it seems that a NULL terminated string is the correct | |
5994 * termination value to use, so 0 it is.) | |
5995 */ | |
5996 #if 0 | |
5997 ALint attrlist[] = { | |
5998 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
5999 /* Don't know anything about these values. | |
6000 * Trust defaults? */ | |
6001 /* Supposed to be the refresh rate in Hz. | |
6002 * I think 15-120 are supposed to be good | |
6003 * values. Though I haven't gotten any effect except | |
6004 * for one strange instance on a Mac. But it was | |
6005 * unrepeatable. | |
6006 */ | |
6007 #if 0 | |
6008 ALC_REFRESH, 15, | |
6009 #endif | |
6010 /* Sync requires a alcProcessContext() call | |
6011 * for every cycle. By default, this is | |
6012 * not used and the value is AL_FALSE | |
6013 * because it will probably perform | |
6014 * pretty badly for me. | |
6015 */ | |
6016 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6017 ALC_SYNC, AL_TRUE, | |
6018 #else | |
6019 ALC_SYNC, AL_FALSE, | |
6020 #endif | |
6021 /* Looking at the API spec, it implies | |
6022 * that the list be a NULL terminated string | |
6023 * so it's probably not safe to use ALC_INVALID | |
6024 */ | |
6025 /* | |
6026 ALC_INVALID }; | |
6027 */ | |
6028 '\0'}; | |
6029 #endif | |
6030 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6031 * However, if no value is specified, I don't | |
6032 * want it in the list so I can get the OpenAL defaults | |
6033 */ | |
6034 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6035 ALsizei current_attrlist_index = 0; |
0 | 6036 |
6037 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6038 /* More problems: I'm getting bit by endian/signedness issues on | |
6039 * different platforms. I can find the endianess easily enough, | |
6040 * but I don't know how to determine what the correct signedness | |
6041 * is (if such a thing exists). I do know that if I try using | |
6042 * unsigned on OSX with an originally signed sample, I get | |
6043 * distortion. However, I don't have any native unsigned samples | |
6044 * to test. But I'm assuming that the platform must be in the | |
6045 * correct signedness no matter what. | |
6046 * I can either assume everybody is signed, or I can try to | |
6047 * determine the value. If I try to determine the values, | |
6048 * I think my only ability to figure it out will be to open | |
6049 * SDL_Audio, and read what the obtained settings were. | |
6050 * Then shutdown everything. However, I don't even know how | |
6051 * reliable this is. | |
6052 * Update: I think I resolved the issues...forgot to update | |
6053 * these comments when it happened. I should check the revision control | |
6054 * log... Anyway, I think the issue was partly related to me not | |
6055 * doing something correctly with the AudioInfo or some kind | |
6056 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6057 * revision control, I think I might have assumed that SDL_Sound would | |
6058 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6059 * and had to fill one out myself. | |
6060 */ | |
6061 SDL_AudioSpec desired; | |
6062 SDL_AudioSpec obtained; | |
6063 #endif | |
6064 | |
6065 | |
6066 /* Make sure ALmixer isn't already initialized */ | |
6067 if(ALmixer_Initialized) | |
6068 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6069 return AL_FALSE; |
0 | 6070 } |
6071 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6072 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6073 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6074 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6075 /* 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
|
6076 /* 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
|
6077 * 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
|
6078 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6079 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6080 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6081 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6082 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6083 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6084 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6085 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6086 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6087 } |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6088 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6089 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6090 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6091 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
|
6092 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
|
6093 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6094 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6095 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6096 |
0 | 6097 /* Set the defaults */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6098 /* |
0 | 6099 attrlist[0] = ALC_FREQUENCY; |
6100 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6101 attrlist[2] = ALC_SYNC; | |
6102 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6103 attrlist[3] = ALC_TRUE; | |
6104 #else | |
6105 attrlist[3] = ALC_FALSE; | |
6106 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6107 */ |
0 | 6108 /* Set frequency value if it is not 0 */ |
6109 if(0 != frequency) | |
6110 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6111 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6112 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6113 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6114 current_attrlist_index++; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6117 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6118 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6119 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6120 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6121 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6122 #endif |
0 | 6123 |
6124 /* If the user specifies a refresh value, | |
6125 * make room for it | |
6126 */ | |
6127 if(0 != refresh) | |
6128 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6129 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
|
6130 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6131 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6132 current_attrlist_index++; |
0 | 6133 } |
6134 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6135 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6136 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6137 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6138 |
0 | 6139 /* Initialize SDL_Sound */ |
6140 if(! Sound_Init() ) | |
6141 { | |
6142 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6143 return AL_FALSE; |
0 | 6144 } |
6145 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6146 /* Here is the paranoid check that opens | |
6147 * SDL audio in an attempt to find the correct | |
6148 * system values. | |
6149 */ | |
6150 /* Doesn't have to be the actual value I think | |
6151 * (as long as it doesn't influence format, in | |
6152 * which case I'm probably screwed anyway because OpenAL | |
6153 * may easily choose to do something else). | |
6154 */ | |
6155 desired.freq = 44100; | |
6156 desired.channels = 2; | |
6157 desired.format = AUDIO_S16SYS; | |
6158 desired.callback = my_dummy_audio_callback; | |
6159 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6160 { | |
6161 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6162 /* Now to get really paranoid, we should probably | |
6163 * also assume that the 8bit format is also the | |
6164 * same sign type and set that value | |
6165 */ | |
6166 if(AUDIO_S16SYS == obtained.format) | |
6167 { | |
6168 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6169 } | |
6170 /* Should be AUDIO_U16SYS */ | |
6171 else | |
6172 { | |
6173 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6174 } | |
6175 SDL_CloseAudio(); | |
6176 } | |
6177 else | |
6178 { | |
6179 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6180 */ | |
6181 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6182 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6183 } | |
6184 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6185 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6186 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6187 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
6188 * causes OpenAL and SMPEG to conflict. For some reason | |
6189 * if SDL_Init on audio is active, then all the SMPEG | |
6190 * decoded sound comes out silent. Unfortunately, | |
6191 * Sound_Init() invokes SDL_Init on audio. I'm | |
6192 * not sure why it actually needs it... | |
6193 * But we'll attempt to disable it here after the | |
6194 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
6195 */ | |
6196 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6197 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6198 |
0 | 6199 /* I'm told NULL will call the default string |
6200 * and hopefully do the right thing for each platform | |
6201 */ | |
6202 /* | |
6203 dev = alcOpenDevice( NULL ); | |
6204 */ | |
6205 /* Now I'm told I need to set both the device and context | |
6206 * to have the same sampling rate, so I must pass a string | |
6207 * to OpenDevice(). I don't know how portable these strings are. | |
6208 * I don't even know if the format for strings is | |
6209 * compatible | |
6210 * From the testattrib.c in the Loki test section | |
6211 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
6212 */ | |
6213 | |
6214 #ifdef USING_LOKI_AL_DIST | |
6215 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
6216 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
6217 #else | |
6218 dev = alcOpenDevice( NULL ); | |
6219 #endif | |
6220 if(NULL == dev) | |
6221 { | |
6222 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
|
6223 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6224 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6225 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6226 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6227 /* 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
|
6228 /* 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
|
6229 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6230 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6231 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6232 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6233 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
|
6234 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6235 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
|
6236 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6237 #endif |
0 | 6238 |
6239 context = alcCreateContext(dev, attrlist); | |
6240 if(NULL == context) | |
6241 { | |
6242 ALmixer_SetError("Cannot create a context OpenAL"); | |
6243 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6244 return AL_FALSE; |
0 | 6245 } |
6246 | |
6247 | |
6248 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6249 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6250 * According to Garin Hiebert, this is actually an inconsistency | |
6251 * in the Loki version. The function should return a boolean. | |
6252 * instead of ALC_NO_ERROR. Garin suggested I check via | |
6253 * alcGetError(). | |
6254 */ | |
6255 /* clear the error */ | |
6256 alcGetError(dev); | |
6257 alcMakeContextCurrent(context); | |
6258 | |
6259 error = alcGetError(dev); | |
6260 if( (ALC_NO_ERROR != error) ) | |
6261 { | |
6262 ALmixer_SetError("Could not MakeContextCurrent"); | |
6263 alcDestroyContext(context); | |
6264 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6265 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6266 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6267 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6268 /* 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
|
6269 * 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
|
6270 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6271 * 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
|
6272 * 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
|
6273 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6274 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6275 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6276 ALmixer_Frequency_global = frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6277 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6278 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6279 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
|
6280 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6281 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
|
6282 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6283 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6284 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6285 |
0 | 6286 #if 0 |
6287 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
6288 if(alcGetCurrentContext() != context) | |
6289 { | |
6290 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6291 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6292 * I think this is a bug in the OpenAL implementation. | |
6293 */ | |
6294 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
6295 | |
6296 fprintf(stderr, "Making context current\n"); | |
6297 #ifndef __APPLE__ | |
6298 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
6299 #else | |
6300 if(!alcMakeContextCurrent(context)) | |
6301 #endif | |
6302 { | |
6303 ALmixer_SetError("Could not MakeContextCurrent"); | |
6304 alcDestroyContext(context); | |
6305 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6306 return AL_FALSE; |
0 | 6307 } |
6308 } | |
6309 #endif | |
6310 | |
6311 | |
6312 /* #endif */ | |
6313 /* Saw this in the README with the OS X OpenAL distribution. | |
6314 * It looked interesting and simple, so I thought I might | |
6315 * try it out. | |
6316 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
6317 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
6318 * Audio format, the audio data passed to the | |
6319 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
6320 * usage by removing an audio data conversion | |
6321 * (per source) at render timem at the expense of a larger memory footprint. | |
6322 * | |
6323 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
6324 * setting will be applied to all subsequent | |
6325 * calls to alBufferData(). | |
6326 */ | |
6327 #ifdef __APPLE__ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6328 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6329 #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
|
6330 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6331 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6332 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6333 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6334 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
|
6335 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6336 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
|
6337 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6338 if(0 != convert_data_enum) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6339 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6340 alEnable(convert_data_enum); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6341 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6342 if( (AL_NO_ERROR != alGetError()) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6343 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6344 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
|
6345 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
|
6346 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6347 |
0 | 6348 #endif |
6349 | |
6350 | |
6351 | |
6352 | |
6353 ALmixer_Initialized = 1; | |
6354 | |
6355 if(num_sources <= 0) | |
6356 { | |
6357 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
6358 } | |
6359 else | |
6360 { | |
6361 Number_of_Channels_global = num_sources; | |
6362 } | |
6363 Number_of_Reserve_Channels_global = 0; | |
6364 Is_Playing_global = 0; | |
6365 /* Set to Null in case system quit and was reinitialized */ | |
6366 Channel_Done_Callback = NULL; | |
6367 Channel_Done_Callback_Userdata = NULL; | |
6368 Channel_Data_Callback = NULL; | |
1 | 6369 Channel_Data_Callback_Userdata = NULL; |
0 | 6370 |
6371 /* Allocate memory for the list of channels */ | |
6372 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
6373 if(NULL == ALmixer_Channel_List) | |
6374 { | |
6375 ALmixer_SetError("Out of Memory for Channel List"); | |
6376 alcDestroyContext(context); | |
6377 alcCloseDevice(dev); | |
6378 ALmixer_Initialized = 0; | |
6379 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6380 return AL_FALSE; |
0 | 6381 } |
6382 | |
6383 /* Allocate memory for the list of sources that map to the channels */ | |
6384 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
6385 if(NULL == Source_Map_List) | |
6386 { | |
6387 ALmixer_SetError("Out of Memory for Source Map List"); | |
6388 free(ALmixer_Channel_List); | |
6389 alcDestroyContext(context); | |
6390 alcCloseDevice(dev); | |
6391 ALmixer_Initialized = 0; | |
6392 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6393 return AL_FALSE; |
0 | 6394 } |
6395 | |
6396 /* Create array that will hold the sources */ | |
6397 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
6398 if(NULL == source) | |
6399 { | |
6400 ALmixer_SetError("Out of Memory for sources"); | |
6401 free(Source_Map_List); | |
6402 free(ALmixer_Channel_List); | |
6403 alcDestroyContext(context); | |
6404 alcCloseDevice(dev); | |
6405 ALmixer_Initialized = 0; | |
6406 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6407 return AL_FALSE; |
0 | 6408 } |
6409 | |
6410 /* Clear the error state */ | |
6411 alGetError(); | |
6412 /* Generate the OpenAL sources */ | |
6413 alGenSources(Number_of_Channels_global, source); | |
6414 if( (error=alGetError()) != AL_NO_ERROR) | |
6415 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6416 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 6417 free(ALmixer_Channel_List); |
6418 free(Source_Map_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 /* Initialize each channel and associate one source to one channel */ | |
6427 for(i=0; i<Number_of_Channels_global; i++) | |
6428 { | |
6429 if(0 == source[i]) | |
6430 { | |
6431 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"); | |
6432 } | |
6433 | |
6434 Init_Channel(i); | |
6435 /* Keeping the source allocation out of the Init function | |
6436 * in case I want to reuse the Init | |
6437 * function for resetting data | |
6438 */ | |
6439 ALmixer_Channel_List[i].alsource = source[i]; | |
6440 /* Now also keep a copy of the source to channel mapping | |
6441 * in case we need to look up a channel from the source | |
6442 * instead of a source from a channel | |
6443 */ | |
6444 Source_Map_List[i].source = source[i]; | |
6445 Source_Map_List[i].channel = i; | |
6446 /* Clean the channel because there are some things that need to | |
6447 * be done that can't happen until the source is set | |
6448 */ | |
6449 Clean_Channel(i); | |
6450 } | |
6451 | |
6452 /* The Source_Map_List must be sorted by source for binary searches | |
6453 */ | |
6454 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
6455 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6456 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6457 ALmixer_OutputDecoders(); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6458 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6459 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6460 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6461 if(NULL == s_simpleLock) |
0 | 6462 { |
6463 /* SDL sets the error message already? */ | |
6464 free(source); | |
6465 free(ALmixer_Channel_List); | |
6466 free(Source_Map_List); | |
6467 alcDestroyContext(context); | |
6468 alcCloseDevice(dev); | |
6469 ALmixer_Initialized = 0; | |
6470 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6471 return AL_FALSE; |
0 | 6472 } |
6473 | |
6474 | |
6475 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
6476 if(NULL == Stream_Thread_global) | |
6477 { | |
6478 /* 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
|
6479 SDL_DestroyMutex(s_simpleLock); |
0 | 6480 free(source); |
6481 free(ALmixer_Channel_List); | |
6482 free(Source_Map_List); | |
6483 alcDestroyContext(context); | |
6484 alcCloseDevice(dev); | |
6485 ALmixer_Initialized = 0; | |
6486 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6487 return AL_FALSE; |
0 | 6488 } |
6489 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6490 /* |
0 | 6491 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6492 */ |
0 | 6493 #endif /* End of ENABLE_ALMIXER_THREADS */ |
6494 | |
6495 /* We don't need this array any more because all the sources | |
6496 * are connected to channels | |
6497 */ | |
6498 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6499 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6500 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6501 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6502 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6503 ALboolean ALmixer_InitContext(ALuint frequency, ALuint refresh) |
0 | 6504 { |
6505 ALCdevice* dev; | |
6506 ALCcontext* context; | |
6507 ALCenum error; | |
6508 | |
6509 #ifdef USING_LOKI_AL_DIST | |
6510 /* The Loki dist requires that I set both the | |
6511 * device and context frequency values separately | |
6512 */ | |
6513 /* Hope this won't overflow */ | |
6514 char device_string[256]; | |
6515 #endif | |
6516 | |
6517 /* (Venting frustration) Damn it! Nobody bothered | |
6518 * documenting how you're supposed to use an attribute | |
6519 * list. In fact, the not even the Loki test program | |
6520 * writers seem to know because they use it inconsistently. | |
6521 * For example, how do you terminate that attribute list? | |
6522 * The Loki test code does it 3 different ways. They | |
6523 * set the last value to 0, or they set it to ALC_INVALID, | |
6524 * or they set two final values: ALC_INVALID, 0 | |
6525 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6526 * but with Creative Labs ALC_INVALID is -1. | |
6527 * So something's going to break. Loki's source | |
6528 * code says to terminate with ALC_INVALID. But I | |
6529 * don't know if that's really true, or it happens | |
6530 * to be a coinicidence because it's defined to 0. | |
6531 * Creative provides no source code, so I can't look at how | |
6532 * they terminate it. | |
6533 * So this is really, really ticking me off... | |
6534 * For now, I'm going to use ALC_INVALID. | |
6535 * (Update...after further review of the API spec, | |
6536 * it seems that a NULL terminated string is the correct | |
6537 * termination value to use, so 0 it is.) | |
6538 */ | |
6539 #if 0 | |
6540 ALint attrlist[] = { | |
6541 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6542 /* Don't know anything about these values. | |
6543 * Trust defaults? */ | |
6544 /* Supposed to be the refresh rate in Hz. | |
6545 * I think 15-120 are supposed to be good | |
6546 * values. Though I haven't gotten any effect except | |
6547 * for one strange instance on a Mac. But it was | |
6548 * unrepeatable. | |
6549 */ | |
6550 #if 0 | |
6551 ALC_REFRESH, 15, | |
6552 #endif | |
6553 /* Sync requires a alcProcessContext() call | |
6554 * for every cycle. By default, this is | |
6555 * not used and the value is AL_FALSE | |
6556 * because it will probably perform | |
6557 * pretty badly for me. | |
6558 */ | |
6559 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6560 ALC_SYNC, AL_TRUE, | |
6561 #else | |
6562 ALC_SYNC, AL_FALSE, | |
6563 #endif | |
6564 /* Looking at the API spec, it implies | |
6565 * that the list be a NULL terminated string | |
6566 * so it's probably not safe to use ALC_INVALID | |
6567 */ | |
6568 /* | |
6569 ALC_INVALID }; | |
6570 */ | |
6571 '\0'}; | |
6572 #endif | |
6573 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6574 * However, if no value is specified, I don't | |
6575 * want it in the list so I can get the OpenAL defaults | |
6576 */ | |
6577 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6578 ALsizei current_attrlist_index = 0; |
0 | 6579 |
6580 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6581 /* More problems: I'm getting bit by endian/signedness issues on | |
6582 * different platforms. I can find the endianess easily enough, | |
6583 * but I don't know how to determine what the correct signedness | |
6584 * is (if such a thing exists). I do know that if I try using | |
6585 * unsigned on OSX with an originally signed sample, I get | |
6586 * distortion. However, I don't have any native unsigned samples | |
6587 * to test. But I'm assuming that the platform must be in the | |
6588 * correct signedness no matter what. | |
6589 * I can either assume everybody is signed, or I can try to | |
6590 * determine the value. If I try to determine the values, | |
6591 * I think my only ability to figure it out will be to open | |
6592 * SDL_Audio, and read what the obtained settings were. | |
6593 * Then shutdown everything. However, I don't even know how | |
6594 * reliable this is. | |
6595 * Update: I think I resolved the issues...forgot to update | |
6596 * these comments when it happened. I should check the revision control | |
6597 * log... Anyway, I think the issue was partly related to me not | |
6598 * doing something correctly with the AudioInfo or some kind | |
6599 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6600 * revision control, I think I might have assumed that SDL_Sound would | |
6601 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6602 * and had to fill one out myself. | |
6603 */ | |
6604 SDL_AudioSpec desired; | |
6605 SDL_AudioSpec obtained; | |
6606 #endif | |
6607 | |
6608 | |
6609 | |
6610 | |
6611 /* Make sure ALmixer isn't already initialized */ | |
6612 if(ALmixer_Initialized) | |
6613 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6614 return AL_FALSE; |
0 | 6615 } |
6616 | |
6617 /* Set the defaults */ | |
6618 attrlist[0] = ALC_FREQUENCY; | |
6619 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6620 attrlist[2] = ALC_SYNC; | |
6621 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6622 attrlist[3] = ALC_TRUE; | |
6623 #else | |
6624 attrlist[3] = ALC_FALSE; | |
6625 #endif | |
6626 /* Set frequency value if it is not 0 */ | |
6627 if(0 != frequency) | |
6628 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6629 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6630 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6631 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6632 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6633 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6634 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6635 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6636 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6637 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6638 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6639 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6640 #endif |
0 | 6641 |
6642 /* If the user specifies a refresh value, | |
6643 * make room for it | |
6644 */ | |
6645 if(0 != refresh) | |
6646 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6647 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
|
6648 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6649 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6650 current_attrlist_index++; |
0 | 6651 } |
6652 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6653 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6654 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6655 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6656 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6657 |
0 | 6658 /* Initialize SDL_Sound */ |
6659 if(! Sound_Init() ) | |
6660 { | |
6661 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6662 return AL_FALSE; |
0 | 6663 } |
6664 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6665 /* Here is the paranoid check that opens | |
6666 * SDL audio in an attempt to find the correct | |
6667 * system values. | |
6668 */ | |
6669 /* Doesn't have to be the actual value I think | |
6670 * (as long as it doesn't influence format, in | |
6671 * which case I'm probably screwed anyway because OpenAL | |
6672 * may easily choose to do something else). | |
6673 */ | |
6674 desired.freq = 44100; | |
6675 desired.channels = 2; | |
6676 desired.format = AUDIO_S16SYS; | |
6677 desired.callback = my_dummy_audio_callback; | |
6678 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6679 { | |
6680 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6681 /* Now to get really paranoid, we should probably | |
6682 * also assume that the 8bit format is also the | |
6683 * same sign type and set that value | |
6684 */ | |
6685 if(AUDIO_S16SYS == obtained.format) | |
6686 { | |
6687 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6688 } | |
6689 /* Should be AUDIO_U16SYS */ | |
6690 else | |
6691 { | |
6692 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6693 } | |
6694 SDL_CloseAudio(); | |
6695 } | |
6696 else | |
6697 { | |
6698 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6699 */ | |
6700 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6701 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6702 } | |
6703 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6704 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6705 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6706 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
6707 * causes OpenAL and SMPEG to conflict. For some reason | |
6708 * if SDL_Init on audio is active, then all the SMPEG | |
6709 * decoded sound comes out silent. Unfortunately, | |
6710 * Sound_Init() invokes SDL_Init on audio. I'm | |
6711 * not sure why it actually needs it... | |
6712 * But we'll attempt to disable it here after the | |
6713 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
6714 */ | |
6715 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6716 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6717 |
0 | 6718 /* I'm told NULL will call the default string |
6719 * and hopefully do the right thing for each platform | |
6720 */ | |
6721 /* | |
6722 dev = alcOpenDevice( NULL ); | |
6723 */ | |
6724 /* Now I'm told I need to set both the device and context | |
6725 * to have the same sampling rate, so I must pass a string | |
6726 * to OpenDevice(). I don't know how portable these strings are. | |
6727 * I don't even know if the format for strings is | |
6728 * compatible | |
6729 * From the testattrib.c in the Loki test section | |
6730 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
6731 */ | |
6732 | |
6733 #ifdef USING_LOKI_AL_DIST | |
6734 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
6735 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
6736 #else | |
6737 dev = alcOpenDevice( NULL ); | |
6738 #endif | |
6739 if(NULL == dev) | |
6740 { | |
6741 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
|
6742 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6743 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6744 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6745 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6746 /* 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
|
6747 /* 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
|
6748 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6749 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6750 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6751 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6752 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
|
6753 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6754 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
|
6755 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6756 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6757 |
0 | 6758 |
6759 context = alcCreateContext(dev, attrlist); | |
6760 if(NULL == context) | |
6761 { | |
6762 ALmixer_SetError("Cannot create a context OpenAL"); | |
6763 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6764 return AL_FALSE; |
0 | 6765 } |
6766 | |
6767 | |
6768 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6769 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6770 * According to Garin Hiebert, this is actually an inconsistency | |
6771 * in the Loki version. The function should return a boolean. | |
6772 * instead of ALC_NO_ERROR. Garin suggested I check via | |
6773 * alcGetError(). | |
6774 */ | |
6775 /* clear the error */ | |
6776 alcGetError(dev); | |
6777 alcMakeContextCurrent(context); | |
6778 | |
6779 error = alcGetError(dev); | |
6780 if( (ALC_NO_ERROR != error) ) | |
6781 { | |
6782 ALmixer_SetError("Could not MakeContextCurrent"); | |
6783 alcDestroyContext(context); | |
6784 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6785 return AL_FALSE; |
0 | 6786 } |
6787 | |
6788 | |
6789 #if 0 | |
6790 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
6791 if(alcGetCurrentContext() != context) | |
6792 { | |
6793 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6794 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6795 * I think this is a bug in the OpenAL implementation. | |
6796 */ | |
6797 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
6798 | |
6799 fprintf(stderr, "Making context current\n"); | |
6800 #ifndef __APPLE__ | |
6801 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
6802 #else | |
6803 if(!alcMakeContextCurrent(context)) | |
6804 #endif | |
6805 { | |
6806 ALmixer_SetError("Could not MakeContextCurrent"); | |
6807 alcDestroyContext(context); | |
6808 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6809 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6810 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6811 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6812 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6813 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6814 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6815 /* 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
|
6816 * 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
|
6817 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6818 * 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
|
6819 * 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
|
6820 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6821 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6822 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6823 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
|
6824 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6825 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
|
6826 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6827 #endif |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6828 |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6829 |
0 | 6830 |
6831 /* Saw this in the README with the OS X OpenAL distribution. | |
6832 * It looked interesting and simple, so I thought I might | |
6833 * try it out. | |
6834 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
6835 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
6836 * Audio format, the audio data passed to the | |
6837 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
6838 * usage by removing an audio data conversion | |
6839 * (per source) at render timem at the expense of a larger memory footprint. | |
6840 * | |
6841 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
6842 * setting will be applied to all subsequent | |
6843 * calls to alBufferData(). | |
6844 */ | |
6845 #ifdef __APPLE__ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6846 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6847 #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
|
6848 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6849 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6850 #endif |
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 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
|
6853 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6854 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
|
6855 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6856 if(0 != convert_data_enum) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6857 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6858 alEnable(convert_data_enum); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6859 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6860 if( (AL_NO_ERROR != alGetError()) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6861 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6862 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
|
6863 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
|
6864 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6865 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6866 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6867 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6868 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6869 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6870 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6871 ALboolean ALmixer_InitMixer(ALint num_sources) |
0 | 6872 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6873 ALint i; |
0 | 6874 ALenum error; |
6875 ALuint* source; | |
6876 | |
6877 | |
6878 ALmixer_Initialized = 1; | |
6879 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6880 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6881 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6882 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6883 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6884 /* 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
|
6885 /* 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
|
6886 * 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
|
6887 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6888 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6889 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6890 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6891 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6892 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6893 if(NULL == s_ALmixerErrorPool) |
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 return AL_FALSE; |
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 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6898 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6899 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6900 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
|
6901 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
|
6902 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6903 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6904 |
0 | 6905 if(num_sources <= 0) |
6906 { | |
6907 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
6908 } | |
6909 else | |
6910 { | |
6911 Number_of_Channels_global = num_sources; | |
6912 } | |
6913 Number_of_Reserve_Channels_global = 0; | |
6914 Is_Playing_global = 0; | |
6915 /* Set to Null in case system quit and was reinitialized */ | |
6916 Channel_Done_Callback = NULL; | |
6917 Channel_Done_Callback_Userdata = NULL; | |
6918 Channel_Data_Callback = NULL; | |
1 | 6919 Channel_Data_Callback_Userdata = NULL; |
0 | 6920 |
6921 /* Allocate memory for the list of channels */ | |
6922 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
6923 if(NULL == ALmixer_Channel_List) | |
6924 { | |
6925 ALmixer_SetError("Out of Memory for Channel List"); | |
6926 ALmixer_Initialized = 0; | |
6927 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6928 return AL_FALSE; |
0 | 6929 } |
6930 | |
6931 /* Allocate memory for the list of sources that map to the channels */ | |
6932 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
6933 if(NULL == Source_Map_List) | |
6934 { | |
6935 ALmixer_SetError("Out of Memory for Source Map List"); | |
6936 free(ALmixer_Channel_List); | |
6937 ALmixer_Initialized = 0; | |
6938 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6939 return AL_FALSE; |
0 | 6940 } |
6941 | |
6942 /* Create array that will hold the sources */ | |
6943 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
6944 if(NULL == source) | |
6945 { | |
6946 ALmixer_SetError("Out of Memory for sources"); | |
6947 free(Source_Map_List); | |
6948 free(ALmixer_Channel_List); | |
6949 ALmixer_Initialized = 0; | |
6950 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6951 return AL_FALSE; |
0 | 6952 } |
6953 | |
6954 /* Clear the error state */ | |
6955 alGetError(); | |
6956 /* Generate the OpenAL sources */ | |
6957 alGenSources(Number_of_Channels_global, source); | |
6958 if( (error=alGetError()) != AL_NO_ERROR) | |
6959 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6960 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 6961 free(ALmixer_Channel_List); |
6962 free(Source_Map_List); | |
6963 ALmixer_Initialized = 0; | |
6964 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6965 return AL_FALSE; |
0 | 6966 } |
6967 | |
6968 /* Initialize each channel and associate one source to one channel */ | |
6969 for(i=0; i<Number_of_Channels_global; i++) | |
6970 { | |
6971 Init_Channel(i); | |
6972 /* Keeping the source allocation out of the Init function | |
6973 * in case I want to reuse the Init | |
6974 * function for resetting data | |
6975 */ | |
6976 ALmixer_Channel_List[i].alsource = source[i]; | |
6977 /* Now also keep a copy of the source to channel mapping | |
6978 * in case we need to look up a channel from the source | |
6979 * instead of a source from a channel | |
6980 */ | |
6981 Source_Map_List[i].source = source[i]; | |
6982 Source_Map_List[i].channel = i; | |
6983 /* Clean the channel because there are some things that need to | |
6984 * be done that can't happen until the source is set | |
6985 */ | |
6986 Clean_Channel(i); | |
6987 } | |
6988 | |
6989 /* The Source_Map_List must be sorted by source for binary searches | |
6990 */ | |
6991 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
6992 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6993 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6994 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6995 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6996 if(NULL == s_simpleLock) |
0 | 6997 { |
6998 /* SDL sets the error message already? */ | |
6999 free(source); | |
7000 free(ALmixer_Channel_List); | |
7001 free(Source_Map_List); | |
7002 ALmixer_Initialized = 0; | |
7003 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7004 return AL_FALSE; |
0 | 7005 } |
7006 | |
7007 | |
7008 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
7009 if(NULL == Stream_Thread_global) | |
7010 { | |
7011 /* 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
|
7012 SDL_DestroyMutex(s_simpleLock); |
0 | 7013 free(source); |
7014 free(ALmixer_Channel_List); | |
7015 free(Source_Map_List); | |
7016 ALmixer_Initialized = 0; | |
7017 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7018 return AL_FALSE; |
0 | 7019 } |
7020 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7021 /* |
0 | 7022 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7023 */ |
0 | 7024 #endif /* End of ENABLE_ALMIXER_THREADS */ |
7025 | |
7026 /* We don't need this array any more because all the sources | |
7027 * are connected to channels | |
7028 */ | |
7029 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7030 return AL_TRUE; |
0 | 7031 } |
7032 | |
7033 | |
7034 | |
7035 /* Keep the return value void to allow easy use with | |
7036 * atexit() | |
7037 */ | |
7038 void ALmixer_Quit() | |
7039 { | |
7040 ALCcontext* context; | |
7041 ALCdevice* dev; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7042 ALint i; |
0 | 7043 |
7044 if( ! ALmixer_Initialized) | |
7045 { | |
7046 return; | |
7047 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7048 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7049 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7050 #endif |
0 | 7051 /* Shutdown everything before closing context */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7052 Internal_HaltChannel(-1, AL_FALSE); |
0 | 7053 |
7054 /* This flag will cause the thread to terminate */ | |
7055 ALmixer_Initialized = 0; | |
7056 #ifdef ENABLE_ALMIXER_THREADS | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7057 SDL_UnlockMutex(s_simpleLock); |
0 | 7058 SDL_WaitThread(Stream_Thread_global, NULL); |
7059 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7060 SDL_DestroyMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7061 #endif |
0 | 7062 |
7063 /* Delete all the OpenAL sources */ | |
7064 for(i=0; i<Number_of_Channels_global; i++) | |
7065 { | |
7066 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
7067 } | |
7068 /* Delete all the channels */ | |
7069 free(ALmixer_Channel_List); | |
7070 free(Source_Map_List); | |
7071 | |
7072 /* Reset the Number_of_Channels just in case somebody | |
7073 * tries using a ALmixer function. | |
7074 * I probably should put "Initialized" checks everywhere, | |
7075 * but I'm too lazy at the moment. | |
7076 */ | |
7077 Number_of_Channels_global = 0; | |
7078 | |
7079 context = alcGetCurrentContext(); | |
7080 if(NULL == context) | |
7081 { | |
7082 return; | |
7083 } | |
7084 /* Need to get the device before I close the context */ | |
7085 dev = alcGetContextsDevice(context); | |
7086 alcDestroyContext(context); | |
7087 | |
7088 if(NULL == dev) | |
7089 { | |
7090 return; | |
7091 } | |
7092 alcCloseDevice(dev); | |
7093 | |
7094 Sound_Quit(); | |
7095 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7096 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7097 /* 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
|
7098 TError_FreeErrorPool(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7099 s_ALmixerErrorPool = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7100 #endif |
0 | 7101 return; |
7102 } | |
7103 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7104 ALboolean ALmixer_IsInitialized() |
0 | 7105 { |
7106 return ALmixer_Initialized; | |
7107 } | |
7108 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7109 ALuint ALmixer_GetFrequency() |
0 | 7110 { |
7111 return ALmixer_Frequency_global; | |
7112 } | |
7113 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7114 const ALmixer_version* ALmixer_GetLinkedVersion() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7115 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7116 static ALmixer_version linked_mixver; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7117 ALMIXER_GET_COMPILED_VERSION(&linked_mixver); |
0 | 7118 return(&linked_mixver); |
7119 } | |
7120 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7121 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7122 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7123 const char* ALmixer_GetError() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7124 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7125 const char* error_string = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7126 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7127 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7128 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
|
7129 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7130 error_string = TError_GetLastErrorStr(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7131 /* 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
|
7132 if(NULL == error_string) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7133 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7134 return ""; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7135 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7136 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7137 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7138 return error_string; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7139 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7140 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7141 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7142 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
|
7143 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7144 if(NULL == s_ALmixerErrorPool) |
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 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
|
7147 return; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7148 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7149 va_list argp; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7150 va_start(argp, err_str); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7151 // 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
|
7152 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
|
7153 va_end(argp); |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7156 #endif |
0 | 7157 |
7158 | |
7159 | |
7160 | |
7161 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7162 void ALmixer_OutputAttributes() |
0 | 7163 { |
7164 ALint num_flags = 0; | |
7165 ALint* flags = 0; | |
7166 int i; | |
7167 ALCdevice* dev = alcGetContextsDevice( alcGetCurrentContext() ); | |
7168 | |
7169 | |
7170 printf("custom context\n"); | |
7171 | |
7172 alcGetIntegerv(dev, ALC_ATTRIBUTES_SIZE, | |
7173 sizeof num_flags, &num_flags ); | |
7174 | |
7175 printf("Number of Flags: %d\n", num_flags); | |
7176 | |
7177 if(num_flags) | |
7178 { | |
7179 flags = malloc(sizeof(num_flags) * sizeof(ALint)); | |
7180 | |
7181 alcGetIntegerv(dev, ALC_ALL_ATTRIBUTES, | |
7182 sizeof num_flags * sizeof(ALint), | |
7183 flags ); | |
7184 } | |
7185 for(i = 0; i < num_flags-1; i += 2) | |
7186 { | |
7187 printf("key 0x%x : value %d\n", | |
7188 flags[i], flags[i+1]); | |
7189 } | |
7190 free(flags); | |
7191 } | |
7192 #endif | |
7193 | |
7194 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7195 void ALmixer_OutputDecoders() |
0 | 7196 { |
7197 Sound_Version sound_compile_version; | |
7198 Sound_Version sound_link_version; | |
7199 | |
7200 const Sound_DecoderInfo **rc = Sound_AvailableDecoders(); | |
7201 const Sound_DecoderInfo **i; | |
7202 const char **ext; | |
7203 FILE* stream = stdout; | |
7204 | |
7205 | |
7206 fprintf(stream, "SDL_sound Information:\n"); | |
7207 | |
7208 SOUND_VERSION(&sound_compile_version); | |
7209 fprintf(stream, "\tCompiled with SDL_sound version: %d.%d.%d\n", | |
7210 sound_compile_version.major, | |
7211 sound_compile_version.minor, | |
7212 sound_compile_version.patch); | |
7213 | |
7214 Sound_GetLinkedVersion(&sound_link_version); | |
7215 fprintf(stream, "\tRunning (linked) with SDL_sound version: %d.%d.%d\n", | |
7216 sound_link_version.major, | |
7217 sound_link_version.minor, | |
7218 sound_link_version.patch); | |
7219 | |
7220 fprintf(stream, "Supported sound formats:\n"); | |
7221 if (rc == NULL) | |
7222 fprintf(stream, " * Apparently, NONE!\n"); | |
7223 else | |
7224 { | |
7225 for (i = rc; *i != NULL; i++) | |
7226 { | |
7227 fprintf(stream, " * %s\n", (*i)->description); | |
7228 | |
7229 for (ext = (*i)->extensions; *ext != NULL; ext++) | |
7230 fprintf(stream, " File extension \"%s\"\n", *ext); | |
7231 | |
7232 fprintf(stream, " Written by %s.\n %s\n\n", | |
7233 (*i)->author, (*i)->url); | |
7234 } /* for */ | |
7235 } /* else */ | |
7236 | |
7237 fprintf(stream, "\n"); | |
7238 } | |
7239 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7240 void ALmixer_OutputOpenALInfo() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7241 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7242 ALmixer_version mixer_compile_version; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7243 const ALmixer_version * mixer_link_version=ALmixer_GetLinkedVersion(); |
0 | 7244 FILE* stream = stdout; |
7245 | |
7246 fprintf(stream, "OpenAL Information:\n"); | |
7247 fprintf(stream, "\tAL_VENDOR: %s\n", alGetString( AL_VENDOR ) ); | |
7248 fprintf(stream, "\tAL_VERSION: %s\n", alGetString( AL_VERSION ) ); | |
7249 fprintf(stream, "\tAL_RENDERER: %s\n", alGetString( AL_RENDERER ) ); | |
7250 fprintf(stream, "\tAL_EXTENSIONS: %s\n", alGetString( AL_EXTENSIONS ) ); | |
7251 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7252 ALMIXER_GET_COMPILED_VERSION(&mixer_compile_version); |
0 | 7253 fprintf(stream, "\nSDL_ALmixer Information:\n"); |
7254 fprintf(stream, "\tCompiled with SDL_ALmixer version: %d.%d.%d\n", | |
7255 mixer_compile_version.major, | |
7256 mixer_compile_version.minor, | |
7257 mixer_compile_version.patch); | |
7258 | |
7259 fprintf(stream, "\tRunning (linked) with SDL_ALmixer version: %d.%d.%d\n", | |
7260 mixer_link_version->major, | |
7261 mixer_link_version->minor, | |
7262 mixer_link_version->patch); | |
7263 | |
7264 fprintf(stream, "\tCompile flags: "); | |
7265 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
7266 fprintf(stream, "ENABLE_LOKI_QUEUE_FIX_HACK "); | |
7267 #endif | |
7268 #ifdef ENABLE_ALMIXER_THREADS | |
7269 fprintf(stream, "ENABLE_ALMIXER_THREADS "); | |
7270 #endif | |
7271 #ifdef ENABLE_ALC_SYNC | |
7272 fprintf(stream, "ENABLE_ALC_SYNC "); | |
7273 #endif | |
7274 fprintf(stream, "\n"); | |
7275 } | |
7276 | |
7277 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7278 ALint ALmixer_AllocateChannels(ALint numchans) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7279 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7280 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7281 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7282 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7283 #endif |
0 | 7284 retval = Internal_AllocateChannels(numchans); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7285 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7286 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7287 #endif |
0 | 7288 return retval; |
7289 } | |
7290 | |
7291 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7292 ALint ALmixer_ReserveChannels(ALint num) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7293 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7294 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7295 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7296 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7297 #endif |
0 | 7298 retval = Internal_ReserveChannels(num); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7299 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7300 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7301 #endif |
0 | 7302 return retval; |
7303 } | |
7304 | |
7305 | |
7306 | |
7307 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7308 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
|
7309 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7310 ALuint bytes_decoded; |
0 | 7311 ALmixer_Data* ret_data; |
7312 ALenum error; | |
7313 | |
7314 /* Allocate memory */ | |
7315 ret_data = (ALmixer_Data *)malloc(sizeof(ALmixer_Data)); | |
7316 if (NULL == ret_data) | |
7317 { | |
7318 ALmixer_SetError("Out of memory"); | |
7319 return(NULL); | |
7320 } | |
7321 | |
7322 /* Initialize the data fields */ | |
7323 | |
7324 /* Set the Sound_Sample pointer */ | |
7325 ret_data->sample = sample; | |
7326 | |
7327 /* Flag the data to note that it is not in use */ | |
7328 ret_data->in_use = 0; | |
7329 | |
7330 /* Initialize remaining flags */ | |
7331 ret_data->total_time = -1; | |
7332 ret_data->eof = 0; | |
7333 | |
7334 /* Just initialize */ | |
7335 ret_data->num_buffers_in_use = 0; | |
7336 | |
7337 /* Just initialize */ | |
7338 ret_data->total_bytes = 0; | |
7339 | |
7340 /* Just initialize */ | |
7341 ret_data->loaded_bytes = 0; | |
7342 | |
7343 /* Set the max queue buffers (minimum must be 2) */ | |
7344 if(max_queue_buffers < 2) | |
7345 { | |
7346 max_queue_buffers = ALMIXER_DEFAULT_QUEUE_BUFFERS; | |
7347 } | |
7348 ret_data->max_queue_buffers = max_queue_buffers; | |
7349 /* Set up the start up buffers */ | |
7350 if(0 == num_startup_buffers) | |
7351 { | |
7352 num_startup_buffers = ALMIXER_DEFAULT_STARTUP_BUFFERS; | |
7353 } | |
7354 /* Make sure start up buffers is less or equal to max_queue_buffers */ | |
7355 if(num_startup_buffers > max_queue_buffers) | |
7356 { | |
7357 num_startup_buffers = max_queue_buffers; | |
7358 } | |
7359 ret_data->num_startup_buffers = num_startup_buffers; | |
7360 | |
7361 ret_data->buffer_map_list = NULL; | |
7362 ret_data->current_buffer = 0; | |
7363 | |
7364 ret_data->circular_buffer_queue = NULL; | |
7365 | |
7366 /* Now decode and load the data into a data chunk */ | |
7367 /* Different cases for Streamed and Predecoded | |
7368 * Streamed might turn into a predecoded if buffersize | |
7369 * is large enough */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7370 if(AL_FALSE == decode_mode_is_predecoded) |
0 | 7371 { |
7372 bytes_decoded = Sound_Decode(sample); | |
7373 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7374 { | |
7375 ALmixer_SetError(Sound_GetError()); | |
7376 Sound_FreeSample(sample); | |
7377 free(ret_data); | |
7378 return NULL; | |
7379 } | |
7380 | |
7381 /* If no data, return an error */ | |
7382 if(0 == bytes_decoded) | |
7383 { | |
7384 ALmixer_SetError("File has no data"); | |
7385 Sound_FreeSample(sample); | |
7386 free(ret_data); | |
7387 return NULL; | |
7388 } | |
7389 | |
7390 /* Note, currently, my Ogg conservative modifications | |
7391 * prevent EOF from being detected in the first read | |
7392 * because of the weird packet behavior of ov_read(). | |
7393 * The EAGAIN will get set, but not the EOF. | |
7394 * I don't know the best way to handle this, | |
7395 * so for now, Ogg's can only be explicitly | |
7396 * predecoded. | |
7397 */ | |
7398 | |
7399 /* Correction: Since we no longer actually keep the | |
7400 * streamed data we read here (we rewind and throw | |
7401 * it away, and start over on Play), it is | |
7402 * safe to read another chunk to see if we've hit EOF | |
7403 */ | |
7404 if(sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
7405 { | |
7406 bytes_decoded = Sound_Decode(sample); | |
7407 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7408 { | |
7409 ALmixer_SetError(Sound_GetError()); | |
7410 Sound_FreeSample(sample); | |
7411 free(ret_data); | |
7412 return NULL; | |
7413 } | |
7414 } | |
7415 | |
7416 | |
7417 /* If we found an EOF, the entire file was | |
7418 * decoded, so we can treat it like one. | |
7419 */ | |
7420 | |
7421 if(sample->flags & SOUND_SAMPLEFLAG_EOF) | |
7422 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7423 /* |
0 | 7424 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
|
7425 */ |
0 | 7426 ret_data->decoded_all = 1; |
7427 /* Need to keep this information around for | |
7428 * seek and rewind abilities. | |
7429 */ | |
7430 ret_data->total_bytes = bytes_decoded; | |
7431 /* For now, the loaded bytes is the same as total bytes, but | |
7432 * this could change during a seek operation | |
7433 */ | |
7434 ret_data->loaded_bytes = bytes_decoded; | |
7435 | |
7436 /* Let's compute the total playing time | |
7437 * SDL_sound does not yet provide this (we're working on | |
7438 * that at the moment...) | |
7439 */ | |
7440 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
7441 | |
7442 /* Create one element in the buffer array for data for OpanAL */ | |
7443 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
7444 if(NULL == ret_data->buffer) | |
7445 { | |
7446 ALmixer_SetError("Out of Memory"); | |
7447 Sound_FreeSample(sample); | |
7448 free(ret_data); | |
7449 return NULL; | |
7450 } | |
7451 /* Clear the error code */ | |
7452 alGetError(); | |
7453 /* Now generate an OpenAL buffer using that first element */ | |
7454 alGenBuffers(1, ret_data->buffer); | |
7455 if( (error = alGetError()) != AL_NO_ERROR) | |
7456 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7457 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7458 Sound_FreeSample(sample); |
7459 free(ret_data->buffer); | |
7460 free(ret_data); | |
7461 return NULL; | |
7462 } | |
7463 | |
7464 | |
7465 /* Now copy the data to the OpenAL buffer */ | |
7466 /* We can't just set a pointer because the API needs | |
7467 * its own copy to assist hardware acceleration */ | |
7468 alBufferData(ret_data->buffer[0], | |
7469 TranslateFormat(&sample->desired), | |
7470 sample->buffer, | |
7471 bytes_decoded, | |
7472 sample->desired.rate | |
7473 ); | |
7474 if( (error = alGetError()) != AL_NO_ERROR) | |
7475 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7476 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 7477 Sound_FreeSample(sample); |
7478 alDeleteBuffers(1, ret_data->buffer); | |
7479 free(ret_data->buffer); | |
7480 free(ret_data); | |
7481 return NULL; | |
7482 } | |
7483 | |
7484 /* We should be done with the sample since it's all | |
7485 * predecoded. So we can free the memory */ | |
7486 | |
7487 /* Additional notes: | |
7488 * We need to keep data around in case Seek() is needed | |
7489 * or other Sound_AudioInfo is needed. | |
7490 * This can either be done by not deleting the sample, | |
7491 * or it can be done by dynamically recreating it | |
7492 * when we need it. | |
7493 */ | |
7494 /* Since OpenAL won't let us retrieve it | |
7495 * (aka dynamically), we have to keep the Sample | |
7496 * around because since the user requested | |
7497 * streamed and we offered predecoded, | |
7498 * we don't want to mess up the user who | |
7499 * was expecting seek support | |
7500 * So Don't Do anything | |
7501 */ | |
7502 /* | |
7503 if(0 == access_data) | |
7504 { | |
7505 Sound_FreeSample(sample); | |
7506 ret_data->sample = NULL; | |
7507 } | |
7508 */ | |
7509 /* Else, We keep a copy of the sample around. | |
7510 * so don't do anything. | |
7511 */ | |
7512 | |
7513 #if 0 | |
7514 #if defined(DISABLE_PREDECODED_SEEK) | |
7515 Sound_FreeSample(sample); | |
7516 ret_data->sample = NULL; | |
7517 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
7518 Sound_FreeSample(sample); | |
7519 ret_data->sample = NULL; | |
7520 #else | |
7521 /* We keep a copy of the sample around. | |
7522 * so don't do anything. | |
7523 */ | |
7524 #endif | |
7525 #endif | |
7526 /* okay we're done here */ | |
7527 | |
7528 } | |
7529 /* Else, we need to stream the data, so we'll | |
7530 * create multple buffers for queuing */ | |
7531 else | |
7532 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7533 /* |
0 | 7534 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
|
7535 */ |
0 | 7536 ret_data->decoded_all = 0; |
7537 | |
7538 /* This information is for predecoded. | |
7539 * Set to 0, since we don't know. | |
7540 */ | |
7541 ret_data->total_bytes = 0; | |
7542 | |
7543 /* Create buffers for data | |
7544 */ | |
7545 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) * max_queue_buffers); | |
7546 if(NULL == ret_data->buffer) | |
7547 { | |
7548 ALmixer_SetError("Out of Memory"); | |
7549 Sound_FreeSample(sample); | |
7550 free(ret_data); | |
7551 return NULL; | |
7552 } | |
7553 | |
7554 /* Clear the error code */ | |
7555 alGetError(); | |
7556 /* Now generate an OpenAL buffer using that first element */ | |
7557 alGenBuffers(max_queue_buffers, ret_data->buffer); | |
7558 if( (error = alGetError()) != AL_NO_ERROR) | |
7559 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7560 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7561 Sound_FreeSample(sample); |
7562 free(ret_data->buffer); | |
7563 free(ret_data); | |
7564 return NULL; | |
7565 } | |
7566 | |
7567 /* Redesign: Okay, because of the unqueuing problems and such, | |
7568 * I've decided to redesign where and how queuing is handled. | |
7569 * Before, everything was queued up here. However, this | |
7570 * placed a penalty on load and made performance inconsistent | |
7571 * when samples had to be rewound. It did make things easier | |
7572 * to queue because I could let OpenAL decide which buffer | |
7573 * needed to be queued next. | |
7574 * Now, I'm going to push off the queuing to the actual | |
7575 * Play() command. I'm going to add some book keeping, | |
7576 * and allow for additional buffers to be filled at later | |
7577 * times. | |
7578 */ | |
7579 | |
7580 | |
7581 /* So first of all, because of I already decoded the sample | |
7582 * for testing, I need to decide what to do with it. | |
7583 * The best thing would be be to alBufferData() it. | |
7584 * The problem is it may conflict with the rest of | |
7585 * the system because everything now assumes buffers | |
7586 * are entirely stripped (because of the unqueing | |
7587 * problem). | |
7588 * So it looks like I have to do the crappy thing | |
7589 * and throw away the data, and rewind. | |
7590 */ | |
7591 | |
7592 if(0 == Sound_Rewind(ret_data->sample)) | |
7593 { | |
7594 ALmixer_SetError("Cannot use sample for streamed data because it must be rewindable: %s", Sound_GetError() ); | |
7595 Sound_FreeSample(sample); | |
7596 free(ret_data->buffer); | |
7597 free(ret_data); | |
7598 return NULL; | |
7599 } | |
7600 | |
7601 | |
7602 /* If the user has selected access_data, we need to | |
7603 * keep copies of the queuing buffers around because | |
7604 * OpenAL won't let us access the data. | |
7605 * Allocate the memory for the buffers here | |
7606 * and initialize the albuffer-index map | |
7607 */ | |
7608 if(access_data) | |
7609 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7610 ALuint j; |
0 | 7611 /* Create buffers for data access |
7612 * Should be the same number as the number of queue buffers | |
7613 */ | |
1 | 7614 ret_data->buffer_map_list = (ALmixer_Buffer_Map*)malloc( sizeof(ALmixer_Buffer_Map) * max_queue_buffers); |
0 | 7615 if(NULL == ret_data->buffer_map_list) |
7616 { | |
7617 ALmixer_SetError("Out of Memory"); | |
7618 Sound_FreeSample(sample); | |
7619 free(ret_data->buffer); | |
7620 free(ret_data); | |
7621 return NULL; | |
7622 } | |
7623 | |
7624 ret_data->circular_buffer_queue = CircularQueueUnsignedInt_CreateQueue(max_queue_buffers); | |
7625 if(NULL == ret_data->circular_buffer_queue) | |
7626 { | |
7627 ALmixer_SetError("Out of Memory"); | |
7628 free(ret_data->buffer_map_list); | |
7629 Sound_FreeSample(sample); | |
7630 free(ret_data->buffer); | |
7631 free(ret_data); | |
7632 return NULL; | |
7633 } | |
7634 | |
7635 | |
7636 for(j=0; j<max_queue_buffers; j++) | |
7637 { | |
7638 ret_data->buffer_map_list[j].albuffer = ret_data->buffer[j]; | |
7639 ret_data->buffer_map_list[j].index = j; | |
7640 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
|
7641 ret_data->buffer_map_list[j].data = (ALbyte*)malloc( sizeof(ALbyte) * buffersize); |
0 | 7642 if(NULL == ret_data->buffer_map_list[j].data) |
7643 { | |
7644 ALmixer_SetError("Out of Memory"); | |
7645 break; | |
7646 } | |
7647 } | |
7648 /* If an error happened, we have to clean up the memory */ | |
7649 if(j < max_queue_buffers) | |
7650 { | |
7651 fprintf(stderr, "################## Buffer allocation failed\n"); | |
7652 for( ; j>=0; j--) | |
7653 { | |
7654 free(ret_data->buffer_map_list[j].data); | |
7655 } | |
7656 free(ret_data->buffer_map_list); | |
7657 CircularQueueUnsignedInt_FreeQueue(ret_data->circular_buffer_queue); | |
7658 Sound_FreeSample(sample); | |
7659 free(ret_data->buffer); | |
7660 free(ret_data); | |
7661 return NULL; | |
7662 } | |
7663 | |
7664 /* The Buffer_Map_List must be sorted by albuffer for binary searches | |
7665 */ | |
1 | 7666 qsort(ret_data->buffer_map_list, max_queue_buffers, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 7667 } /* End if access_data==true */ |
7668 | |
7669 | |
7670 } /* End of do stream */ | |
7671 } /* end of DECODE_STREAM */ | |
7672 /* 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
|
7673 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
|
7674 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7675 #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
|
7676 /* 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
|
7677 * 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
|
7678 * 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
|
7679 * so looping isn't needed. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7680 * 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
|
7681 * 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
|
7682 * 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
|
7683 * 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
|
7684 * 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
|
7685 * 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
|
7686 * to load a file. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7687 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7688 ALint sound_duration = Sound_GetDuration(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7689 if(sound_duration > 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7690 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7691 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
|
7692 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
|
7693 if(0 == buffer_resize_succeeded) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7694 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7695 ALmixer_SetError(Sound_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7696 Sound_FreeSample(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7697 free(ret_data); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7698 return NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7699 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7700 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7701 #endif /* ALMIXER_DISABLE_PREDECODED_PRECOMPUTE_BUFFER_SIZE_OPTIMIZATION */ |
0 | 7702 bytes_decoded = Sound_DecodeAll(sample); |
7703 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7704 { | |
7705 ALmixer_SetError(Sound_GetError()); | |
7706 Sound_FreeSample(sample); | |
7707 free(ret_data); | |
7708 return NULL; | |
7709 } | |
7710 | |
7711 /* If no data, return an error */ | |
7712 if(0 == bytes_decoded) | |
7713 { | |
7714 ALmixer_SetError("File has no data"); | |
7715 Sound_FreeSample(sample); | |
7716 free(ret_data); | |
7717 return NULL; | |
7718 } | |
7719 | |
7720 | |
7721 ret_data->decoded_all = 1; | |
7722 /* Need to keep this information around for | |
7723 * seek and rewind abilities. | |
7724 */ | |
7725 ret_data->total_bytes = bytes_decoded; | |
7726 /* For now, the loaded bytes is the same as total bytes, but | |
7727 * this could change during a seek operation | |
7728 */ | |
7729 ret_data->loaded_bytes = bytes_decoded; | |
7730 | |
7731 /* Let's compute the total playing time | |
7732 * SDL_sound does not yet provide this (we're working on | |
7733 * that at the moment...) | |
7734 */ | |
7735 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
7736 | |
7737 /* Create one element in the buffer array for data for OpanAL */ | |
7738 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
7739 if(NULL == ret_data->buffer) | |
7740 { | |
7741 ALmixer_SetError("Out of Memory"); | |
7742 Sound_FreeSample(sample); | |
7743 free(ret_data); | |
7744 return NULL; | |
7745 } | |
7746 /* Clear the error code */ | |
7747 alGetError(); | |
7748 /* Now generate an OpenAL buffer using that first element */ | |
7749 alGenBuffers(1, ret_data->buffer); | |
7750 if( (error = alGetError()) != AL_NO_ERROR) | |
7751 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7752 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7753 Sound_FreeSample(sample); |
7754 free(ret_data->buffer); | |
7755 free(ret_data); | |
7756 return NULL; | |
7757 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7758 /* |
0 | 7759 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
|
7760 */ |
0 | 7761 /* Now copy the data to the OpenAL buffer */ |
7762 /* We can't just set a pointer because the API needs | |
7763 * its own copy to assist hardware acceleration */ | |
7764 alBufferData(ret_data->buffer[0], | |
7765 TranslateFormat(&sample->desired), | |
7766 sample->buffer, | |
7767 bytes_decoded, | |
7768 sample->desired.rate | |
7769 ); | |
7770 if( (error = alGetError()) != AL_NO_ERROR) | |
7771 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7772 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 7773 Sound_FreeSample(sample); |
7774 alDeleteBuffers(1, ret_data->buffer); | |
7775 free(ret_data->buffer); | |
7776 free(ret_data); | |
7777 return NULL; | |
7778 } | |
7779 | |
7780 /* We should be done with the sample since it's all | |
7781 * predecoded. So we can free the memory */ | |
7782 /* Need to keep around because Seek() needs it */ | |
7783 | |
7784 /* Additional notes: | |
7785 * We need to keep data around in case Seek() is needed | |
7786 * or other Sound_AudioInfo is needed. | |
7787 * This can either be done by not deleting the sample, | |
7788 * or it can be done by dynamically recreating it | |
7789 * when we need it. | |
7790 * Update: I think now it's up to the user by passing the | |
7791 * access_data flag. If they set the flag, then they get | |
7792 * data callbacks and seek support. If not, then they can | |
7793 * get all that stuff at the expense of keeping extra memory | |
7794 * around. | |
7795 */ | |
7796 if(0 == access_data) | |
7797 { | |
7798 Sound_FreeSample(sample); | |
7799 ret_data->sample = NULL; | |
7800 } | |
7801 | |
7802 /* Else, We keep a copy of the sample around. | |
7803 * so don't do anything. | |
7804 */ | |
7805 #if 0 | |
7806 #if defined(DISABLE_PREDECODED_SEEK) | |
7807 Sound_FreeSample(sample); | |
7808 ret_data->sample = NULL; | |
7809 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
7810 Sound_FreeSample(sample); | |
7811 ret_data->sample = NULL; | |
7812 #else | |
7813 /* We keep a copy of the sample around. | |
7814 * so don't do anything. | |
7815 */ | |
7816 #endif | |
7817 #endif | |
7818 | |
7819 /* okay we're done here */ | |
7820 } | |
7821 else | |
7822 { | |
7823 /* Shouldn't get here */ | |
7824 ALmixer_SetError("Unknown decode mode"); | |
7825 Sound_FreeSample(sample); | |
7826 free(ret_data); | |
7827 return NULL; | |
7828 } | |
7829 | |
7830 return ret_data; | |
7831 } | |
7832 | |
7833 | |
7834 /* This will load a sample for us. Most of the uglyness is | |
7835 * error checking and the fact that streamed/predecoded files | |
7836 * must be treated differently. | |
7837 * I don't like the AudioInfo parameter. I removed it once, | |
7838 * but the system will fail on RAW samples because the user | |
7839 * must specify it, so I had to bring it back. | |
7840 * Remember I must close the rwops if there is an error before NewSample() | |
7841 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7842 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 | 7843 { |
7844 Sound_Sample* sample = NULL; | |
7845 Sound_AudioInfo target; | |
7846 | |
7847 /* Initialize target values to defaults | |
7848 * 0 tells SDL_sound to use the "actual" values | |
7849 */ | |
7850 target.channels = 0; | |
7851 target.rate = 0; | |
7852 #if 0 | |
7853 /* This requires my new additions to SDL_sound. It will | |
7854 * convert the sample to the proper endian order. | |
7855 * If the actual is 8-bit, it will do unsigned, if | |
7856 * the actual is 16-bit, it will do signed. | |
7857 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
7858 * in this way. | |
7859 */ | |
7860 target.format = AUDIO_U8S16SYS; | |
7861 #else | |
7862 target.format = AUDIO_S16SYS; | |
7863 #endif | |
7864 | |
7865 /* Set a default buffersize if needed */ | |
7866 if(0 == buffersize) | |
7867 { | |
7868 buffersize = ALMIXER_DEFAULT_BUFFERSIZE; | |
7869 } | |
7870 | |
7871 sample = Sound_NewSample(rwops, fileext, &target, buffersize); | |
7872 if(NULL == sample) | |
7873 { | |
7874 ALmixer_SetError(Sound_GetError()); | |
7875 return NULL; | |
7876 } | |
7877 | |
1 | 7878 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 7879 } |
7880 | |
7881 | |
7882 | |
7883 /* This will load a sample for us from | |
7884 * a file (instead of RWops). Most of the uglyness is | |
7885 * error checking and the fact that streamed/predecoded files | |
7886 * must be treated differently. | |
7887 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7888 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 | 7889 { |
7890 Sound_Sample* sample = NULL; | |
7891 Sound_AudioInfo target; | |
7892 | |
7893 /* Initialize target values to defaults | |
7894 * 0 tells SDL_sound to use the "actual" values | |
7895 */ | |
7896 target.channels = 0; | |
7897 target.rate = 0; | |
7898 | |
7899 #if 0 | |
7900 /* This requires my new additions to SDL_sound. It will | |
7901 * convert the sample to the proper endian order. | |
7902 * If the actual is 8-bit, it will do unsigned, if | |
7903 * the actual is 16-bit, it will do signed. | |
7904 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
7905 * in this way. | |
7906 */ | |
7907 target.format = AUDIO_U8S16SYS; | |
7908 #else | |
7909 target.format = AUDIO_S16SYS; | |
7910 #endif | |
7911 | |
7912 #if 0 | |
7913 /* Okay, here's a messy hack. The problem is that we need | |
7914 * to convert the sample to have the correct bitdepth, | |
7915 * endian order, and signedness values. | |
7916 * The bit depth is 8 or 16. | |
7917 * The endian order is the native order of the system. | |
7918 * The signedness depends on what the original value | |
7919 * of the sample. Unfortunately, we can't specify these | |
7920 * values until we after we already know what the original | |
7921 * values were for bitdepth and signedness. | |
7922 * So we must open the file once to get the values, | |
7923 * then close it, and then reopen it with the | |
7924 * correct desired target values. | |
7925 * I tried changing the sample->desired field after | |
7926 * the NewSample call, but it had no effect, so | |
7927 * it looks like it must be set on open. | |
7928 */ | |
7929 /* Pick a small buffersize for the first open to not | |
7930 * waste much time allocating memory */ | |
7931 sample = Sound_NewSampleFromFile(filename, NULL, 512); | |
7932 if(NULL == sample) | |
7933 { | |
7934 ALmixer_SetError(Sound_GetError()); | |
7935 return NULL; | |
7936 } | |
7937 | |
7938 bit_depth = GetBitDepth(sample->actual.format); | |
7939 signedness_value = GetSignednessValue(sample->actual.format); | |
7940 if(8 == bit_depth) | |
7941 { | |
7942 /* If 8 bit, then we don't have to worry about | |
7943 * endian issues. We can just use the actual format | |
7944 * value and it should do the right thing | |
7945 */ | |
7946 target.format = sample->actual.format; | |
7947 } | |
7948 else | |
7949 { | |
7950 /* We'll assume it's 16-bit, and if it's not | |
7951 * hopefully SDL_sound will return an error, | |
7952 * or let us convert to 16-bit | |
7953 */ | |
7954 /* Now we need to get the correct signedness */ | |
7955 if(ALMIXER_UNSIGNED_VALUE == signedness_value) | |
7956 { | |
7957 /* Set to Unsigned 16-bit, system endian order */ | |
7958 target.format = AUDIO_U16SYS; | |
7959 } | |
7960 else | |
7961 { | |
7962 /* Again, we'll assume it's Signed 16-bit system order | |
7963 * or force the conversion and hope it works out | |
7964 */ | |
7965 target.format = AUDIO_S16SYS; | |
7966 } | |
7967 } | |
7968 | |
7969 /* Now we have the correct info. We need to close and reopen */ | |
7970 Sound_FreeSample(sample); | |
7971 #endif | |
7972 | |
7973 sample = Sound_NewSampleFromFile(filename, &target, buffersize); | |
7974 if(NULL == sample) | |
7975 { | |
7976 ALmixer_SetError(Sound_GetError()); | |
7977 return NULL; | |
7978 } | |
7979 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7980 /* |
0 | 7981 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
|
7982 */ |
1 | 7983 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 7984 } |
7985 | |
7986 | |
7987 /* This is a back door for RAW samples or if you need the | |
7988 * AudioInfo field. Use at your own risk. | |
7989 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7990 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 | 7991 { |
7992 Sound_Sample* sample = NULL; | |
1 | 7993 Sound_AudioInfo sound_desired; |
7994 /* Rather than copying the data from struct to struct, I could just | |
7995 * cast the thing since the structs are meant to be identical. | |
7996 * But if SDL_sound changes it's implementation, bad things | |
7997 * will probably happen. (Or if I change my implementation and | |
7998 * forget about the cast, same bad scenario.) Since this is a load | |
7999 * function, performance of this is negligible. | |
8000 */ | |
8001 if(NULL == desired) | |
8002 { | |
8003 sample = Sound_NewSample(rwops, fileext, NULL, buffersize); | |
8004 } | |
8005 else | |
8006 { | |
8007 sound_desired.format = desired->format; | |
8008 sound_desired.channels = desired->channels; | |
8009 sound_desired.rate = desired->rate; | |
8010 sample = Sound_NewSample(rwops, fileext, &sound_desired, buffersize); | |
8011 } | |
0 | 8012 if(NULL == sample) |
8013 { | |
8014 ALmixer_SetError(Sound_GetError()); | |
8015 return NULL; | |
8016 } | |
1 | 8017 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8018 } |
8019 | |
8020 | |
8021 | |
8022 | |
8023 /* This is a back door for RAW samples or if you need the | |
8024 * AudioInfo field. Use at your own risk. | |
8025 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8026 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 | 8027 { |
8028 Sound_Sample* sample = NULL; | |
1 | 8029 Sound_AudioInfo sound_desired; |
8030 /* Rather than copying the data from struct to struct, I could just | |
8031 * cast the thing since the structs are meant to be identical. | |
8032 * But if SDL_sound changes it's implementation, bad things | |
8033 * will probably happen. (Or if I change my implementation and | |
8034 * forget about the cast, same bad scenario.) Since this is a load | |
8035 * function, performance of this is negligible. | |
8036 */ | |
8037 if(NULL == desired) | |
8038 { | |
8039 sample = Sound_NewSampleFromFile(filename, NULL, buffersize); | |
8040 } | |
8041 else | |
8042 { | |
8043 sound_desired.format = desired->format; | |
8044 sound_desired.channels = desired->channels; | |
8045 sound_desired.rate = desired->rate; | |
8046 sample = Sound_NewSampleFromFile(filename, &sound_desired, buffersize); | |
8047 } | |
8048 | |
0 | 8049 if(NULL == sample) |
8050 { | |
8051 ALmixer_SetError(Sound_GetError()); | |
8052 return NULL; | |
8053 } | |
1 | 8054 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8055 } |
8056 | |
8057 | |
8058 | |
8059 | |
8060 void ALmixer_FreeData(ALmixer_Data* data) | |
8061 { | |
8062 ALenum error; | |
8063 if(NULL == data) | |
8064 { | |
8065 return; | |
8066 } | |
8067 | |
8068 if(data->decoded_all) | |
8069 { | |
8070 /* If access_data was enabled, then the Sound_Sample* | |
8071 * still exists. We need to free it | |
8072 */ | |
8073 if(data->sample != NULL) | |
8074 { | |
8075 Sound_FreeSample(data->sample); | |
8076 } | |
8077 alDeleteBuffers(1, data->buffer); | |
8078 if((error = alGetError()) != AL_NO_ERROR) | |
8079 { | |
8080 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
|
8081 alGetString(error)); |
0 | 8082 } |
8083 | |
8084 } | |
8085 else | |
8086 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8087 ALuint i; |
0 | 8088 |
8089 /* Delete buffer copies if access_data was enabled */ | |
8090 if(data->buffer_map_list != NULL) | |
8091 { | |
8092 for(i=0; i<data->max_queue_buffers; i++) | |
8093 { | |
8094 free(data->buffer_map_list[i].data); | |
8095 } | |
8096 free(data->buffer_map_list); | |
8097 } | |
8098 if(data->circular_buffer_queue != NULL) | |
8099 { | |
8100 CircularQueueUnsignedInt_FreeQueue(data->circular_buffer_queue); | |
8101 } | |
8102 | |
8103 Sound_FreeSample(data->sample); | |
8104 alDeleteBuffers(data->max_queue_buffers, data->buffer); | |
8105 if((error = alGetError()) != AL_NO_ERROR) | |
8106 { | |
8107 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
|
8108 alGetString(error)); |
0 | 8109 } |
8110 } | |
8111 free(data->buffer); | |
8112 free(data); | |
8113 } | |
8114 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8115 ALint ALmixer_GetTotalTime(ALmixer_Data* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8116 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8117 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8118 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8119 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8120 } |
0 | 8121 return data->total_time; |
8122 } | |
8123 | |
8124 /* This function will look up the source for the corresponding channel */ | |
8125 /* 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
|
8126 ALuint ALmixer_GetSource(ALint channel) |
0 | 8127 { |
8128 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8129 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8130 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8131 #endif |
0 | 8132 retval = Internal_GetSource(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8133 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8134 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8135 #endif |
0 | 8136 return retval; |
8137 } | |
8138 | |
8139 /* 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
|
8140 ALint ALmixer_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8141 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8142 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8143 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8144 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8145 #endif |
0 | 8146 retval = Internal_GetChannel(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8147 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8148 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8149 #endif |
0 | 8150 return retval; |
8151 } | |
8152 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8153 ALint ALmixer_FindFreeChannel(ALint start_channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8154 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8155 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8156 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8157 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8158 #endif |
0 | 8159 retval = Internal_FindFreeChannel(start_channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8160 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8161 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8162 #endif |
0 | 8163 return retval; |
8164 } | |
8165 | |
8166 | |
8167 | |
8168 /* API update function. | |
8169 * It should return the number of buffers that were | |
8170 * queued during the call. The value might be | |
8171 * used to guage how long you might wait to | |
8172 * call the next update loop in case you are worried | |
8173 * about preserving CPU cycles. The idea is that | |
8174 * when a buffer is queued, there was probably some | |
8175 * CPU intensive looping which took awhile. | |
8176 * 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
|
8177 * Timing the call with ALmixer_GetTicks() would produce |
0 | 8178 * more accurate information. |
8179 * Returns a negative value if there was an error, | |
8180 * the value being the number of errors. | |
8181 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8182 ALint ALmixer_Update() |
0 | 8183 { |
8184 #ifdef ENABLE_ALMIXER_THREADS | |
8185 /* The thread will handle all updates by itself. | |
8186 * Don't allow the user to explicitly call update. | |
8187 */ | |
8188 return 0; | |
8189 #else | |
8190 return( Update_ALmixer(NULL) ); | |
8191 #endif | |
8192 } | |
8193 | |
8194 | |
8195 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8196 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
|
8197 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8198 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8199 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8200 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8201 Channel_Done_Callback = playback_finished_callback; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8202 Channel_Done_Callback_Userdata = user_data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8203 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8204 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8205 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8206 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8207 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8208 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8209 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
|
8210 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8211 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8212 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8213 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8214 Channel_Data_Callback = playback_data_callback; |
1 | 8215 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
|
8216 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8217 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8218 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8219 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8220 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8221 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8222 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8223 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8224 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8225 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
|
8226 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8227 ALint retval; |
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 |
0 | 8231 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
|
8232 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8233 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8234 #endif |
0 | 8235 return retval; |
8236 } | |
8237 | |
8238 | |
8239 /* In case the user wants to specify a source instead of a channel, | |
8240 * they may use this function. This function will look up the | |
8241 * source-to-channel map, and convert the call into a | |
8242 * PlayChannelTimed() function call. | |
8243 * Returns the channel it's being played on. | |
8244 * Note: If you are prefer this method, then you need to be careful | |
8245 * about using PlayChannel, particularly if you request the | |
8246 * first available channels because source and channels have | |
8247 * a one-to-one mapping in this API. It is quite easy for | |
8248 * a channel/source to already be in use because of this. | |
8249 * In this event, an error message will be returned to you. | |
8250 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8251 ALuint ALmixer_PlaySourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALint ticks) |
0 | 8252 { |
8253 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8254 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8255 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8256 #endif |
0 | 8257 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
|
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8260 #endif |
0 | 8261 return retval; |
8262 } | |
8263 | |
8264 | |
8265 /* Will return the number of channels halted | |
8266 * or 0 for error | |
8267 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8268 ALint ALmixer_HaltChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8269 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8270 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8271 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8272 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8273 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8274 retval = Internal_HaltChannel(channel, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8275 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8276 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8277 #endif |
0 | 8278 return retval; |
8279 } | |
8280 | |
8281 /* Will return the number of channels halted | |
8282 * or 0 for error | |
8283 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8284 ALint ALmixer_HaltSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8285 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8286 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8287 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8288 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8289 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8290 retval = Internal_HaltSource(source, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8291 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8292 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8293 #endif |
0 | 8294 return retval; |
8295 } | |
8296 | |
8297 | |
8298 /* This will rewind the SDL_Sound sample for streamed | |
8299 * samples and start buffering up the data for the next | |
8300 * playback. This may require samples to be halted | |
8301 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8302 ALint ALmixer_RewindData(ALmixer_Data* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8303 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8304 ALint retval; |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8307 #endif |
0 | 8308 retval = Internal_RewindData(data); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8309 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8310 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8311 #endif |
0 | 8312 return retval; |
8313 } | |
8314 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8315 ALint ALmixer_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8316 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8317 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8318 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8319 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8320 #endif |
0 | 8321 retval = Internal_RewindChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8322 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8323 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8324 #endif |
0 | 8325 return retval; |
8326 } | |
8327 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8328 ALint ALmixer_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8329 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8330 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8331 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8332 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8333 #endif |
0 | 8334 retval = Internal_RewindSource(source); |
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8337 #endif |
0 | 8338 return retval; |
8339 } | |
8340 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8341 ALint ALmixer_PauseChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8342 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8343 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8344 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8345 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8346 #endif |
0 | 8347 retval = Internal_PauseChannel(channel); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8350 #endif |
0 | 8351 return retval; |
8352 } | |
8353 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8354 ALint ALmixer_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8355 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8356 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8357 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8358 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8359 #endif |
0 | 8360 retval = Internal_PauseSource(source); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8363 #endif |
0 | 8364 return retval; |
8365 } | |
8366 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8367 ALint ALmixer_ResumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8368 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8369 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8370 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8371 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8372 #endif |
0 | 8373 retval = Internal_ResumeChannel(channel); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8376 #endif |
0 | 8377 return retval; |
8378 } | |
8379 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8380 ALint ALmixer_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8381 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8382 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8383 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8384 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8385 #endif |
0 | 8386 retval = Internal_ResumeSource(source); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8389 #endif |
0 | 8390 return retval; |
8391 } | |
8392 | |
8393 /* Might consider setting eof to 0 as a "feature" | |
8394 * This will allow seek to end to stay there because | |
8395 * Play automatically rewinds if at the end */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8396 ALint ALmixer_SeekData(ALmixer_Data* data, ALuint msec) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8397 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8398 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8399 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8400 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8401 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8402 retval = Internal_SeekData(data, msec); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8403 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8404 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8405 #endif |
0 | 8406 return retval; |
8407 } | |
8408 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8409 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
|
8410 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8411 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8412 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8413 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8414 #endif |
0 | 8415 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
|
8416 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8417 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8418 #endif |
0 | 8419 return retval; |
8420 } | |
8421 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8422 ALuint ALmixer_FadeInSourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 8423 { |
8424 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8425 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8426 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8427 #endif |
0 | 8428 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
|
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8431 #endif |
0 | 8432 return retval; |
8433 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8434 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8435 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
|
8436 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8437 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8438 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8439 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8440 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8441 retval = Internal_FadeOutChannel(channel, ticks); |
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8444 #endif |
0 | 8445 return retval; |
8446 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8447 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8448 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
|
8449 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8450 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8451 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8452 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8453 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8454 retval = Internal_FadeOutSource(source, ticks); |
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8457 #endif |
0 | 8458 return retval; |
8459 } | |
8460 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8461 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
|
8462 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8463 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8464 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8465 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8466 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8467 retval = Internal_FadeChannel(channel, ticks, volume); |
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_UnlockMutex(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 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8472 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8473 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8474 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
|
8475 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8476 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8477 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8478 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8479 #endif |
0 | 8480 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
|
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8483 #endif |
0 | 8484 return retval; |
8485 } | |
8486 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8487 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8488 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
|
8489 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8490 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8491 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8492 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8493 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8494 retval = Internal_SetVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8495 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8496 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8497 #endif |
0 | 8498 return retval; |
8499 } | |
8500 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8501 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
|
8502 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8503 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8504 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8505 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8506 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8507 retval = Internal_SetVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8508 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8509 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8510 #endif |
0 | 8511 return retval; |
8512 } | |
8513 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8514 ALfloat ALmixer_GetVolumeChannel(ALint channel) |
0 | 8515 { |
8516 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8517 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8518 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8519 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8520 retval = Internal_GetVolumeChannel(channel); |
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_UnlockMutex(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 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8525 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8526 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8527 ALfloat ALmixer_GetVolumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8528 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8529 ALfloat retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8530 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8531 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8532 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8533 retval = Internal_GetVolumeSource(source); |
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_UnlockMutex(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 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8538 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8539 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8540 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
|
8541 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8542 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8543 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8544 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8545 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8546 retval = Internal_SetMaxVolumeChannel(channel, volume); |
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_UnlockMutex(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 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8551 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8552 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8553 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
|
8554 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8555 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8556 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8557 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8558 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8559 retval = Internal_SetMaxVolumeSource(source, volume); |
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_UnlockMutex(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 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8564 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8565 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8566 ALfloat ALmixer_GetMaxVolumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8567 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8568 ALfloat retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8569 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8570 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8571 #endif |
0 | 8572 retval = Internal_GetMaxVolumeChannel(channel); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8575 #endif |
0 | 8576 return retval; |
8577 } | |
8578 | |
8579 ALfloat ALmixer_GetMaxVolumeSource(ALuint source) | |
8580 { | |
8581 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8582 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8583 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8584 #endif |
0 | 8585 retval = Internal_GetMaxVolumeSource(source); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8588 #endif |
0 | 8589 return retval; |
8590 } | |
8591 | |
8592 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8593 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
|
8594 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8595 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8596 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8597 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8598 #endif |
0 | 8599 retval = Internal_SetMinVolumeChannel(channel, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8600 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8601 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8602 #endif |
0 | 8603 return retval; |
8604 } | |
8605 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8606 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
|
8607 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8608 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8609 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8610 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8611 #endif |
0 | 8612 retval = Internal_SetMinVolumeSource(source, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8613 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8614 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8615 #endif |
0 | 8616 return retval; |
8617 } | |
8618 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8619 ALfloat ALmixer_GetMinVolumeChannel(ALint channel) |
0 | 8620 { |
8621 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8622 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8623 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8624 #endif |
0 | 8625 retval = Internal_GetMinVolumeChannel(channel); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8628 #endif |
0 | 8629 return retval; |
8630 } | |
8631 | |
8632 ALfloat ALmixer_GetMinVolumeSource(ALuint source) | |
8633 { | |
8634 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8635 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8636 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8637 #endif |
0 | 8638 retval = Internal_GetMinVolumeSource(source); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8641 #endif |
0 | 8642 return retval; |
8643 } | |
8644 | |
8645 | |
8646 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8647 ALboolean ALmixer_SetMasterVolume(ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8648 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8649 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8650 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8651 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8652 #endif |
0 | 8653 retval = Internal_SetMasterVolume(volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8654 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8655 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8656 #endif |
0 | 8657 return retval; |
8658 } | |
8659 | |
8660 ALfloat ALmixer_GetMasterVolume() | |
8661 { | |
8662 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8663 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8664 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8665 #endif |
0 | 8666 retval = Internal_GetMasterVolume(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8667 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8668 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8669 #endif |
0 | 8670 return retval; |
8671 } | |
8672 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8673 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
|
8674 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8675 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8676 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8677 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8678 #endif |
0 | 8679 retval = Internal_ExpireChannel(channel, ticks); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8682 #endif |
0 | 8683 return retval; |
8684 } | |
8685 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8686 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
|
8687 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8688 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8689 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8690 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8691 #endif |
0 | 8692 retval = Internal_ExpireSource(source, ticks); |
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8695 #endif |
0 | 8696 return retval; |
8697 } | |
8698 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8699 ALint ALmixer_IsActiveChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8700 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8701 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8702 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8703 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8704 #endif |
0 | 8705 retval = Internal_QueryChannel(channel); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8708 #endif |
0 | 8709 return retval; |
8710 } | |
8711 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8712 ALint ALmixer_IsActiveSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8713 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8714 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8715 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8716 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8717 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8718 retval = Internal_QuerySource(source); |
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8721 #endif |
0 | 8722 return retval; |
8723 } | |
8724 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8725 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8726 ALint ALmixer_IsPlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8727 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8728 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8729 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8730 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8731 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8732 retval = Internal_PlayingChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8733 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8734 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8735 #endif |
0 | 8736 return retval; |
8737 } | |
8738 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8739 ALint ALmixer_IsPlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8740 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8741 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8742 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8743 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8744 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8745 retval = Internal_PlayingSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8746 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8747 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8748 #endif |
0 | 8749 return retval; |
8750 } | |
8751 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8752 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8753 ALint ALmixer_IsPausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8754 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8755 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8756 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8757 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8758 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8759 retval = Internal_PausedChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8760 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8761 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8762 #endif |
0 | 8763 return retval; |
8764 } | |
8765 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8766 ALint ALmixer_IsPausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8767 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8768 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8769 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8770 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8771 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8772 retval = Internal_PausedSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8773 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8774 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8775 #endif |
0 | 8776 return retval; |
8777 } | |
8778 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8779 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8780 ALuint ALmixer_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8781 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8782 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8783 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8784 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8785 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8786 retval = Internal_CountAllFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8787 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8788 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8789 #endif |
0 | 8790 return retval; |
8791 } | |
8792 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8793 ALuint ALmixer_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8794 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8795 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8796 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8797 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8798 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8799 retval = Internal_CountUnreservedFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8800 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8801 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8802 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8803 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8804 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8805 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8806 ALuint ALmixer_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8807 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8808 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8809 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8810 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8811 #endif |
0 | 8812 retval = Internal_CountAllUsedChannels(); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8815 #endif |
0 | 8816 return retval; |
8817 } | |
8818 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8819 ALuint ALmixer_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8820 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8821 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8822 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8823 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8824 #endif |
0 | 8825 retval = Internal_CountUnreservedUsedChannels(); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8828 #endif |
0 | 8829 return retval; |
8830 } | |
8831 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8832 ALboolean ALmixer_IsPredecoded(ALmixer_Data* data) |
1 | 8833 { |
8834 if(NULL == data) | |
8835 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8836 return AL_FALSE; |
1 | 8837 } |
8838 return data->decoded_all; | |
8839 } | |
8840 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8841 ALboolean ALmixer_CompiledWithThreadBackend() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8842 { |
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 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8845 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8846 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8847 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8848 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8849 |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8852 |