Mercurial > almixer_isolated
annotate ALmixer.c @ 10:c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Behavior change: Decided to make finishedNaturally return false if ending was due to expired ticks.
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Sun, 31 Oct 2010 05:49:44 -0700 |
parents | 4b1048af7e55 |
children | bfe90b4f3d87 |
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 |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
1754 /* Launch callback for consistency? */ |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
1755 Invoke_Channel_Done_Callback(channel, did_finish_naturally); |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
1756 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1757 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1758 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1759 counter++; |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1762 /* 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
|
1763 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1764 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1765 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1766 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
|
1767 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1768 /* 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
|
1769 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
|
1770 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1771 alSourceStop(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1772 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1773 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1774 fprintf(stderr, "19Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1775 alGetString(error)); |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1778 /* 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
|
1779 * 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
|
1780 * 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
|
1781 * 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
|
1782 * 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
|
1783 * 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
|
1784 * 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
|
1785 * 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
|
1786 * 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
|
1787 * 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
|
1788 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1789 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1790 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1791 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1792 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1793 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1794 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1795 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1796 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
|
1797 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1798 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
|
1799 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1800 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1801 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1802 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1803 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1804 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1805 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1806 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1807 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1808 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
|
1809 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1810 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
|
1811 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1812 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1813 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1814 /* 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
|
1815 * to clear the source |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1816 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1817 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
|
1818 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1819 alSourcei(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1820 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1821 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1822 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1823 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1824 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
|
1825 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1826 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
|
1827 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1828 retval = -1; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1832 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
|
1833 |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
1834 /* Launch callback for consistency? */ |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
1835 Invoke_Channel_Done_Callback(i, did_finish_naturally); |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
1836 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1837 Clean_Channel(i); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1838 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1839 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1840 /* Increment the counter */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1841 counter++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1842 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1843 /* 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
|
1844 * are bugs. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1845 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1846 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1847 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1848 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1849 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1850 / * 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
|
1851 * data will get messed up * / |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1852 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1853 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1854 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1855 /* Just in case */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1856 Is_Playing_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1857 } |
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 if(-1 == retval) |
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 -1; |
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 return counter; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1866 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1867 /* 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
|
1868 * 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
|
1869 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1870 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
|
1871 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1872 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1873 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1874 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1875 /* 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
|
1876 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
|
1877 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1878 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1879 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1880 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1881 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1882 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
|
1883 return -1; |
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 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
|
1886 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1887 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1888 |
0 | 1889 |
1890 /* Note: Behaves, almost like SDL_mixer, but keep in mind | |
1891 * that there is no "music" channel anymore, so 0 | |
1892 * will remove everything. (Note, I no longer allow 0 | |
1893 * so it gets set to the default number.) | |
1894 * Also, callbacks for deleted channels will not be called. | |
1895 * I really need to do error checking, for realloc and | |
1896 * GenSources, but reversing the damage is too painful | |
1897 * for me to think about at the moment, so it's not in here. | |
1898 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1899 static ALint Internal_AllocateChannels(ALint numchans) |
0 | 1900 { |
1901 ALenum error; | |
1902 int i; | |
1903 /* Return info */ | |
1904 if(numchans < 0) | |
1905 { | |
1906 return Number_of_Channels_global; | |
1907 } | |
1908 if(0 == numchans) | |
1909 { | |
1910 numchans = ALMIXER_DEFAULT_NUM_CHANNELS; | |
1911 } | |
1912 /* No change */ | |
1913 if(numchans == Number_of_Channels_global) | |
1914 { | |
1915 return Number_of_Channels_global; | |
1916 } | |
1917 /* We need to increase the number of channels */ | |
1918 if(numchans > Number_of_Channels_global) | |
1919 { | |
1920 /* Not sure how safe this is, but SDL_mixer does it | |
1921 * the same way */ | |
1922 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1923 | |
1924 /* Allocate memory for the list of sources that map to the channels */ | |
1925 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
1926 | |
1927 for(i=Number_of_Channels_global; i<numchans; i++) | |
1928 { | |
1929 Init_Channel(i); | |
1930 /* Generate a new source and associate it with the channel */ | |
1931 alGenSources(1, &ALmixer_Channel_List[i].alsource); | |
1932 if((error = alGetError()) != AL_NO_ERROR) | |
1933 { | |
1934 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
|
1935 alGetString(error)); |
0 | 1936 } |
1937 /* Copy the source so the SourceMap has it too */ | |
1938 Source_Map_List[i].source = ALmixer_Channel_List[i].alsource; | |
1939 Source_Map_List[i].channel = i; | |
1940 /* Clean the channel because there are some things that need to | |
1941 * be done that can't happen until the source is set | |
1942 */ | |
1943 Clean_Channel(i); | |
1944 } | |
1945 | |
1946 /* The Source_Map_List must be sorted by source for binary searches | |
1947 */ | |
1948 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
1949 | |
1950 Number_of_Channels_global = numchans; | |
1951 return numchans; | |
1952 } | |
1953 /* Need to remove channels. This might be dangerous */ | |
1954 if(numchans < Number_of_Channels_global) | |
1955 { | |
1956 for(i=numchans; i<Number_of_Channels_global; i++) | |
1957 { | |
1958 /* Halt the channel */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1959 Internal_HaltChannel(i, AL_FALSE); |
0 | 1960 |
1961 /* Delete source associated with the channel */ | |
1962 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
1963 if((error = alGetError()) != AL_NO_ERROR) | |
1964 { | |
1965 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
|
1966 alGetString(error)); |
0 | 1967 } |
1968 } | |
1969 | |
1970 | |
1971 /* Not sure how safe this is, but SDL_mixer does it | |
1972 * the same way */ | |
1973 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1974 | |
1975 /* The tricky part is that we must remove the entries | |
1976 * in the source map that correspond to the deleted channels. | |
1977 * We'll resort the map by channels so we can pick them off | |
1978 * in order. | |
1979 */ | |
1980 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map_by_channel); | |
1981 | |
1982 /* Deallocate memory for the list of sources that map to the channels */ | |
1983 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
1984 | |
1985 /* Now resort the map by source and the correct num of chans */ | |
1986 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
1987 | |
1988 /* Reset the number of channels */ | |
1989 Number_of_Channels_global = numchans; | |
1990 return numchans; | |
1991 } | |
1992 /* Shouldn't ever reach here */ | |
1993 return -1; | |
1994 | |
1995 } | |
1996 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1997 static ALint Internal_ReserveChannels(ALint num) |
0 | 1998 { |
1999 /* Can't reserve more than the max num of channels */ | |
2000 /* Actually, I'll allow it for people who just want to | |
2001 * set the value really high to effectively disable | |
2002 * auto-assignment | |
2003 */ | |
2004 | |
2005 /* Return the current number of reserved channels */ | |
2006 if(num < 0) | |
2007 { | |
2008 return Number_of_Reserve_Channels_global; | |
2009 } | |
2010 Number_of_Reserve_Channels_global = num; | |
2011 return Number_of_Reserve_Channels_global; | |
2012 } | |
2013 | |
2014 | |
2015 /* This will rewind the SDL_Sound sample for streamed | |
2016 * samples and start buffering up the data for the next | |
2017 * playback. This may require samples to be halted | |
2018 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2019 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
|
2020 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2021 ALint retval = 0; |
0 | 2022 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2023 ALint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2024 ALint i; |
0 | 2025 */ |
2026 if(NULL == data) | |
2027 { | |
2028 ALmixer_SetError("Cannot rewind because data is NULL\n"); | |
2029 return -1; | |
2030 } | |
2031 | |
2032 | |
2033 /* Might have to require Halt */ | |
2034 /* Okay, we assume Halt or natural stop has already | |
2035 * cleared the data buffers | |
2036 */ | |
2037 if(data->in_use) | |
2038 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2039 /* |
0 | 2040 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
|
2041 */ |
0 | 2042 /* |
2043 ALmixer_SetError("Data is in use. Cannot rewind unless all sources using the data are halted\n"); | |
2044 return -1; | |
2045 */ | |
2046 } | |
2047 | |
2048 | |
2049 /* Because Seek can alter things even in predecoded data, | |
2050 * decoded data must also be rewound | |
2051 */ | |
2052 if(data->decoded_all) | |
2053 { | |
2054 data->eof = 0; | |
2055 | |
2056 #if 0 | |
2057 #if defined(DISABLE_PREDECODED_SEEK) | |
2058 /* Since we can't seek predecoded stuff, it should be rewound */ | |
2059 return 0; | |
2060 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
2061 /* This case is if the Sound_Sample has been deleted. | |
2062 * It assumes the data is already at the beginning. | |
2063 */ | |
2064 if(NULL == data->sample) | |
2065 { | |
2066 return 0; | |
2067 } | |
2068 /* Else, the sample has already been reallocated, | |
2069 * and we can fall to normal behavior | |
2070 */ | |
2071 #endif | |
2072 #endif | |
2073 /* If access_data, was enabled, the sound sample | |
2074 * still exists and we can do stuff. | |
2075 * If it's NULL, we can't do anything, but | |
2076 * it should already be "rewound". | |
2077 */ | |
2078 if(NULL == data->sample) | |
2079 { | |
2080 return 0; | |
2081 } | |
2082 /* Else, the sample has already been reallocated, | |
2083 * and we can fall to normal behavior | |
2084 */ | |
2085 | |
2086 Set_Predecoded_Seek_Position(data, 0); | |
2087 /* | |
2088 return data->total_bytes; | |
2089 */ | |
2090 return 0; | |
2091 } | |
2092 | |
2093 /* Remaining stuff for streamed data */ | |
2094 | |
2095 data->eof = 0; | |
2096 retval = Sound_Rewind(data->sample); | |
2097 if(0 == retval) | |
2098 { | |
2099 ALmixer_SetError( Sound_GetError() ); | |
2100 return -1; | |
2101 } | |
2102 #if 0 | |
2103 /* Clear error */ | |
2104 alGetError(); | |
2105 for(i=0; i<data->num_buffers; i++) | |
2106 { | |
2107 bytes_returned = GetMoreData(data, data->buffer[i]); | |
2108 if(-1 == bytes_returned) | |
2109 { | |
2110 return -1; | |
2111 } | |
2112 else if(0 == bytes_returned) | |
2113 { | |
2114 return -1; | |
2115 } | |
2116 retval += bytes_returned; | |
2117 | |
2118 } | |
2119 #endif | |
2120 | |
2121 | |
2122 | |
2123 return retval; | |
2124 } | |
2125 | |
2126 | |
2127 | |
2128 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2129 static ALint Internal_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2130 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2131 ALint retval = 0; |
0 | 2132 ALenum error; |
2133 ALint state; | |
2134 | |
2135 if(channel >= Number_of_Channels_global) | |
2136 { | |
2137 ALmixer_SetError("Cannot rewind channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2138 return -1; | |
2139 } | |
2140 | |
2141 if((error = alGetError()) != AL_NO_ERROR) | |
2142 { | |
2143 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
|
2144 alGetString(error)); |
0 | 2145 } |
2146 /* Clear error */ | |
2147 alGetError(); | |
2148 | |
2149 /* If the user specified a specific channel */ | |
2150 if(channel >= 0) | |
2151 { | |
2152 /* only need to process channel if in use */ | |
2153 if(ALmixer_Channel_List[channel].channel_in_use) | |
2154 { | |
2155 | |
2156 /* What should I do? Do I just rewind the channel | |
2157 * or also rewind the data? Since the data is | |
2158 * shared, let's make it the user's responsibility | |
2159 * to rewind the data. | |
2160 */ | |
2161 if(ALmixer_Channel_List[channel].almixer_data->decoded_all) | |
2162 { | |
2163 alGetSourcei( | |
2164 ALmixer_Channel_List[channel].alsource, | |
2165 AL_SOURCE_STATE, &state | |
2166 ); | |
2167 if((error = alGetError()) != AL_NO_ERROR) | |
2168 { | |
2169 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
|
2170 alGetString(error)); |
0 | 2171 } |
2172 alSourceRewind(ALmixer_Channel_List[channel].alsource); | |
2173 if((error = alGetError()) != AL_NO_ERROR) | |
2174 { | |
2175 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2176 alGetString(error) ); |
0 | 2177 retval = -1; |
2178 } | |
2179 /* Need to resume playback if it was originally playing */ | |
2180 if(AL_PLAYING == state) | |
2181 { | |
2182 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2183 if((error = alGetError()) != AL_NO_ERROR) | |
2184 { | |
2185 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2186 alGetString(error) ); |
0 | 2187 retval = -1; |
2188 } | |
2189 } | |
2190 else if(AL_PAUSED == state) | |
2191 { | |
2192 /* HACK: The problem is that when paused, after | |
2193 * the Rewind, I can't get it off the INITIAL | |
2194 * state without restarting | |
2195 */ | |
2196 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2197 if((error = alGetError()) != AL_NO_ERROR) | |
2198 { | |
2199 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
|
2200 alGetString(error)); |
0 | 2201 } |
2202 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2203 if((error = alGetError()) != AL_NO_ERROR) | |
2204 { | |
2205 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2206 alGetString(error) ); |
0 | 2207 retval = -1; |
2208 } | |
2209 } | |
2210 } | |
2211 else | |
2212 { | |
2213 /* Streamed data is different. Rewinding the channel | |
2214 * does no good. Rewinding the data will have an | |
2215 * effect, but it will be lagged based on how | |
2216 * much data is queued. Recommend users call Halt | |
2217 * before rewind if they want immediate results. | |
2218 */ | |
2219 retval = Internal_RewindData(ALmixer_Channel_List[channel].almixer_data); | |
2220 } | |
2221 } | |
2222 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2223 /* The user wants to rewind all channels */ |
0 | 2224 else |
2225 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2226 ALint i; |
0 | 2227 for(i=0; i<Number_of_Channels_global; i++) |
2228 { | |
2229 /* only need to process channel if in use */ | |
2230 if(ALmixer_Channel_List[i].channel_in_use) | |
2231 { | |
2232 /* What should I do? Do I just rewind the channel | |
2233 * or also rewind the data? Since the data is | |
2234 * shared, let's make it the user's responsibility | |
2235 * to rewind the data. | |
2236 */ | |
2237 if(ALmixer_Channel_List[i].almixer_data->decoded_all) | |
2238 { | |
2239 alGetSourcei( | |
2240 ALmixer_Channel_List[i].alsource, | |
2241 AL_SOURCE_STATE, &state | |
2242 ); | |
2243 if((error = alGetError()) != AL_NO_ERROR) | |
2244 { | |
2245 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
|
2246 alGetString(error)); |
0 | 2247 } |
2248 alSourceRewind(ALmixer_Channel_List[i].alsource); | |
2249 if((error = alGetError()) != AL_NO_ERROR) | |
2250 { | |
2251 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2252 alGetString(error) ); |
0 | 2253 retval = -1; |
2254 } | |
2255 /* Need to resume playback if it was originally playing */ | |
2256 if(AL_PLAYING == state) | |
2257 { | |
2258 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2259 if((error = alGetError()) != AL_NO_ERROR) | |
2260 { | |
2261 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2262 alGetString(error) ); |
0 | 2263 retval = -1; |
2264 } | |
2265 } | |
2266 else if(AL_PAUSED == state) | |
2267 { | |
2268 /* HACK: The problem is that when paused, after | |
2269 * the Rewind, I can't get it off the INITIAL | |
2270 * state without restarting | |
2271 */ | |
2272 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2273 if((error = alGetError()) != AL_NO_ERROR) | |
2274 { | |
2275 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
|
2276 alGetString(error)); |
0 | 2277 } |
2278 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2279 if((error = alGetError()) != AL_NO_ERROR) | |
2280 { | |
2281 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2282 alGetString(error) ); |
0 | 2283 retval = -1; |
2284 } | |
2285 } | |
2286 } | |
2287 else | |
2288 { | |
2289 /* Streamed data is different. Rewinding the channel | |
2290 * does no good. Rewinding the data will have an | |
2291 * effect, but it will be lagged based on how | |
2292 * much data is queued. Recommend users call Halt | |
2293 * before rewind if they want immediate results. | |
2294 */ | |
2295 retval = Internal_RewindData(ALmixer_Channel_List[i].almixer_data); | |
2296 } | |
2297 } | |
2298 } | |
2299 } | |
2300 return retval; | |
2301 } | |
2302 | |
2303 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2304 static ALint Internal_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2305 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2306 ALint channel; |
0 | 2307 if(0 == source) |
2308 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2309 return Internal_RewindChannel(-1) + 1; |
0 | 2310 } |
2311 | |
2312 channel = Internal_GetChannel(source); | |
2313 if(-1 == channel) | |
2314 { | |
2315 ALmixer_SetError("Cannot rewind source: %s", ALmixer_GetError()); | |
2316 return 0; | |
2317 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2318 return Internal_RewindChannel(channel) + 1; |
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 |
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 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
|
2326 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2327 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2328 int ret_flag = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2329 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2330 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2331 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
|
2332 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2333 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2334 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2335 /* 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
|
2336 * 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
|
2337 * 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
|
2338 * 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
|
2339 * 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
|
2340 * to prevent sharing |
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(0 == data->decoded_all) |
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 if(data->in_use) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2345 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2346 ALmixer_SetError("Can't play 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
|
2347 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2348 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2349 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2350 /* 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
|
2351 * This mainly affects streamed files, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2352 * so the check is placed here |
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(data->eof) |
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 if( -1 == Internal_RewindData(data) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2357 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2358 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
|
2359 return -1; |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2362 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2363 /* 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
|
2364 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2365 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2366 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2367 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
|
2368 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2369 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
|
2370 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2371 channel = i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2372 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2373 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2374 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2375 /* 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
|
2376 if(i == Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2377 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2378 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
|
2379 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2380 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2381 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2382 /* 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
|
2383 * out of bounds or in use */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2384 else |
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 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2387 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2388 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
|
2389 return -1; |
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 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
|
2392 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2393 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
|
2394 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2395 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2396 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2397 /* 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
|
2398 if(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 loops = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2401 } |
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 /* 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
|
2404 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2405 /* 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
|
2406 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
|
2407 data->in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2408 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2409 /* 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
|
2410 * (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
|
2411 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2412 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
|
2413 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
|
2414 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
|
2415 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2416 /* 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
|
2417 if(ticks < 0) |
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 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
|
2420 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2421 else |
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 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
|
2424 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2425 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2426 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2427 ALmixer_Channel_List[channel].halted = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2428 ALmixer_Channel_List[channel].paused = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2429 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2430 /* 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
|
2431 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2432 if( (-1 == loops) && (data->decoded_all) ) |
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 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
|
2435 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2436 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2437 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2438 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
|
2439 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2440 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2441 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2442 fprintf(stderr, "13Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2443 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2444 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2445 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2446 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2447 /* Because of the corner case, predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2448 * 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
|
2449 * Streams do not have this problem |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2450 * 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
|
2451 * avoid the conflict. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2452 * 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
|
2453 * Since streams, cannot share, only predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2454 * files are affected |
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 if(data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2457 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2458 /* 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
|
2459 * 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
|
2460 * 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
|
2461 * must be +1 |
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 if(-1 == loops) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2464 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2465 /* -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
|
2466 * to add +1 to it */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2467 ALmixer_Channel_List[channel].loops = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2468 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
|
2469 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2470 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2471 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2472 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
|
2473 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
|
2474 } |
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2477 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2478 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2479 /* 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
|
2480 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
|
2481 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2482 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2483 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2484 /* 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
|
2485 /* 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
|
2486 * 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
|
2487 * 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
|
2488 * 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
|
2489 * 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
|
2490 * 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
|
2491 * easier to maintain. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2492 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2493 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2494 /* Clear the error flag */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2495 alGetError(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2496 if(data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2497 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2498 /* Bind the data to the source */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2499 alSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2500 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2501 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2502 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2503 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2504 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2505 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
|
2506 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2507 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2508 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2509 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2510 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2511 /* 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
|
2512 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
|
2513 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2514 else |
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 /* 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
|
2517 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2518 ALuint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2519 ALuint j; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2520 data->num_buffers_in_use=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2521 /****** MODIFICATION must go here *********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2522 /* 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
|
2523 * 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
|
2524 * 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
|
2525 * 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
|
2526 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2527 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2528 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2529 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2530 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2531 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2532 /* No data or error */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2533 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
|
2534 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2535 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2536 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2537 /* 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
|
2538 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2539 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2540 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2541 /* 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
|
2542 * 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
|
2543 * before the last buffer is filled. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2544 * 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
|
2545 * 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
|
2546 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2547 |
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 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
|
2550 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2551 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
|
2552 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2553 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2554 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
|
2555 fprintf(stderr, ">>>>>>>>>>>>>>>>>>HACK for GetMoreData2\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2556 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2557 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2558 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2559 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2560 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2561 * 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
|
2562 * 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
|
2563 * 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
|
2564 * 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
|
2565 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2566 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2567 if(bytes_returned < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2568 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2569 /* Error found */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2570 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
|
2571 /* 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
|
2572 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2573 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2574 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2575 else if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2576 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2577 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2578 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2579 /* No more data to buffer */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2580 /* Check for loops */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2581 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
|
2582 { |
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 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
|
2585 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2586 if(0 == Sound_Rewind(data->sample)) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2587 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2588 fprintf(stderr, "error in rewind\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2589 ALmixer_SetError( Sound_GetError() ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2590 ALmixer_Channel_List[channel].loops = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2591 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2592 /* 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
|
2593 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2594 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2595 /* 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
|
2596 data->eof = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2597 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
|
2598 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2599 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 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
|
2602 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2603 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2604 /* 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
|
2605 * 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
|
2606 * into an infinite loop |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2607 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2608 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2609 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2610 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2611 if(bytes_returned <= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2612 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2613 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
|
2614 /* 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
|
2615 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2616 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2617 } |
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2620 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2621 /* 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
|
2622 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2623 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2624 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2625 /* 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
|
2626 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2627 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2628 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2629 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
|
2630 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2631 data->num_buffers_in_use); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2632 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2633 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2634 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2635 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2636 data->num_buffers_in_use, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2637 data->buffer); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2638 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2639 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2640 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
|
2641 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2642 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2643 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2644 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2645 /* 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
|
2646 * 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
|
2647 * 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
|
2648 * 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
|
2649 * "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
|
2650 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2651 if(data->circular_buffer_queue != NULL) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2652 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2653 ALuint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2654 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2655 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
|
2656 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2657 // fprintf(stderr, "56c: CircularQueue_PushBack.\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2658 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
|
2659 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2660 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2661 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
|
2662 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
|
2663 } |
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2666 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2667 fprintf(stderr, "Queue in PlayTimed\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2668 CircularQueueUnsignedInt_Print(data->circular_buffer_queue); |
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 |
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 /****** END **********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2676 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2677 /* 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
|
2678 * so now we can play |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2679 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2680 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2681 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2682 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2683 ALmixer_SetError("Play failed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2684 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2685 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2686 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2687 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2688 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2689 /* 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
|
2690 Is_Playing_global++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2691 if(-1 == ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2692 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2693 fprintf(stderr, "BACKDOOR ERROR >>>>>>>>>>>>>>>>>>\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2694 return -1; |
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 return channel; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2699 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2700 /* 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
|
2701 * 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
|
2702 * 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
|
2703 * PlayChannelTimed() function call. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2704 * 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
|
2705 * 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
|
2706 * 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
|
2707 * 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
|
2708 * 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
|
2709 * 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
|
2710 * 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
|
2711 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2712 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
|
2713 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2714 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2715 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2716 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2717 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2718 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
|
2719 if(-1 == retval) |
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 return 0; |
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 else |
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 return Internal_GetSource(retval); |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2728 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2729 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2730 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2731 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2732 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
|
2733 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2734 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2735 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
|
2736 if(-1 == retval) |
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 return 0; |
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 else |
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 return source; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2743 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2744 /* make compiler happy */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2745 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2746 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2747 |
0 | 2748 |
2749 | |
2750 | |
2751 /* Returns the channel or number of channels actually paused */ | |
2752 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2753 static ALint Internal_PauseChannel(ALint channel) |
0 | 2754 { |
2755 ALenum error; | |
2756 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2757 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2758 ALint counter = 0; |
0 | 2759 |
2760 if(channel >= Number_of_Channels_global) | |
2761 { | |
2762 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2763 return -1; | |
2764 } | |
2765 | |
2766 if((error = alGetError()) != AL_NO_ERROR) | |
2767 { | |
2768 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
|
2769 alGetString(error)); |
0 | 2770 } |
2771 /* Clear error */ | |
2772 alGetError(); | |
2773 | |
2774 /* If the user specified a specific channel */ | |
2775 if(channel >= 0) | |
2776 { | |
2777 /* only need to process channel if in use */ | |
2778 if(ALmixer_Channel_List[channel].channel_in_use) | |
2779 { | |
2780 /* We don't want to repause if already | |
2781 * paused because the fadeout/expire | |
2782 * timing will get messed up | |
2783 */ | |
2784 alGetSourcei( | |
2785 ALmixer_Channel_List[channel].alsource, | |
2786 AL_SOURCE_STATE, &state | |
2787 ); | |
2788 if((error = alGetError()) != AL_NO_ERROR) | |
2789 { | |
2790 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
|
2791 alGetString(error)); |
0 | 2792 } |
2793 if(AL_PLAYING == state) | |
2794 { | |
2795 /* Count the actual number of channels being paused */ | |
2796 counter++; | |
2797 | |
2798 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2799 if((error = alGetError()) != AL_NO_ERROR) | |
2800 { | |
2801 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2802 alGetString(error) ); |
0 | 2803 retval = -1; |
2804 } | |
2805 /* We need to pause the expire time count down */ | |
2806 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
2807 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2808 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2809 ALuint diff_time; |
0 | 2810 diff_time = current_time - |
2811 ALmixer_Channel_List[channel].start_time; | |
2812 /* When we unpause, we will want to reset | |
2813 * the start time so we can continue | |
2814 * to base calculations off GetTicks(). | |
2815 * This means we need to subtract the amount | |
2816 * of time already used up from expire_ticks. | |
2817 */ | |
2818 ALmixer_Channel_List[channel].expire_ticks = | |
2819 ALmixer_Channel_List[channel].expire_ticks - | |
2820 diff_time; | |
2821 /* Because -1 is a special value, we can't | |
2822 * allow the time to go negative | |
2823 */ | |
2824 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2825 { | |
2826 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2827 } | |
2828 } | |
2829 /* Do the same as expire time for fading */ | |
2830 if(ALmixer_Channel_List[channel].fade_enabled) | |
2831 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2832 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2833 ALuint diff_time; |
0 | 2834 diff_time = current_time - |
2835 ALmixer_Channel_List[channel].fade_start_time; | |
2836 /* When we unpause, we will want to reset | |
2837 * the start time so we can continue | |
2838 * to base calculations off GetTicks(). | |
2839 * This means we need to subtract the amount | |
2840 * of time already used up from expire_ticks. | |
2841 */ | |
2842 ALmixer_Channel_List[channel].fade_expire_ticks = | |
2843 ALmixer_Channel_List[channel].fade_expire_ticks - | |
2844 diff_time; | |
2845 /* Don't allow the time to go negative */ | |
2846 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2847 { | |
2848 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2849 } | |
2850 } /* End fade check */ | |
2851 } /* End if PLAYING */ | |
2852 } /* End If in use */ | |
2853 } /* End specific channel */ | |
2854 /* The user wants to halt all channels */ | |
2855 else | |
2856 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2857 ALint i; |
0 | 2858 for(i=0; i<Number_of_Channels_global; i++) |
2859 { | |
2860 /* only need to process channel if in use */ | |
2861 if(ALmixer_Channel_List[i].channel_in_use) | |
2862 { | |
2863 /* We don't want to repause if already | |
2864 * paused because the fadeout/expire | |
2865 * timing will get messed up | |
2866 */ | |
2867 alGetSourcei( | |
2868 ALmixer_Channel_List[i].alsource, | |
2869 AL_SOURCE_STATE, &state | |
2870 ); | |
2871 if((error = alGetError()) != AL_NO_ERROR) | |
2872 { | |
2873 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
|
2874 alGetString(error)); |
0 | 2875 } |
2876 if(AL_PLAYING == state) | |
2877 { | |
2878 /* Count the actual number of channels being paused */ | |
2879 counter++; | |
2880 | |
2881 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2882 if((error = alGetError()) != AL_NO_ERROR) | |
2883 { | |
2884 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2885 alGetString(error) ); |
0 | 2886 retval = -1; |
2887 } | |
2888 /* We need to pause the expire time count down */ | |
2889 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
2890 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2891 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2892 ALuint diff_time; |
0 | 2893 diff_time = current_time - |
2894 ALmixer_Channel_List[i].start_time; | |
2895 /* When we unpause, we will want to reset | |
2896 * the start time so we can continue | |
2897 * to base calculations off GetTicks(). | |
2898 * This means we need to subtract the amount | |
2899 * of time already used up from expire_ticks. | |
2900 */ | |
2901 ALmixer_Channel_List[i].expire_ticks = | |
2902 ALmixer_Channel_List[i].expire_ticks - | |
2903 diff_time; | |
2904 /* Because -1 is a special value, we can't | |
2905 * allow the time to go negative | |
2906 */ | |
2907 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2908 { | |
2909 ALmixer_Channel_List[i].expire_ticks = 0; | |
2910 } | |
2911 } | |
2912 /* Do the same as expire time for fading */ | |
2913 if(ALmixer_Channel_List[i].fade_enabled) | |
2914 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2915 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2916 ALuint diff_time; |
0 | 2917 diff_time = current_time - |
2918 ALmixer_Channel_List[i].fade_start_time; | |
2919 /* When we unpause, we will want to reset | |
2920 * the start time so we can continue | |
2921 * to base calculations off GetTicks(). | |
2922 * This means we need to subtract the amount | |
2923 * of time already used up from expire_ticks. | |
2924 */ | |
2925 ALmixer_Channel_List[i].fade_expire_ticks = | |
2926 ALmixer_Channel_List[i].fade_expire_ticks - | |
2927 diff_time; | |
2928 /* Don't allow the time to go negative */ | |
2929 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2930 { | |
2931 ALmixer_Channel_List[i].expire_ticks = 0; | |
2932 } | |
2933 } /* End fade check */ | |
2934 } /* End if PLAYING */ | |
2935 } /* End channel in use */ | |
2936 } /* End for-loop */ | |
2937 } | |
2938 if(-1 == retval) | |
2939 { | |
2940 return -1; | |
2941 } | |
2942 return counter; | |
2943 } | |
2944 | |
2945 /* 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
|
2946 static ALint Internal_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2947 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2948 ALint channel; |
0 | 2949 if(0 == source) |
2950 { | |
2951 return Internal_PauseChannel(-1); | |
2952 } | |
2953 | |
2954 channel = Internal_GetChannel(source); | |
2955 if(-1 == channel) | |
2956 { | |
2957 ALmixer_SetError("Cannot pause source: %s", ALmixer_GetError()); | |
2958 return -1; | |
2959 } | |
2960 return Internal_PauseChannel(channel); | |
2961 } | |
2962 | |
2963 | |
2964 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2965 static ALint Internal_ResumeChannel(ALint channel) |
0 | 2966 { |
2967 ALint state; | |
2968 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2969 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2970 ALint counter = 0; |
0 | 2971 |
2972 if(channel >= Number_of_Channels_global) | |
2973 { | |
2974 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2975 return -1; | |
2976 } | |
2977 | |
2978 if((error = alGetError()) != AL_NO_ERROR) | |
2979 { | |
2980 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
|
2981 alGetString(error)); |
0 | 2982 } |
2983 /* Clear error */ | |
2984 alGetError(); | |
2985 | |
2986 /* If the user specified a specific channel */ | |
2987 if(channel >= 0) | |
2988 { | |
2989 /* only need to process channel if in use */ | |
2990 if(ALmixer_Channel_List[channel].channel_in_use) | |
2991 { | |
2992 alGetSourcei( | |
2993 ALmixer_Channel_List[channel].alsource, | |
2994 AL_SOURCE_STATE, &state | |
2995 ); | |
2996 if((error = alGetError()) != AL_NO_ERROR) | |
2997 { | |
2998 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
|
2999 alGetString(error)); |
0 | 3000 } |
3001 if(AL_PAUSED == state) | |
3002 { | |
3003 /* Count the actual number of channels resumed */ | |
3004 counter++; | |
3005 | |
3006 /* We need to resume the expire time count down */ | |
3007 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
3008 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3009 ALmixer_Channel_List[channel].start_time = ALmixer_GetTicks(); |
0 | 3010 } |
3011 /* Do the same as expire time for fading */ | |
3012 if(ALmixer_Channel_List[channel].fade_enabled) | |
3013 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3014 ALmixer_Channel_List[channel].fade_start_time = ALmixer_GetTicks(); |
0 | 3015 } |
3016 | |
3017 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
3018 if((error = alGetError()) != AL_NO_ERROR) | |
3019 { | |
3020 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3021 alGetString(error) ); |
0 | 3022 retval = -1; |
3023 } | |
3024 } | |
3025 } | |
3026 } | |
3027 /* The user wants to halt all channels */ | |
3028 else | |
3029 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3030 ALint i; |
0 | 3031 for(i=0; i<Number_of_Channels_global; i++) |
3032 { | |
3033 /* only need to process channel if in use */ | |
3034 if(ALmixer_Channel_List[i].channel_in_use) | |
3035 { | |
3036 alGetSourcei( | |
3037 ALmixer_Channel_List[i].alsource, | |
3038 AL_SOURCE_STATE, &state | |
3039 ); | |
3040 if((error = alGetError()) != AL_NO_ERROR) | |
3041 { | |
3042 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
|
3043 alGetString(error)); |
0 | 3044 } |
3045 if(AL_PAUSED == state) | |
3046 { | |
3047 /* Count the actual number of channels resumed */ | |
3048 counter++; | |
3049 | |
3050 /* We need to resume the expire time count down */ | |
3051 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
3052 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3053 ALmixer_Channel_List[i].start_time = ALmixer_GetTicks(); |
0 | 3054 } |
3055 /* Do the same as expire time for fading */ | |
3056 if(ALmixer_Channel_List[i].fade_enabled) | |
3057 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3058 ALmixer_Channel_List[i].fade_start_time = ALmixer_GetTicks(); |
0 | 3059 } |
3060 | |
3061 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
3062 if((error = alGetError()) != AL_NO_ERROR) | |
3063 { | |
3064 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3065 alGetString(error) ); |
0 | 3066 retval = -1; |
3067 } | |
3068 } | |
3069 } | |
3070 } | |
3071 } | |
3072 if(-1 == retval) | |
3073 { | |
3074 return -1; | |
3075 } | |
3076 return counter; | |
3077 } | |
3078 | |
3079 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3080 static ALint Internal_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3081 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3082 ALint channel; |
0 | 3083 if(0 == source) |
3084 { | |
3085 return Internal_ResumeChannel(-1); | |
3086 } | |
3087 | |
3088 channel = Internal_GetChannel(source); | |
3089 if(-1 == channel) | |
3090 { | |
3091 ALmixer_SetError("Cannot resume source: %s", ALmixer_GetError()); | |
3092 return -1; | |
3093 } | |
3094 return Internal_ResumeChannel(channel); | |
3095 } | |
3096 | |
3097 | |
3098 /* Might consider setting eof to 0 as a "feature" | |
3099 * This will allow seek to end to stay there because | |
3100 * 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
|
3101 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
|
3102 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3103 ALint retval; |
0 | 3104 |
3105 if(NULL == data) | |
3106 { | |
3107 ALmixer_SetError("Cannot Seek because data is NULL"); | |
3108 return -1; | |
3109 } | |
3110 | |
3111 /* Seek for predecoded files involves moving the chunk pointer around */ | |
3112 if(data->decoded_all) | |
3113 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3114 ALuint byte_position; |
0 | 3115 |
3116 /* OpenAL doesn't seem to like it if I change the buffer | |
3117 * while playing (crashes), so I must require that Seek only | |
3118 * be done when the data is not in use. | |
3119 * Since data may be shared among multiple sources, | |
3120 * I can't shut them down myself, so I have to return an error. | |
3121 */ | |
3122 if(data->in_use) | |
3123 { | |
3124 ALmixer_SetError("Cannot seek on predecoded data while instances are playing"); | |
3125 return -1; | |
3126 } | |
3127 #if 0 | |
3128 #if defined(DISABLE_PREDECODED_SEEK) | |
3129 ALmixer_SetError("Seek support for predecoded samples was not compiled in"); | |
3130 return -1; | |
3131 | |
3132 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
3133 /* By default, ALmixer frees the Sound_Sample for predecoded | |
3134 * samples because of the potential memory waste. | |
3135 * However, to seek a sample, we need to have a full | |
3136 * copy of the data around. So the strategy is to | |
3137 * recreate a hackish Sound_Sample to be used for seeking | |
3138 * purposes. If Sound_Sample is NULL, we will reallocate | |
3139 * memory for it and then procede as if everything | |
3140 * was normal. | |
3141 */ | |
3142 if(NULL == data->sample) | |
3143 { | |
3144 if( -1 == Reconstruct_Sound_Sample(data) ) | |
3145 { | |
3146 return -1; | |
3147 } | |
3148 } | |
3149 #endif | |
3150 #endif | |
3151 /* If access_data was set, then we still have the | |
3152 * Sound_Sample and we can move around in the data. | |
3153 * If it was not set, the data has been freed and we | |
3154 * cannot do anything because there is no way to | |
3155 * recover the data because OpenAL won't let us | |
3156 * get access to the buffers | |
3157 */ | |
3158 if(NULL == data->sample) | |
3159 { | |
3160 ALmixer_SetError("Cannot seek because access_data flag was set false when data was initialized"); | |
3161 return -1; | |
3162 } | |
3163 | |
3164 byte_position = Convert_Msec_To_Byte_Pos(&data->sample->desired, msec); | |
3165 return( Set_Predecoded_Seek_Position(data, byte_position) ); | |
3166 } | |
3167 else | |
3168 { | |
3169 /* Reset eof flag?? */ | |
3170 data->eof = 0; | |
3171 retval = Sound_Seek(data->sample, msec); | |
3172 if(0 == retval) | |
3173 { | |
3174 ALmixer_SetError(Sound_GetError()); | |
3175 | |
3176 fprintf(stderr, "Sound seek error: %s\n", ALmixer_GetError()); | |
3177 /* Try rewinding to clean up? */ | |
3178 /* | |
3179 Internal_RewindData(data); | |
3180 */ | |
3181 return -1; | |
3182 } | |
3183 return 0; | |
3184 } | |
3185 | |
3186 return 0; | |
3187 } | |
3188 | |
3189 | |
3190 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3191 static ALint Internal_FadeInChannelTimed(ALint channel, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 3192 { |
3193 ALfloat value; | |
3194 ALenum error; | |
3195 ALfloat original_value; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3196 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3197 ALint retval; |
0 | 3198 |
3199 | |
3200 | |
3201 if(channel >= Number_of_Channels_global) | |
3202 { | |
3203 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); | |
3204 return -1; | |
3205 } | |
3206 /* Let's call PlayChannelTimed to do the job. | |
3207 * There are two catches: | |
3208 * First is that we must set the volumes before the play call(s). | |
3209 * Second is that we must initialize the channel values | |
3210 */ | |
3211 | |
3212 if(channel < 0) | |
3213 { | |
3214 /* This might cause a problem for threads/race conditions. | |
3215 * We need to set the volume on an unknown channel, | |
3216 * so we need to request a channel first. Remember | |
3217 * that requesting a channel doesn't lock and it | |
3218 * could be surrendered to somebody else before we claim it. | |
3219 */ | |
3220 channel = Internal_GetChannel(0); | |
3221 if(-1 == channel) | |
3222 { | |
3223 return -1; | |
3224 } | |
3225 } | |
3226 else if(ALmixer_Channel_List[channel].channel_in_use) | |
3227 { | |
3228 ALmixer_SetError("Channel %d is already in use", channel); | |
3229 return -1; | |
3230 } | |
3231 | |
3232 | |
3233 /* Get the original volume in case of a problem */ | |
3234 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
|
3235 AL_GAIN, &original_value); |
0 | 3236 |
3237 if((error = alGetError()) != AL_NO_ERROR) | |
3238 { | |
3239 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
|
3240 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3241 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3242 ALmixer_Channel_List[channel].fade_end_volume = original_value; |
0 | 3243 |
3244 /* Get the Min volume */ | |
3245 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3246 AL_MIN_GAIN, &value); | |
3247 if((error = alGetError()) != AL_NO_ERROR) | |
3248 { | |
3249 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
|
3250 alGetString(error)); |
0 | 3251 } |
3252 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3253 | |
3254 /* Set the actual volume */ | |
3255 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
|
3256 AL_GAIN, value); |
0 | 3257 if((error = alGetError()) != AL_NO_ERROR) |
3258 { | |
3259 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
|
3260 alGetString(error)); |
0 | 3261 } |
3262 | |
3263 | |
3264 /* Now call PlayChannelTimed */ | |
3265 retval = Internal_PlayChannelTimed(channel, data, loops, expire_ticks); | |
3266 if(-1 == retval) | |
3267 { | |
3268 /* Chance of failure is actually pretty high since | |
3269 * a channel might already be in use or streamed | |
3270 * data can be shared | |
3271 */ | |
3272 /* Restore the original value to avoid accidental | |
3273 * distruption of playback | |
3274 */ | |
3275 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
|
3276 AL_GAIN, original_value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3277 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3278 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3279 fprintf(stderr, "38Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3280 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3281 } |
0 | 3282 return retval; |
3283 } | |
3284 | |
3285 /* We can't accept 0 as a value because of div-by-zero. | |
3286 * If zero, just call PlayChannelTimed at normal | |
3287 * volume | |
3288 */ | |
3289 if(0 == fade_ticks) | |
3290 { | |
3291 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
|
3292 AL_GAIN, |
0 | 3293 ALmixer_Channel_List[channel].fade_end_volume |
3294 ); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3295 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3296 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3297 fprintf(stderr, "39Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3298 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3299 } |
0 | 3300 |
3301 return retval; | |
3302 } | |
3303 | |
3304 /* Enable fading effects via the flag */ | |
3305 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3306 /* Set fade start time */ | |
3307 ALmixer_Channel_List[channel].fade_start_time | |
3308 = ALmixer_Channel_List[channel].start_time; | |
3309 /* Set the fade expire ticks */ | |
3310 ALmixer_Channel_List[channel].fade_expire_ticks = fade_ticks; | |
3311 | |
3312 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3313 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / fade_ticks; | |
3314 | |
3315 return retval; | |
3316 | |
3317 } | |
3318 | |
3319 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3320 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
|
3321 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3322 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3323 ALint retval; |
0 | 3324 if(0 == source) |
3325 { | |
3326 retval = Internal_FadeInChannelTimed(-1, data, loops, fade_ticks, expire_ticks); | |
3327 if(-1 == retval) | |
3328 { | |
3329 return 0; | |
3330 } | |
3331 else | |
3332 { | |
3333 return Internal_GetSource(retval); | |
3334 } | |
3335 } | |
3336 | |
3337 channel = Internal_GetChannel(source); | |
3338 if(-1 == channel) | |
3339 { | |
3340 ALmixer_SetError("Cannot FadeIn source: %s", ALmixer_GetError()); | |
3341 return 0; | |
3342 } | |
3343 retval = Internal_FadeInChannelTimed(channel, data, loops, fade_ticks, expire_ticks); | |
3344 if(-1 == retval) | |
3345 { | |
3346 return 0; | |
3347 } | |
3348 else | |
3349 { | |
3350 return source; | |
3351 } | |
3352 /* make compiler happy */ | |
3353 return 0; | |
3354 } | |
3355 | |
3356 | |
3357 | |
3358 | |
3359 /* Will fade out currently playing channels. | |
3360 * 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
|
3361 static ALint Internal_FadeOutChannel(ALint channel, ALuint ticks) |
0 | 3362 { |
3363 ALfloat value; | |
3364 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3365 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3366 ALuint counter = 0; |
0 | 3367 |
3368 /* We can't accept 0 as a value because of div-by-zero. | |
3369 * If zero, just call Halt at normal | |
3370 * volume | |
3371 */ | |
3372 if(0 == ticks) | |
3373 { | |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
3374 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 3375 } |
3376 | |
3377 | |
3378 if(channel >= Number_of_Channels_global) | |
3379 { | |
3380 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); | |
3381 return -1; | |
3382 } | |
3383 | |
3384 if(channel >= 0) | |
3385 { | |
3386 if(ALmixer_Channel_List[channel].channel_in_use) | |
3387 { | |
3388 /* Get the current volume */ | |
3389 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
|
3390 AL_GAIN, &value); |
0 | 3391 ALmixer_Channel_List[channel].fade_start_volume = value; |
3392 if((error = alGetError()) != AL_NO_ERROR) | |
3393 { | |
3394 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
|
3395 alGetString(error)); |
0 | 3396 } |
3397 | |
3398 /* Get the Min volume */ | |
3399 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3400 AL_MIN_GAIN, &value); | |
3401 if((error = alGetError()) != AL_NO_ERROR) | |
3402 { | |
3403 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
|
3404 alGetString(error)); |
0 | 3405 } |
3406 ALmixer_Channel_List[channel].fade_end_volume = value; | |
3407 | |
3408 /* Set expire start time */ | |
3409 ALmixer_Channel_List[channel].start_time = current_time; | |
3410 /* Set the expire ticks */ | |
3411 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
3412 /* Set fade start time */ | |
3413 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3414 /* Set the fade expire ticks */ | |
3415 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3416 /* Enable fading effects via the flag */ | |
3417 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3418 | |
3419 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3420 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3421 | |
3422 counter++; | |
3423 } | |
3424 } | |
3425 /* Else need to fade out all channels */ | |
3426 else | |
3427 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3428 ALint i; |
0 | 3429 for(i=0; i<Number_of_Channels_global; i++) |
3430 { | |
3431 if(ALmixer_Channel_List[i].channel_in_use) | |
3432 { | |
3433 /* Get the current volume */ | |
3434 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
|
3435 AL_GAIN, &value); |
0 | 3436 ALmixer_Channel_List[i].fade_start_volume = value; |
3437 if((error = alGetError()) != AL_NO_ERROR) | |
3438 { | |
3439 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
|
3440 alGetString(error)); |
0 | 3441 } |
3442 | |
3443 /* Get the Min volume */ | |
3444 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
3445 AL_MIN_GAIN, &value); | |
3446 if((error = alGetError()) != AL_NO_ERROR) | |
3447 { | |
3448 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
|
3449 alGetString(error)); |
0 | 3450 } |
3451 ALmixer_Channel_List[i].fade_end_volume = value; | |
3452 | |
3453 /* Set expire start time */ | |
3454 ALmixer_Channel_List[i].start_time = current_time; | |
3455 /* Set the expire ticks */ | |
3456 ALmixer_Channel_List[i].expire_ticks = ticks; | |
3457 /* Set fade start time */ | |
3458 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3459 /* Set the fade expire ticks */ | |
3460 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3461 /* Enable fading effects via the flag */ | |
3462 ALmixer_Channel_List[i].fade_enabled = 1; | |
3463 | |
3464 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3465 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3466 | |
3467 counter++; | |
3468 } | |
3469 } /* End for loop */ | |
3470 } | |
3471 return counter; | |
3472 } | |
3473 | |
3474 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3475 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
|
3476 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3477 ALint channel; |
0 | 3478 if(0 == source) |
3479 { | |
3480 return Internal_FadeOutChannel(-1, ticks); | |
3481 } | |
3482 | |
3483 channel = Internal_GetChannel(source); | |
3484 if(-1 == channel) | |
3485 { | |
3486 ALmixer_SetError("Cannot FadeOut source: %s", ALmixer_GetError()); | |
3487 return -1; | |
3488 } | |
3489 return Internal_FadeOutChannel(channel, ticks); | |
3490 } | |
3491 | |
3492 | |
3493 /* Will fade currently playing channels. | |
3494 * It starts at the current volume level and go to target | |
3495 * Only affects channels that are playing | |
3496 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3497 static ALint Internal_FadeChannel(ALint channel, ALuint ticks, ALfloat volume) |
0 | 3498 { |
3499 ALfloat value; | |
3500 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3501 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3502 ALuint counter = 0; |
0 | 3503 |
3504 if(channel >= Number_of_Channels_global) | |
3505 { | |
3506 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); | |
3507 return -1; | |
3508 } | |
3509 | |
3510 if(channel >= 0) | |
3511 { | |
3512 if(volume < ALmixer_Channel_List[channel].min_volume) | |
3513 { | |
3514 volume = ALmixer_Channel_List[channel].min_volume; | |
3515 } | |
3516 else if(volume > ALmixer_Channel_List[channel].max_volume) | |
3517 { | |
3518 volume = ALmixer_Channel_List[channel].max_volume; | |
3519 } | |
3520 | |
3521 if(ALmixer_Channel_List[channel].channel_in_use) | |
3522 { | |
3523 if(ticks > 0) | |
3524 { | |
3525 /* Get the current volume */ | |
3526 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
|
3527 AL_GAIN, &value); |
0 | 3528 if((error = alGetError()) != AL_NO_ERROR) |
3529 { | |
3530 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
|
3531 alGetString(error)); |
0 | 3532 } |
3533 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3534 | |
3535 /* Set the target volume */ | |
3536 ALmixer_Channel_List[channel].fade_end_volume = volume; | |
3537 | |
3538 /* Set fade start time */ | |
3539 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3540 /* Set the fade expire ticks */ | |
3541 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3542 /* Enable fading effects via the flag */ | |
3543 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3544 | |
3545 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3546 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3547 } | |
3548 else | |
3549 { | |
3550 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
|
3551 AL_GAIN, volume); |
0 | 3552 if((error = alGetError()) != AL_NO_ERROR) |
3553 { | |
3554 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
|
3555 alGetString(error)); |
0 | 3556 } |
3557 } | |
3558 counter++; | |
3559 } | |
3560 } | |
3561 /* Else need to fade out all channels */ | |
3562 else | |
3563 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3564 ALint i; |
0 | 3565 for(i=0; i<Number_of_Channels_global; i++) |
3566 { | |
3567 if(volume < ALmixer_Channel_List[i].min_volume) | |
3568 { | |
3569 volume = ALmixer_Channel_List[i].min_volume; | |
3570 } | |
3571 else if(volume > ALmixer_Channel_List[i].max_volume) | |
3572 { | |
3573 volume = ALmixer_Channel_List[i].max_volume; | |
3574 } | |
3575 | |
3576 if(ALmixer_Channel_List[i].channel_in_use) | |
3577 { | |
3578 if(ticks > 0) | |
3579 { | |
3580 /* Get the current volume */ | |
3581 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
|
3582 AL_GAIN, &value); |
0 | 3583 if((error = alGetError()) != AL_NO_ERROR) |
3584 { | |
3585 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
|
3586 alGetString(error)); |
0 | 3587 } |
3588 ALmixer_Channel_List[i].fade_start_volume = value; | |
3589 | |
3590 /* Set target volume */ | |
3591 ALmixer_Channel_List[i].fade_end_volume = volume; | |
3592 | |
3593 /* Set fade start time */ | |
3594 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3595 /* Set the fade expire ticks */ | |
3596 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3597 /* Enable fading effects via the flag */ | |
3598 ALmixer_Channel_List[i].fade_enabled = 1; | |
3599 | |
3600 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3601 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3602 } | |
3603 else | |
3604 { | |
3605 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
|
3606 AL_GAIN, volume); |
0 | 3607 if((error = alGetError()) != AL_NO_ERROR) |
3608 { | |
3609 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
|
3610 alGetString(error)); |
0 | 3611 } |
3612 } | |
3613 counter++; | |
3614 } | |
3615 } /* End for loop */ | |
3616 } | |
3617 return counter; | |
3618 } | |
3619 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3620 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
|
3621 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3622 ALint channel; |
0 | 3623 if(0 == source) |
3624 { | |
3625 return Internal_FadeChannel(-1, ticks, volume); | |
3626 } | |
3627 | |
3628 channel = Internal_GetChannel(source); | |
3629 if(-1 == channel) | |
3630 { | |
3631 ALmixer_SetError("Cannot Fade source: %s", ALmixer_GetError()); | |
3632 return -1; | |
3633 } | |
3634 return Internal_FadeChannel(channel, ticks, volume); | |
3635 } | |
3636 | |
3637 | |
3638 | |
3639 | |
3640 /* Set a volume regardless if it's in use or not. | |
3641 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3642 static ALboolean Internal_SetVolumeChannel(ALint channel, ALfloat volume) |
0 | 3643 { |
3644 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3645 ALboolean retval = AL_TRUE; |
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 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3648 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3649 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
|
3650 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3651 } |
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(channel >= 0) |
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 if(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 volume = 0.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 else if(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 volume = 1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3662 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3663 alSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3664 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3665 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3666 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3667 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3668 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3669 retval = AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3670 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3671 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3672 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3673 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3674 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3675 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
|
3676 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3677 if(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 volume = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3680 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3681 else if(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 volume = 1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3684 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3685 alSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3686 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3687 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3688 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3689 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3690 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3691 retval = AL_FALSE; |
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 } |
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 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3696 } |
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 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
|
3699 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3700 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3701 if(0 == source) |
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 return Internal_SetVolumeChannel(-1, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3704 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3705 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3706 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3707 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3708 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3709 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
|
3710 return AL_FALSE; |
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 return Internal_SetVolumeChannel(channel, volume); |
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 |
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 static ALfloat Internal_GetVolumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3717 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3718 ALfloat value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3719 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3720 ALfloat running_total = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3721 ALfloat retval = 0.0f; |
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 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3724 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3725 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
|
3726 return -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3727 } |
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 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3730 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3731 alGetSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3732 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3733 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3734 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3735 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3736 retval = -1.0f; |
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 else |
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 retval = value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3741 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3742 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3743 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3744 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3745 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3746 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
|
3747 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3748 alGetSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3749 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3750 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3751 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3752 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3753 retval = -1; |
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 else |
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 running_total += value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3758 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3759 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3760 if(0 == Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3761 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3762 ALmixer_SetError("No channels are allocated"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3763 retval = -1.0f; |
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 else |
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 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
|
3768 } |
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 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3771 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3772 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3773 static ALfloat Internal_GetVolumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3774 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3775 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3776 if(0 == source) |
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 return Internal_GetVolumeChannel(-1); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3779 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3780 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3781 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3782 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3783 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3784 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
|
3785 return -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3786 } |
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 return Internal_GetVolumeChannel(channel); |
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 |
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 /* 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
|
3794 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3795 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
|
3796 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3797 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3798 ALboolean retval = AL_TRUE; |
0 | 3799 |
3800 if(channel >= Number_of_Channels_global) | |
3801 { | |
3802 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
|
3803 return AL_FALSE; |
0 | 3804 } |
3805 | |
3806 if(channel >= 0) | |
3807 { | |
3808 if(volume < 0.0f) | |
3809 { | |
3810 volume = 0.0f; | |
3811 } | |
3812 else if(volume > 1.0f) | |
3813 { | |
3814 volume = 1.0f; | |
3815 } | |
3816 ALmixer_Channel_List[channel].max_volume = volume; | |
3817 alSourcef(ALmixer_Channel_List[channel].alsource, | |
3818 AL_MAX_GAIN, volume); | |
3819 if((error = alGetError()) != AL_NO_ERROR) | |
3820 { | |
3821 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3822 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3823 retval = AL_FALSE; |
0 | 3824 } |
3825 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
3826 { | |
3827 ALmixer_Channel_List[channel].min_volume = volume; | |
3828 alSourcef(ALmixer_Channel_List[channel].alsource, | |
3829 AL_MIN_GAIN, volume); | |
3830 if((error = alGetError()) != AL_NO_ERROR) | |
3831 { | |
3832 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3833 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3834 retval = AL_FALSE; |
0 | 3835 } |
3836 } | |
3837 } | |
3838 else | |
3839 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3840 ALint i; |
0 | 3841 for(i=0; i<Number_of_Channels_global; i++) |
3842 { | |
3843 if(volume < 0.0f) | |
3844 { | |
3845 volume = 0.0f; | |
3846 } | |
3847 else if(volume > 1.0f) | |
3848 { | |
3849 volume = 1.0f; | |
3850 } | |
3851 ALmixer_Channel_List[i].max_volume = volume; | |
3852 alSourcef(ALmixer_Channel_List[i].alsource, | |
3853 AL_MAX_GAIN, volume); | |
3854 if((error = alGetError()) != AL_NO_ERROR) | |
3855 { | |
3856 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3857 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3858 retval = AL_FALSE; |
0 | 3859 } |
3860 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
3861 { | |
3862 ALmixer_Channel_List[i].min_volume = volume; | |
3863 alSourcef(ALmixer_Channel_List[i].alsource, | |
3864 AL_MIN_GAIN, volume); | |
3865 if((error = alGetError()) != AL_NO_ERROR) | |
3866 { | |
3867 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3868 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3869 retval = AL_FALSE; |
0 | 3870 } |
3871 } | |
3872 } | |
3873 } | |
3874 return retval; | |
3875 } | |
3876 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3877 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
|
3878 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3879 ALint channel; |
0 | 3880 if(0 == source) |
3881 { | |
3882 return Internal_SetMaxVolumeChannel(-1, volume); | |
3883 } | |
3884 | |
3885 channel = Internal_GetChannel(source); | |
3886 if(-1 == channel) | |
3887 { | |
3888 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
|
3889 return AL_FALSE; |
0 | 3890 } |
3891 return Internal_SetMaxVolumeChannel(channel, volume); | |
3892 } | |
3893 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3894 static ALfloat Internal_GetMaxVolumeChannel(ALint channel) |
0 | 3895 { |
3896 /* | |
3897 ALfloat value; | |
3898 ALenum error; | |
3899 */ | |
3900 ALfloat running_total = 0.0f; | |
3901 ALfloat retval = 0.0f; | |
3902 | |
3903 if(channel >= Number_of_Channels_global) | |
3904 { | |
3905 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); | |
3906 return -1.0f; | |
3907 } | |
3908 | |
3909 if(channel >= 0) | |
3910 { | |
3911 /* | |
3912 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3913 AL_GAIN, &value); | |
3914 if((error = alGetError()) != AL_NO_ERROR) | |
3915 { | |
3916 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3917 alGetString(error) ); |
0 | 3918 retval = -1.0f; |
3919 } | |
3920 else | |
3921 { | |
3922 retval = value; | |
3923 } | |
3924 */ | |
3925 retval = ALmixer_Channel_List[channel].max_volume; | |
3926 | |
3927 } | |
3928 else | |
3929 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3930 ALint i; |
0 | 3931 for(i=0; i<Number_of_Channels_global; i++) |
3932 { | |
3933 /* | |
3934 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
3935 AL_GAIN, &value); | |
3936 if((error = alGetError()) != AL_NO_ERROR) | |
3937 { | |
3938 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3939 alGetString(error) ); |
0 | 3940 retval = -1; |
3941 } | |
3942 else | |
3943 { | |
3944 running_total += value; | |
3945 } | |
3946 */ | |
3947 running_total += ALmixer_Channel_List[i].max_volume; | |
3948 } | |
3949 if(0 == Number_of_Channels_global) | |
3950 { | |
3951 ALmixer_SetError("No channels are allocated"); | |
3952 retval = -1.0f; | |
3953 } | |
3954 else | |
3955 { | |
3956 retval = running_total / Number_of_Channels_global; | |
3957 } | |
3958 } | |
3959 return retval; | |
3960 } | |
3961 | |
3962 static ALfloat Internal_GetMaxVolumeSource(ALuint source) | |
3963 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3964 ALint channel; |
0 | 3965 if(0 == source) |
3966 { | |
3967 return Internal_GetMaxVolumeChannel(-1); | |
3968 } | |
3969 | |
3970 channel = Internal_GetChannel(source); | |
3971 if(-1 == channel) | |
3972 { | |
3973 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
3974 return -1.0f; | |
3975 } | |
3976 | |
3977 return Internal_GetMaxVolumeChannel(channel); | |
3978 } | |
3979 | |
3980 | |
3981 /* Set a volume regardless if it's in use or not. | |
3982 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3983 static ALboolean Internal_SetMinVolumeChannel(ALint channel, ALfloat volume) |
0 | 3984 { |
3985 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3986 ALboolean retval = AL_TRUE; |
0 | 3987 |
3988 if(channel >= Number_of_Channels_global) | |
3989 { | |
3990 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
|
3991 return AL_FALSE; |
0 | 3992 } |
3993 | |
3994 if(channel >= 0) | |
3995 { | |
3996 if(volume < 0.0f) | |
3997 { | |
3998 volume = 0.0f; | |
3999 } | |
4000 else if(volume > 1.0f) | |
4001 { | |
4002 volume = 1.0f; | |
4003 } | |
4004 ALmixer_Channel_List[channel].min_volume = volume; | |
4005 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4006 AL_MIN_GAIN, volume); | |
4007 if((error = alGetError()) != AL_NO_ERROR) | |
4008 { | |
4009 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4010 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4011 retval = AL_FALSE; |
0 | 4012 } |
4013 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
4014 { | |
4015 ALmixer_Channel_List[channel].max_volume = volume; | |
4016 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4017 AL_MAX_GAIN, volume); | |
4018 if((error = alGetError()) != AL_NO_ERROR) | |
4019 { | |
4020 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4021 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4022 retval = AL_FALSE; |
0 | 4023 } |
4024 } | |
4025 } | |
4026 else | |
4027 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4028 ALint i; |
0 | 4029 for(i=0; i<Number_of_Channels_global; i++) |
4030 { | |
4031 if(volume < 0.0f) | |
4032 { | |
4033 volume = 0.0f; | |
4034 } | |
4035 else if(volume > 1.0f) | |
4036 { | |
4037 volume = 1.0f; | |
4038 } | |
4039 ALmixer_Channel_List[i].min_volume = volume; | |
4040 alSourcef(ALmixer_Channel_List[i].alsource, | |
4041 AL_MIN_GAIN, volume); | |
4042 if((error = alGetError()) != AL_NO_ERROR) | |
4043 { | |
4044 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4045 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4046 retval = AL_FALSE; |
0 | 4047 } |
4048 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
4049 { | |
4050 ALmixer_Channel_List[i].max_volume = volume; | |
4051 alSourcef(ALmixer_Channel_List[i].alsource, | |
4052 AL_MAX_GAIN, volume); | |
4053 if((error = alGetError()) != AL_NO_ERROR) | |
4054 { | |
4055 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4056 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4057 retval = AL_FALSE; |
0 | 4058 } |
4059 } | |
4060 } | |
4061 } | |
4062 return retval; | |
4063 } | |
4064 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4065 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
|
4066 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4067 ALint channel; |
0 | 4068 if(0 == source) |
4069 { | |
4070 return Internal_SetMinVolumeChannel(-1, volume); | |
4071 } | |
4072 | |
4073 channel = Internal_GetChannel(source); | |
4074 if(-1 == channel) | |
4075 { | |
4076 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
|
4077 return AL_FALSE; |
0 | 4078 } |
4079 return Internal_SetMinVolumeChannel(channel, volume); | |
4080 } | |
4081 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4082 static ALfloat Internal_GetMinVolumeChannel(ALint channel) |
0 | 4083 { |
4084 /* | |
4085 ALfloat value; | |
4086 ALenum error; | |
4087 */ | |
4088 ALfloat running_total = 0.0f; | |
4089 ALfloat retval = 0.0f; | |
4090 | |
4091 if(channel >= Number_of_Channels_global) | |
4092 { | |
4093 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); | |
4094 return -1.0f; | |
4095 } | |
4096 | |
4097 if(channel >= 0) | |
4098 { | |
4099 /* | |
4100 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
4101 AL_GAIN, &value); | |
4102 if((error = alGetError()) != AL_NO_ERROR) | |
4103 { | |
4104 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4105 alGetString(error) ); |
0 | 4106 retval = -1.0f; |
4107 } | |
4108 else | |
4109 { | |
4110 retval = value; | |
4111 } | |
4112 */ | |
4113 retval = ALmixer_Channel_List[channel].min_volume; | |
4114 | |
4115 } | |
4116 else | |
4117 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4118 ALint i; |
0 | 4119 for(i=0; i<Number_of_Channels_global; i++) |
4120 { | |
4121 /* | |
4122 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
4123 AL_GAIN, &value); | |
4124 if((error = alGetError()) != AL_NO_ERROR) | |
4125 { | |
4126 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4127 alGetString(error) ); |
0 | 4128 retval = -1; |
4129 } | |
4130 else | |
4131 { | |
4132 running_total += value; | |
4133 } | |
4134 */ | |
4135 running_total += ALmixer_Channel_List[i].min_volume; | |
4136 } | |
4137 if(0 == Number_of_Channels_global) | |
4138 { | |
4139 ALmixer_SetError("No channels are allocated"); | |
4140 retval = -1.0f; | |
4141 } | |
4142 else | |
4143 { | |
4144 retval = running_total / Number_of_Channels_global; | |
4145 } | |
4146 } | |
4147 return retval; | |
4148 } | |
4149 | |
4150 static ALfloat Internal_GetMinVolumeSource(ALuint source) | |
4151 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4152 ALint channel; |
0 | 4153 if(0 == source) |
4154 { | |
4155 return Internal_GetMinVolumeChannel(-1); | |
4156 } | |
4157 | |
4158 channel = Internal_GetChannel(source); | |
4159 if(-1 == channel) | |
4160 { | |
4161 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
4162 return -1.0f; | |
4163 } | |
4164 | |
4165 return Internal_GetMinVolumeChannel(channel); | |
4166 } | |
4167 | |
4168 | |
4169 /* Changes the listener volume */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4170 static ALboolean Internal_SetMasterVolume(ALfloat volume) |
0 | 4171 { |
4172 ALenum error; | |
4173 alListenerf(AL_GAIN, volume); | |
4174 if((error = alGetError()) != AL_NO_ERROR) | |
4175 { | |
4176 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4177 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4178 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4179 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4180 return AL_TRUE; |
0 | 4181 } |
4182 | |
4183 static ALfloat Internal_GetMasterVolume() | |
4184 { | |
4185 ALenum error; | |
4186 ALfloat volume; | |
4187 alGetListenerf(AL_GAIN, &volume); | |
4188 if((error = alGetError()) != AL_NO_ERROR) | |
4189 { | |
4190 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4191 alGetString(error) ); |
0 | 4192 return -1.0f; |
4193 } | |
4194 return volume; | |
4195 } | |
4196 | |
4197 | |
4198 | |
4199 | |
4200 /* Will fade out currently playing channels. | |
4201 * 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
|
4202 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
|
4203 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4204 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4205 ALuint counter = 0; |
0 | 4206 |
4207 /* We can't accept 0 as a value because of div-by-zero. | |
4208 * If zero, just call Halt at normal | |
4209 * volume | |
4210 */ | |
4211 if(0 == ticks) | |
4212 { | |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
4213 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 4214 } |
4215 if(ticks < -1) | |
4216 { | |
4217 ticks = -1; | |
4218 } | |
4219 | |
4220 | |
4221 if(channel >= Number_of_Channels_global) | |
4222 { | |
4223 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); | |
4224 return -1; | |
4225 } | |
4226 | |
4227 if(channel >= 0) | |
4228 { | |
4229 if(ALmixer_Channel_List[channel].channel_in_use) | |
4230 { | |
4231 /* Set expire start time */ | |
4232 ALmixer_Channel_List[channel].start_time = current_time; | |
4233 /* Set the expire ticks */ | |
4234 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
4235 | |
4236 counter++; | |
4237 } | |
4238 } | |
4239 /* Else need to fade out all channels */ | |
4240 else | |
4241 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4242 ALint i; |
0 | 4243 for(i=0; i<Number_of_Channels_global; i++) |
4244 { | |
4245 if(ALmixer_Channel_List[i].channel_in_use) | |
4246 { | |
4247 /* Set expire start time */ | |
4248 ALmixer_Channel_List[i].start_time = current_time; | |
4249 /* Set the expire ticks */ | |
4250 ALmixer_Channel_List[i].expire_ticks = ticks; | |
4251 | |
4252 counter++; | |
4253 } | |
4254 } /* End for loop */ | |
4255 } | |
4256 return counter; | |
4257 } | |
4258 | |
4259 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4260 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
|
4261 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4262 ALint channel; |
0 | 4263 if(0 == source) |
4264 { | |
4265 return Internal_ExpireChannel(-1, ticks); | |
4266 } | |
4267 | |
4268 channel = Internal_GetChannel(source); | |
4269 if(-1 == channel) | |
4270 { | |
4271 ALmixer_SetError("Cannot Expire source: %s", ALmixer_GetError()); | |
4272 return -1; | |
4273 } | |
4274 return Internal_ExpireChannel(channel, ticks); | |
4275 } | |
4276 | |
4277 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4278 static ALint Internal_QueryChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4279 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4280 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4281 ALint counter = 0; |
0 | 4282 if(channel >= Number_of_Channels_global) |
4283 { | |
4284 ALmixer_SetError("Invalid channel: %d", channel); | |
4285 return -1; | |
4286 } | |
4287 | |
4288 if(channel >= 0) | |
4289 { | |
4290 return ALmixer_Channel_List[channel].channel_in_use; | |
4291 } | |
4292 | |
4293 /* Else, return the number of channels in use */ | |
4294 for(i=0; i<Number_of_Channels_global; i++) | |
4295 { | |
4296 if(ALmixer_Channel_List[i].channel_in_use) | |
4297 { | |
4298 counter++; | |
4299 } | |
4300 } | |
4301 return counter; | |
4302 } | |
4303 | |
4304 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4305 static ALint Internal_QuerySource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4306 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4307 ALint channel; |
0 | 4308 if(0 == source) |
4309 { | |
4310 return Internal_QueryChannel(-1); | |
4311 } | |
4312 | |
4313 channel = Internal_GetChannel(source); | |
4314 if(-1 == channel) | |
4315 { | |
4316 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4317 return -1; | |
4318 } | |
4319 | |
4320 return Internal_QueryChannel(channel); | |
4321 } | |
4322 | |
4323 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4324 static ALuint Internal_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4325 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4326 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4327 ALuint counter = 0; |
0 | 4328 |
4329 | |
4330 /* Else, return the number of channels in use */ | |
4331 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4332 { | |
4333 if(ALmixer_Channel_List[i].channel_in_use) | |
4334 { | |
4335 counter++; | |
4336 } | |
4337 } | |
4338 return counter; | |
4339 } | |
4340 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4341 static ALuint Internal_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4342 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4343 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4344 ALuint counter = 0; |
0 | 4345 |
4346 | |
4347 /* Else, return the number of channels in use */ | |
4348 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4349 { | |
4350 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4351 { | |
4352 counter++; | |
4353 } | |
4354 } | |
4355 return counter; | |
4356 } | |
4357 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4358 static ALuint Internal_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4359 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4360 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4361 ALuint counter = 0; |
0 | 4362 |
4363 | |
4364 /* Else, return the number of channels in use */ | |
4365 for(i=0; i<Number_of_Channels_global; i++) | |
4366 { | |
4367 if(ALmixer_Channel_List[i].channel_in_use) | |
4368 { | |
4369 counter++; | |
4370 } | |
4371 } | |
4372 return counter; | |
4373 } | |
4374 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4375 static ALuint Internal_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4376 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4377 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4378 ALuint counter = 0; |
0 | 4379 |
4380 | |
4381 /* Else, return the number of channels in use */ | |
4382 for(i=0; i<Number_of_Channels_global; i++) | |
4383 { | |
4384 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4385 { | |
4386 counter++; | |
4387 } | |
4388 } | |
4389 return counter; | |
4390 } | |
4391 | |
4392 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4393 static ALint Internal_PlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4394 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4395 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4396 ALint counter = 0; |
0 | 4397 ALint state; |
4398 | |
4399 if(channel >= Number_of_Channels_global) | |
4400 { | |
4401 ALmixer_SetError("Invalid channel: %d", channel); | |
4402 return -1; | |
4403 } | |
4404 | |
4405 if(channel >= 0) | |
4406 { | |
4407 if(ALmixer_Channel_List[channel].channel_in_use) | |
4408 { | |
4409 alGetSourcei( | |
4410 ALmixer_Channel_List[channel].alsource, | |
4411 AL_SOURCE_STATE, &state | |
4412 ); | |
4413 if(AL_PLAYING == state) | |
4414 { | |
4415 return 1; | |
4416 } | |
4417 } | |
4418 return 0; | |
4419 } | |
4420 | |
4421 /* Else, return the number of channels in use */ | |
4422 for(i=0; i<Number_of_Channels_global; i++) | |
4423 { | |
4424 if(ALmixer_Channel_List[i].channel_in_use) | |
4425 { | |
4426 alGetSourcei( | |
4427 ALmixer_Channel_List[i].alsource, | |
4428 AL_SOURCE_STATE, &state | |
4429 ); | |
4430 if(AL_PLAYING == state) | |
4431 { | |
4432 counter++; | |
4433 } | |
4434 } | |
4435 } | |
4436 return counter; | |
4437 } | |
4438 | |
4439 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4440 static ALint Internal_PlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4441 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4442 ALint channel; |
0 | 4443 if(0 == source) |
4444 { | |
4445 return Internal_PlayingChannel(-1); | |
4446 } | |
4447 | |
4448 channel = Internal_GetChannel(source); | |
4449 if(-1 == channel) | |
4450 { | |
4451 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4452 return -1; | |
4453 } | |
4454 | |
4455 return Internal_PlayingChannel(channel); | |
4456 } | |
4457 | |
4458 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4459 static ALint Internal_PausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4460 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4461 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4462 ALint counter = 0; |
0 | 4463 ALint state; |
4464 | |
4465 if(channel >= Number_of_Channels_global) | |
4466 { | |
4467 ALmixer_SetError("Invalid channel: %d", channel); | |
4468 return -1; | |
4469 } | |
4470 | |
4471 if(channel >= 0) | |
4472 { | |
4473 if(ALmixer_Channel_List[channel].channel_in_use) | |
4474 { | |
4475 alGetSourcei( | |
4476 ALmixer_Channel_List[channel].alsource, | |
4477 AL_SOURCE_STATE, &state | |
4478 ); | |
4479 if(AL_PAUSED == state) | |
4480 { | |
4481 return 1; | |
4482 } | |
4483 } | |
4484 return 0; | |
4485 } | |
4486 | |
4487 /* Else, return the number of channels in use */ | |
4488 for(i=0; i<Number_of_Channels_global; i++) | |
4489 { | |
4490 if(ALmixer_Channel_List[i].channel_in_use) | |
4491 { | |
4492 alGetSourcei( | |
4493 ALmixer_Channel_List[i].alsource, | |
4494 AL_SOURCE_STATE, &state | |
4495 ); | |
4496 if(AL_PAUSED == state) | |
4497 { | |
4498 counter++; | |
4499 } | |
4500 } | |
4501 } | |
4502 return counter; | |
4503 } | |
4504 | |
4505 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4506 static ALint Internal_PausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4507 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4508 ALint channel; |
0 | 4509 if(0 == source) |
4510 { | |
4511 return Internal_PausedChannel(-1); | |
4512 } | |
4513 | |
4514 channel = Internal_GetChannel(source); | |
4515 if(-1 == channel) | |
4516 { | |
4517 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4518 return -1; | |
4519 } | |
4520 | |
4521 return Internal_PausedChannel(channel); | |
4522 } | |
4523 | |
4524 | |
4525 | |
4526 | |
4527 | |
4528 | |
4529 /* Private function for Updating ALmixer. | |
4530 * This is a very big and ugly function. | |
4531 * It should return the number of buffers that were | |
4532 * queued during the call. The value might be | |
4533 * used to guage how long you might wait to | |
4534 * call the next update loop in case you are worried | |
4535 * about preserving CPU cycles. The idea is that | |
4536 * when a buffer is queued, there was probably some | |
4537 * CPU intensive looping which took awhile. | |
4538 * 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
|
4539 * Timing the call with ALmixer_GetTicks() would produce |
0 | 4540 * more accurate information. |
4541 * Returns a negative value if there was an error, | |
4542 * the value being the number of errors. | |
4543 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4544 static ALint Update_ALmixer(void* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4545 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4546 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4547 ALint error_flag = 0; |
0 | 4548 ALenum error; |
4549 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4550 ALint i=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4551 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4552 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4553 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4554 #endif |
0 | 4555 if(0 == ALmixer_Initialized) |
4556 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4557 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4558 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4559 #endif |
0 | 4560 return 0; |
4561 } | |
4562 | |
4563 /* Check the quick flag to see if anything needs updating */ | |
4564 /* If anything is playing, then we have to do work */ | |
4565 if( 0 == Is_Playing_global) | |
4566 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4567 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4568 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4569 #endif |
0 | 4570 return 0; |
4571 } | |
4572 /* Clear error */ | |
4573 if((error = alGetError()) != AL_NO_ERROR) | |
4574 { | |
4575 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
|
4576 alGetString(error)); |
0 | 4577 } |
4578 alGetError(); | |
4579 | |
4580 for(i=0; i<Number_of_Channels_global; i++) | |
4581 { | |
4582 if( ALmixer_Channel_List[i].channel_in_use ) | |
4583 { | |
4584 | |
4585 /* For simplicity, before we do anything else, | |
4586 * we can check the timeout and fading values | |
4587 * and do the appropriate things | |
4588 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4589 ALuint current_time = ALmixer_GetTicks(); |
0 | 4590 |
4591 /* Check to see if we need to halt due to Timed play */ | |
4592 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
4593 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4594 ALuint target_time = (ALuint)ALmixer_Channel_List[i].expire_ticks |
0 | 4595 + ALmixer_Channel_List[i].start_time; |
4596 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4597 AL_SOURCE_STATE, &state); | |
4598 if((error = alGetError()) != AL_NO_ERROR) | |
4599 { | |
4600 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
|
4601 alGetString(error)); |
0 | 4602 } |
4603 | |
4604 /* Check the time, and also make sure that it is not | |
4605 * paused (if paused, we don't want to make the | |
4606 * evaluation because when resumed, we will adjust | |
4607 * the times to compensate for the pause). | |
4608 */ | |
4609 if( (current_time >= target_time) | |
4610 && (state != AL_PAUSED) ) | |
4611 { | |
4612 /* Stop the playback */ | |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
4613 Internal_HaltChannel(i, AL_FALSE); |
0 | 4614 if((error = alGetError()) != AL_NO_ERROR) |
4615 { | |
4616 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
|
4617 alGetString(error)); |
0 | 4618 } |
4619 | |
4620 /* Everything should be done so go on to the next loop */ | |
4621 continue; | |
4622 } | |
4623 } /* End if time expired check */ | |
4624 | |
4625 /* Check to see if we need to adjust the volume for fading */ | |
4626 if( ALmixer_Channel_List[i].fade_enabled ) | |
4627 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4628 ALuint target_time = ALmixer_Channel_List[i].fade_expire_ticks |
0 | 4629 + ALmixer_Channel_List[i].fade_start_time; |
4630 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4631 AL_SOURCE_STATE, &state); | |
4632 if((error = alGetError()) != AL_NO_ERROR) | |
4633 { | |
4634 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
|
4635 alGetString(error)); |
0 | 4636 } |
4637 | |
4638 /* Check the time, and also make sure that it is not | |
4639 * paused (if paused, we don't want to make the | |
4640 * evaluation because when resumed, we will adjust | |
4641 * the times to compensate for the pause). | |
4642 */ | |
4643 if(state != AL_PAUSED) | |
4644 { | |
4645 ALfloat t; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4646 ALuint delta_time; |
0 | 4647 ALfloat current_volume; |
4648 if(current_time >= target_time) | |
4649 { | |
4650 /* Need to constrain value to the end time | |
4651 * (can't go pass the value for calculations) | |
4652 */ | |
4653 current_time = target_time; | |
4654 /* We can disable the fade flag now */ | |
4655 ALmixer_Channel_List[i].fade_enabled = 0; | |
4656 } | |
4657 /* Use the linear interpolation formula: | |
4658 * X = (1-t)x0 + tx1 | |
4659 * where x0 would be the start value | |
4660 * and x1 is the final value | |
4661 * and t is delta_time*inv_time (adjusts 0 <= time <= 1) | |
4662 * delta_time = current_time-start_time | |
4663 * inv_time = 1/ (end_time-start_time) | |
4664 * so t = current_time-start_time / (end_time-start_time) | |
4665 * | |
4666 */ | |
4667 delta_time = current_time - ALmixer_Channel_List[i].fade_start_time; | |
4668 t = (ALfloat) delta_time * ALmixer_Channel_List[i].fade_inv_time; | |
4669 | |
4670 current_volume = (1.0f-t) * ALmixer_Channel_List[i].fade_start_volume | |
4671 + t * ALmixer_Channel_List[i].fade_end_volume; | |
4672 | |
4673 /* Set the volume */ | |
4674 alSourcef(ALmixer_Channel_List[i].alsource, | |
4675 AL_MAX_GAIN, current_volume); | |
4676 if((error = alGetError()) != AL_NO_ERROR) | |
4677 { | |
4678 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
|
4679 alGetString(error)); |
0 | 4680 } |
4681 | |
4682 /* | |
4683 fprintf(stderr, "Current time =%d\n", current_time); | |
4684 fprintf(stderr, "Current vol=%f on channel %d\n", current_volume, i); | |
4685 */ | |
4686 } /* End if not PAUSED */ | |
4687 } /* End if fade_enabled */ | |
4688 | |
4689 | |
4690 /* Okay, now that the time expired and fading stuff | |
4691 * is done, do the rest of the hard stuff | |
4692 */ | |
4693 | |
4694 | |
4695 /* For predecoded, check to see if done */ | |
4696 if( ALmixer_Channel_List[i].almixer_data->decoded_all ) | |
4697 { | |
4698 | |
4699 #if 0 | |
4700 /********* Remove this **********/ | |
4701 ALint buffers_processed; | |
4702 ALint buffers_still_queued; | |
4703 fprintf(stderr, "For Predecoded\n"); | |
4704 | |
4705 alGetSourcei( | |
4706 ALmixer_Channel_List[i].alsource, | |
4707 AL_SOURCE_STATE, &state | |
4708 ); | |
4709 switch(state) { | |
4710 case AL_PLAYING: | |
4711 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
4712 break; | |
4713 case AL_PAUSED: | |
4714 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
4715 break; | |
4716 case AL_STOPPED: | |
4717 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
4718 break; | |
4719 case AL_INITIAL: | |
4720 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
4721 break; | |
4722 default: | |
4723 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
4724 break; | |
4725 } | |
4726 | |
4727 alGetSourcei( | |
4728 ALmixer_Channel_List[i].alsource, | |
4729 AL_BUFFERS_PROCESSED, &buffers_processed | |
4730 ); | |
4731 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
4732 | |
4733 alGetSourcei( | |
4734 ALmixer_Channel_List[i].alsource, | |
4735 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4736 ); | |
4737 | |
4738 /******** END REMOVE *******/ | |
4739 #endif | |
4740 /* FIXME: Ugh! Somewhere an alError is being thrown ("Invalid Enum Value"), but I can't | |
4741 * find it. It only seems to be thrown for OS X. I placed error messages after every al* | |
4742 * command I could find in the above loops, but the error doesn't seem to show | |
4743 * up until around here. I mistook it for a get queued buffers | |
4744 * error in OS X. I don't think there's an error down there. | |
4745 * For now, I'm clearing the error here. | |
4746 */ | |
4747 | |
4748 if((error = alGetError()) != AL_NO_ERROR) | |
4749 { | |
4750 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
|
4751 alGetString(error)); |
0 | 4752 } |
4753 | |
4754 | |
4755 alGetSourcei( | |
4756 ALmixer_Channel_List[i].alsource, | |
4757 AL_SOURCE_STATE, &state | |
4758 ); | |
4759 if((error = alGetError()) != AL_NO_ERROR) | |
4760 { | |
4761 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
|
4762 alGetString(error)); |
0 | 4763 } |
4764 | |
4765 | |
4766 if(AL_STOPPED == state) | |
4767 { | |
4768 /* Playback has ended. | |
4769 * Loop if necessary, or launch callback | |
4770 * and clear channel (or clear channel and | |
4771 * then launch callback?) | |
4772 */ | |
4773 | |
4774 | |
4775 /* Need to check for loops */ | |
4776 if(ALmixer_Channel_List[i].loops != 0) | |
4777 { | |
4778 /* Corner Case: If the buffer has | |
4779 * been modified using Seek, | |
4780 * the loop will start at the seek | |
4781 * position. | |
4782 */ | |
4783 if(ALmixer_Channel_List[i].loops != -1) | |
4784 { | |
4785 ALmixer_Channel_List[i].loops--; | |
4786 } | |
4787 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
4788 if((error = alGetError()) != AL_NO_ERROR) | |
4789 { | |
4790 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
|
4791 alGetString(error)); |
0 | 4792 } |
4793 continue; | |
4794 } | |
4795 /* No loops. End play. */ | |
4796 else | |
4797 { | |
4798 /* Problem: It seems that when mixing | |
4799 * streamed and predecoded sources, | |
4800 * the previous instance lingers, | |
4801 * so we need to force remove | |
4802 * the data from the source. | |
4803 * The sharing problem | |
4804 * occurs when a previous predecoded buffer is played on | |
4805 * a source, and then a streamed source is played later | |
4806 * on that same source. OpenAL isn't consistently | |
4807 * removing the previous buffer so both get played. | |
4808 * (Different dists seem to have different quirks. | |
4809 * The problem might lead to crashes in the worst case.) | |
4810 */ | |
4811 /* Additional problem: There is another | |
4812 * inconsistency among OpenAL distributions. | |
4813 * Both Loki and Creative Windows seem to keep | |
4814 * the buffer queued which requires removing. | |
4815 * But the Creative Macintosh version does | |
4816 * not have any buffer queued after play | |
4817 * and it returns the error: Invalid Enum Value | |
4818 * if I try to unqueue it. | |
4819 * So I'm going to put in a check to see if I | |
4820 * can detect any buffers queued first | |
4821 * and then unqueue them if I can see them. | |
4822 * Additional note: The new CoreAudio based | |
4823 * implementation leaves it's buffer queued | |
4824 * like Loki and Creative Windows. But | |
4825 * considering all the problems I'm having | |
4826 * with the different distributions, this | |
4827 * check seems reasonable. | |
4828 */ | |
4829 ALint buffers_still_queued; | |
4830 if((error = alGetError()) != AL_NO_ERROR) | |
4831 { | |
4832 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
|
4833 alGetString(error)); |
0 | 4834 } |
4835 | |
4836 alGetSourcei( | |
4837 ALmixer_Channel_List[i].alsource, | |
4838 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4839 ); | |
4840 if((error = alGetError()) != AL_NO_ERROR) | |
4841 { | |
4842 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
|
4843 alGetString(error)); |
0 | 4844 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
|
4845 alGetString(error) ); |
0 | 4846 error_flag--; |
4847 } | |
4848 if(buffers_still_queued > 0) | |
4849 { | |
1 | 4850 |
4851 #if 0 /* This triggers an error in OS X Core Audio. */ | |
4852 alSourceUnqueueBuffers( | |
4853 ALmixer_Channel_List[i].alsource, | |
4854 1, | |
4855 ALmixer_Channel_List[i].almixer_data->buffer | |
4856 ); | |
4857 #else | |
4858 /* fprintf(stderr, "In the Bob Aron section...about to clear source\n"); | |
0 | 4859 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 4860 */ |
0 | 4861 /* Rather than force unqueuing the buffer, let's see if |
4862 * setting the buffer to none works (the OpenAL 1.0 | |
4863 * Reference Annotation suggests this should work). | |
4864 */ | |
4865 alSourcei(ALmixer_Channel_List[i].alsource, | |
4866 AL_BUFFER, AL_NONE); | |
4867 /* | |
4868 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
4869 */ | |
1 | 4870 #endif |
0 | 4871 if((error = alGetError()) != AL_NO_ERROR) |
4872 { | |
4873 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
|
4874 alGetString(error)); |
0 | 4875 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
|
4876 alGetString(error) ); |
0 | 4877 error_flag--; |
4878 } | |
4879 | |
4880 } | |
4881 | |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
4882 /* Launch callback */ |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
4883 Invoke_Channel_Done_Callback(i, AL_TRUE); |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
4884 |
0 | 4885 Clean_Channel(i); |
4886 /* Subtract counter */ | |
4887 Is_Playing_global--; | |
4888 | |
4889 | |
4890 /* We're done for this loop. | |
4891 * Go to next channel | |
4892 */ | |
4893 continue; | |
4894 } | |
4895 continue; | |
4896 } | |
4897 } /* End if decoded_all */ | |
4898 /* For streamed */ | |
4899 else | |
4900 { | |
4901 ALint buffers_processed; | |
4902 ALint buffers_still_queued; | |
4903 ALint current_buffer_id; | |
4904 | |
4905 ALuint unqueued_buffer_id; | |
4906 #if 0 | |
4907 /********* Remove this **********/ | |
4908 fprintf(stderr, "For Streamed\n"); | |
4909 | |
4910 alGetSourcei( | |
4911 ALmixer_Channel_List[i].alsource, | |
4912 AL_SOURCE_STATE, &state | |
4913 ); | |
4914 switch(state) { | |
4915 case AL_PLAYING: | |
4916 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
4917 break; | |
4918 case AL_PAUSED: | |
4919 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
4920 break; | |
4921 case AL_STOPPED: | |
4922 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
4923 break; | |
4924 case AL_INITIAL: | |
4925 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
4926 break; | |
4927 default: | |
4928 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
4929 break; | |
4930 } | |
4931 /******** END REMOVE *******/ | |
4932 #endif | |
4933 /* Get the number of buffers still queued */ | |
4934 alGetSourcei( | |
4935 ALmixer_Channel_List[i].alsource, | |
4936 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4937 ); | |
4938 if((error = alGetError()) != AL_NO_ERROR) | |
4939 { | |
4940 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
|
4941 alGetString(error)); |
0 | 4942 } |
4943 /* Get the number of buffers processed | |
4944 * so we know if we need to refill | |
4945 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4946 /* 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
|
4947 * 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
|
4948 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4949 // fprintf(stderr, "calling AL_BUFFERS_PROCESSED on source:%d", ALmixer_Channel_List[i].alsource); |
0 | 4950 alGetSourcei( |
4951 ALmixer_Channel_List[i].alsource, | |
4952 AL_BUFFERS_PROCESSED, &buffers_processed | |
4953 ); | |
4954 if((error = alGetError()) != AL_NO_ERROR) | |
4955 { | |
4956 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
|
4957 alGetString(error)); |
0 | 4958 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4959 // fprintf(stderr, "finished AL_BUFFERS_PROCESSED, buffers_processed=%d", buffers_processed); |
0 | 4960 |
4961 /* WTF!!! The Nvidia distribution is failing on the alGetSourcei(source, AL_BUFFER, buf_id) call. | |
4962 * I need this call to figure out which buffer OpenAL is currently playing. | |
4963 * It keeps returning an "Invalid Enum" error. | |
4964 * This is totally inane! It's a basic query. | |
4965 * By the spec, this functionality is not explicitly defined so Nvidia refuses to | |
4966 * fix this behavior, even though all other distributions work fine with this. | |
4967 * The only workaround for this is for | |
4968 * a significant rewrite of my code which requires me to | |
4969 * duplicate the OpenAL queued buffers state with my own | |
4970 * code and try to derive what the current playing buffer is by indirect observation of | |
4971 * looking at buffers_processed. But of course this has a ton of downsides since my | |
4972 * queries do not give me perfect timing of what OpenAL is actually doing and | |
4973 * the fact that some of the distributions seem to have buffer queuing problems | |
4974 * with their query results (CoreAudio). This also means a ton of extra code | |
4975 * on my side. The lack of support of a 1 line call has required me to | |
4976 * implement yet another entire state machine. <sigh> | |
4977 */ | |
4978 #if 0 /* This code will not work until possibly OpenAL 1.1 because of Nvidia */ | |
4979 /* Get the id to the current buffer playing */ | |
4980 alGetSourcei( | |
4981 ALmixer_Channel_List[i].alsource, | |
4982 AL_BUFFER, ¤t_buffer_id | |
4983 ); | |
4984 if((error = alGetError()) != AL_NO_ERROR) | |
4985 { | |
4986 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
|
4987 alGetString(error)); |
0 | 4988 } |
4989 | |
4990 /* Before the hard stuff, check to see if the | |
4991 * current queued AL buffer has changed. | |
4992 * If it has, we should launch a data callback if | |
4993 * necessary | |
4994 */ | |
4995 if( ((ALuint)current_buffer_id) != | |
4996 ALmixer_Channel_List[i].almixer_data->current_buffer) | |
4997 { | |
4998 ALmixer_Channel_List[i].almixer_data->current_buffer | |
4999 = (ALuint)current_buffer_id; | |
5000 | |
5001 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5002 } | |
5003 #else | |
5004 /* Only do this if "access_data" was requested (i.e. the circular_buffer!=NULL) | |
5005 * And if one of the two are true: | |
5006 * Either buffers_processed > 0 (because the current_buffer might have changed) | |
5007 * or if the current_buffer==0 (because we are in an initial state or recovering from | |
5008 * a buffer underrun) | |
5009 */ | |
5010 if((ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5011 && ( | |
5012 (buffers_processed > 0) || (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5013 ) | |
5014 ) | |
5015 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5016 ALint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5017 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5018 ALubyte is_out_of_sync = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5019 ALuint my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
1 | 5020 /* Ugh, I have to deal with signed/unsigned mismatch here. */ |
5021 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
|
5022 ALuint unplayed_buffers; |
1 | 5023 if(buffers_unplayed_int < 0) |
5024 { | |
5025 unplayed_buffers = 0; | |
5026 } | |
5027 else | |
5028 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5029 unplayed_buffers = (ALuint)buffers_unplayed_int; |
1 | 5030 } |
0 | 5031 /* |
5032 fprintf(stderr, "Queue in processed check, before pop, buffers_processed=%d\n", buffers_processed); | |
5033 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5034 */ | |
5035 /* We can't make any determinations solely based on the number of buffers_processed | |
5036 * because currently, we only unqueue 1 buffer per loop. That means if 2 or more | |
5037 * buffers became processed in one loop, the following loop, we would have | |
5038 * at least that_many-1 buffers_processed (plus possible new processed). | |
5039 * If we tried to just remove 1 buffer from our queue, we would be incorrect | |
5040 * because we would not actually reflect the current playing buffer. | |
5041 * So the solution seems to be to make sure our queue is the same size | |
5042 * as the number of buffers_queued-buffers_processed, and return the head of our queue | |
5043 * as the current playing buffer. | |
5044 */ | |
5045 /* Also, we have a corner case. When we first start playing or if we have | |
5046 * a buffer underrun, we have not done a data callback. | |
5047 * In this case, we need to see if there is any new data in our queue | |
5048 * and if so, launch that data callback. | |
5049 */ | |
5050 /* Warning, this code risks the possibility of no data callback being fired if | |
5051 * the system is really late (or skipped buffers). | |
5052 */ | |
5053 | |
5054 /* First, let's syncronize our queue with the OpenAL queue */ | |
5055 #if 0 | |
5056 fprintf(stderr, "inside, Buffers processed=%d, Buffers queued=%d, my queue=%d\n", | |
5057 buffers_processed, buffers_still_queued, my_queue_size); | |
1 | 5058 #endif |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5059 is_out_of_sync = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5060 for(k=0; k<buffers_processed; k++) |
0 | 5061 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5062 queue_ret_flag = CircularQueueUnsignedInt_PopFront( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5063 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
|
5064 if(0 == queue_ret_flag) |
0 | 5065 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5066 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
|
5067 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5068 } |
0 | 5069 my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
5070 /* We have several possibilities we need to handle: | |
5071 * 1) We are in an initial state or underrun and need to do a data callback on the head. | |
5072 * 2) We were out of sync and need to do a new data callback on the new head. | |
5073 * 3) We were not out of sync but just had left over processed buffers which caused us to | |
5074 * fall in this block of code. (Don't do anything.) | |
5075 */ | |
5076 if( (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) || (1 == is_out_of_sync) ) | |
5077 { | |
5078 if(my_queue_size > 0) | |
5079 { | |
5080 current_buffer_id = CircularQueueUnsignedInt_Front( | |
5081 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5082 if(0 == current_buffer_id) | |
5083 { | |
5084 fprintf(stderr, "53a Internal Error, current_buffer_id=0 when it shouldn't be 0\n"); | |
5085 } | |
5086 /* | |
5087 else | |
5088 { | |
5089 fprintf(stderr, "Queue in processed check, after pop\n"); | |
5090 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5091 } | |
5092 */ | |
5093 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5094 = (ALuint)current_buffer_id; | |
5095 | |
5096 #if 0 | |
5097 /* Remove me...only for checking...doesn't work on Nvidia */ | |
5098 { | |
5099 ALuint real_id; | |
5100 alGetSourcei( | |
5101 ALmixer_Channel_List[i].alsource, | |
5102 AL_BUFFER, &real_id | |
5103 ); | |
5104 alGetError(); | |
5105 fprintf(stderr, "Callback fired on data buffer=%d, real_id shoud be=%d\n", current_buffer_id, real_id); | |
5106 } | |
5107 #endif | |
5108 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5109 } | |
5110 else | |
5111 { | |
1 | 5112 /* |
0 | 5113 fprintf(stderr, "53b, Notice/Warning:, OpenAL queue has been depleted.\n"); |
1 | 5114 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
5115 */ | |
0 | 5116 /* In this case, we might either be in an underrun or finished with playback */ |
5117 ALmixer_Channel_List[i].almixer_data->current_buffer = 0; | |
5118 } | |
5119 } | |
5120 } | |
5121 #endif | |
5122 | |
5123 | |
5124 | |
5125 /* Just a test - remove | |
5126 if( ALmixer_Channel_List[i].loops > 0) | |
5127 { | |
5128 fprintf(stderr, ">>>>>>>>>>>>>>>Loops = %d\n", | |
5129 ALmixer_Channel_List[i].loops); | |
5130 } | |
5131 */ | |
5132 #if 0 | |
5133 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
5134 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5135 #endif | |
5136 /* We've used up a buffer so we need to unqueue and replace */ | |
5137 /* Okay, it gets more complicated here: | |
5138 * We need to Queue more data | |
5139 * if buffers_processed > 0 or | |
5140 * if num_of_buffers_in_use < NUMBER_OF_QUEUE_BUFFERS | |
5141 * but we don't do this if at EOF, | |
5142 * except when there is looping | |
5143 */ | |
5144 /* For this to work, we must rely on EVERYTHING | |
5145 * else to unset the EOF if there is looping. | |
5146 * Remember, even Play() must do this | |
5147 */ | |
5148 | |
5149 /* If not EOF, then we are still playing. | |
5150 * Inside, we might find num_of_buffers < NUM...QUEUE_BUF.. | |
5151 * or buffers_process > 0 | |
5152 * in which case we queue up. | |
5153 * We also might find no buffers we need to fill, | |
5154 * in which case we just keep going | |
5155 */ | |
5156 if( ! ALmixer_Channel_List[i].almixer_data->eof) | |
5157 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5158 ALuint bytes_returned; |
0 | 5159 /* We have a priority. We first must assign |
5160 * unused buffers in reserve. If there is nothing | |
5161 * left, then we may unqueue buffers. We can't | |
5162 * do it the other way around because we will | |
5163 * lose the pointer to the unqueued buffer | |
5164 */ | |
5165 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5166 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5167 { | |
1 | 5168 #if 0 |
0 | 5169 fprintf(stderr, "Getting more data in NOT_EOF and num_buffers_in_use (%d) < max_queue (%d)\n", |
5170 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5171 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5172 #endif |
0 | 5173 /* Going to add an unused packet. |
5174 * Grab next packet */ | |
5175 bytes_returned = GetMoreData( | |
5176 ALmixer_Channel_List[i].almixer_data, | |
5177 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5178 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5179 ); | |
5180 } | |
5181 /* For processed > 0 */ | |
5182 else if(buffers_processed > 0) | |
5183 { | |
5184 /* Unqueue only 1 buffer for now. | |
5185 * If there are more than one, | |
5186 * let the next Update pass deal with it | |
5187 * so we don't stall the program for too long. | |
5188 */ | |
5189 #if 0 | |
5190 fprintf(stderr, "About to Unqueue, Buffers processed = %d\n", buffers_processed); | |
5191 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5192 fprintf(stderr, "Unqueuing a buffer\n"); | |
5193 #endif | |
5194 alSourceUnqueueBuffers( | |
5195 ALmixer_Channel_List[i].alsource, | |
5196 1, &unqueued_buffer_id | |
5197 ); | |
5198 if((error = alGetError()) != AL_NO_ERROR) | |
5199 { | |
5200 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
|
5201 alGetString(error)); |
0 | 5202 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
|
5203 alGetString(error) ); |
0 | 5204 error_flag--; |
5205 } | |
5206 /* | |
5207 fprintf(stderr, "Right after unqueue..."); | |
5208 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5209 fprintf(stderr, "Getting more data for NOT_EOF, max_buffers filled\n"); | |
5210 */ | |
5211 /* Grab unqueued packet */ | |
5212 bytes_returned = GetMoreData( | |
5213 ALmixer_Channel_List[i].almixer_data, | |
5214 unqueued_buffer_id); | |
5215 } | |
5216 /* We are still streaming, but currently | |
5217 * don't need to fill any buffers */ | |
5218 else | |
5219 { | |
5220 /* Might want to check state */ | |
5221 /* In case the playback stopped, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5222 * we need to resume |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5223 * a.k.a. buffer underrun |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5224 */ |
1 | 5225 #if 1 |
5226 /* Try not refetching the state here because I'm getting a duplicate | |
5227 buffer playback (hiccup) */ | |
0 | 5228 alGetSourcei( |
5229 ALmixer_Channel_List[i].alsource, | |
5230 AL_SOURCE_STATE, &state | |
5231 ); | |
1 | 5232 if((error = alGetError()) != AL_NO_ERROR) |
5233 { | |
5234 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
|
5235 alGetString(error)); |
1 | 5236 } |
5237 /* Get the number of buffers processed | |
5238 */ | |
5239 alGetSourcei( | |
5240 ALmixer_Channel_List[i].alsource, | |
5241 AL_BUFFERS_PROCESSED, | |
5242 &buffers_processed | |
5243 ); | |
5244 if((error = alGetError()) != AL_NO_ERROR) | |
5245 { | |
5246 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
|
5247 alGetString(error)); |
1 | 5248 } |
5249 #endif | |
0 | 5250 if(AL_STOPPED == state) |
5251 { | |
5252 /* Resuming in not eof, but nothing to buffer */ | |
1 | 5253 |
5254 /* Okay, here's another lately discovered problem: | |
5255 * I can't find it in the spec, but for at least some of the | |
5256 * implementations, if I call play on a stopped source that | |
5257 * has processed buffers, all those buffers get marked as unprocessed | |
5258 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5259 * processed, on resume, the earlier 24 buffers will get replayed, | |
5260 * causing a "hiccup" like sound in the playback. | |
5261 * To avoid this, I must unqueue all processed buffers before | |
5262 * calling play. But to complicate things, I need to worry about resyncing | |
5263 * the circular queue with this since I designed this thing | |
5264 * with some correlation between the two. However, I might | |
5265 * have already handled this, so I will try writing this code without | |
5266 * syncing for now. | |
5267 * There is currently an assumption that a buffer | |
5268 * was queued above so I actually have something | |
5269 * to play. | |
5270 */ | |
5271 ALint temp_count; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5272 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5273 fprintf(stderr, "STOPPED1, need to clear processed=%d, status is:\n", buffers_processed); |
1 | 5274 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
|
5275 #endif |
1 | 5276 for(temp_count=0; temp_count<buffers_processed; temp_count++) |
5277 { | |
5278 alSourceUnqueueBuffers( | |
5279 ALmixer_Channel_List[i].alsource, | |
5280 1, &unqueued_buffer_id | |
5281 ); | |
5282 if((error = alGetError()) != AL_NO_ERROR) | |
5283 { | |
5284 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
|
5285 alGetString(error)); |
1 | 5286 error_flag--; |
5287 } | |
5288 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5289 #if 0 |
1 | 5290 fprintf(stderr, "After unqueue clear...:\n"); |
5291 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
|
5292 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5293 /* 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
|
5294 * 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
|
5295 * 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
|
5296 * 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
|
5297 * no buffers in queue. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5298 * 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
|
5299 * Then we need to resume playing. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5300 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5301 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5302 int buffers_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5303 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5304 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5305 AL_BUFFERS_QUEUED, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5306 &buffers_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5307 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5308 |
1 | 5309 if((error = alGetError()) != AL_NO_ERROR) |
5310 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5311 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
|
5312 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5313 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5314 assert(buffers_queued == 0); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5315 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
|
5316 #endif |
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 /* 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
|
5319 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
|
5320 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5321 /* 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
|
5322 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5323 ALmixer_Channel_List[i].almixer_data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5324 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
|
5325 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5326 /* 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
|
5327 * 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
|
5328 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5329 if(bytes_returned > 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5330 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5331 /* Queue up the new data */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5332 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5333 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5334 1, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5335 &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
|
5336 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5337 if((error = alGetError()) != AL_NO_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 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
|
5340 alGetString(error)); |
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 /* 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
|
5343 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
|
5344 |
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 /* 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
|
5347 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
|
5348 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5349 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5350 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
|
5351 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5352 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
|
5353 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
|
5354 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5355 if(0 == queue_ret_flag) |
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 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
|
5358 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
|
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5363 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5364 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5365 /* Resume playback from underrun */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5366 alSourcePlay(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5367 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5368 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5369 fprintf(stderr, "55Tbesting error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5370 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5371 } |
1 | 5372 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5373 |
0 | 5374 } |
5375 /* Let's escape to the next loop. | |
5376 * All code below this point is for queuing up | |
5377 */ | |
5378 /* | |
1 | 5379 fprintf(stderr, "Entry: Nothing to do...continue\n\n"); |
5380 */ | |
0 | 5381 continue; |
5382 } | |
5383 /* We now know we have to fill an available | |
5384 * buffer. | |
5385 */ | |
5386 | |
5387 /* In the previous branch, we just grabbed more data. | |
5388 * Let's check it to make sure it's okay, | |
5389 * and then queue it up | |
5390 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5391 /* This check doesn't work anymore because it is now ALuint */ |
0 | 5392 #if 0 |
5393 if(-1 == bytes_returned) | |
5394 { | |
5395 /* Problem occurred...not sure what to do */ | |
5396 /* Go to next loop? */ | |
5397 error_flag--; | |
5398 /* Set the eof flag to force a quit so | |
5399 * we don't get stuck in an infinite loop | |
5400 */ | |
5401 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5402 continue; | |
5403 } | |
5404 #endif | |
5405 /* This is a special case where we've run | |
5406 * out of data. We should check for loops | |
5407 * and get more data. If there is no loop, | |
5408 * then do nothing and wait for future | |
5409 * update passes to handle the EOF. | |
5410 * The advantage of handling the loop here | |
5411 * instead of waiting for play to stop is | |
5412 * that we should be able to keep the buffer | |
5413 * filled. | |
5414 */ | |
5415 #if 0 | |
5416 else if(0 == bytes_returned) | |
5417 #endif | |
5418 if(0 == bytes_returned) | |
5419 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5420 /* |
0 | 5421 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
|
5422 */ |
0 | 5423 /* Check for loops */ |
5424 if( ALmixer_Channel_List[i].loops != 0 ) | |
5425 { | |
5426 /* We have to loop, so rewind | |
5427 * and fetch more data | |
5428 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5429 /* |
0 | 5430 fprintf(stderr, "Rewinding data\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5431 */ |
0 | 5432 if(0 == Sound_Rewind( |
5433 ALmixer_Channel_List[i].almixer_data->sample)) | |
5434 { | |
5435 fprintf(stderr, "Rewinding failed\n"); | |
5436 ALmixer_SetError( Sound_GetError() ); | |
5437 ALmixer_Channel_List[i].loops = 0; | |
5438 error_flag--; | |
5439 /* We'll continue on because we do have some valid data */ | |
5440 continue; | |
5441 } | |
5442 /* Remember to reset the data->eof flag */ | |
5443 ALmixer_Channel_List[i].almixer_data->eof = 0; | |
5444 if(ALmixer_Channel_List[i].loops > 0) | |
5445 { | |
5446 ALmixer_Channel_List[i].loops--; | |
5447 } | |
5448 /* Try grabbing another packet now. | |
5449 * Since we may have already unqueued a | |
5450 * buffer, we don't want to lose it. | |
5451 */ | |
5452 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5453 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5454 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5455 /* |
0 | 5456 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
|
5457 */ |
0 | 5458 /* Grab next packet */ |
5459 bytes_returned = GetMoreData( | |
5460 ALmixer_Channel_List[i].almixer_data, | |
5461 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5462 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5463 ); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5464 /* |
0 | 5465 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
|
5466 */ |
0 | 5467 } |
5468 /* Refilling unqueued packet */ | |
5469 else | |
5470 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5471 /* |
0 | 5472 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
|
5473 */ |
0 | 5474 /* Grab next packet */ |
5475 bytes_returned = GetMoreData( | |
5476 ALmixer_Channel_List[i].almixer_data, | |
5477 unqueued_buffer_id); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5478 /* |
0 | 5479 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
|
5480 */ |
0 | 5481 } |
5482 /* Another error check */ | |
5483 /* | |
5484 if(bytes_returned <= 0) | |
5485 */ | |
5486 if(0 == bytes_returned) | |
5487 { | |
5488 fprintf(stderr, "??????????ERROR\n"); | |
5489 ALmixer_SetError("Could not loop because after rewind, no data could be retrieved"); | |
5490 /* Problem occurred...not sure what to do */ | |
5491 /* Go to next loop? */ | |
5492 error_flag--; | |
5493 /* Set the eof flag to force a quit so | |
5494 * we don't get stuck in an infinite loop | |
5495 */ | |
5496 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5497 continue; | |
5498 } | |
5499 /* We made it to the end. We still need | |
5500 * to BufferData, so let this branch | |
5501 * fall into the next piece of | |
5502 * code below which will handle that | |
5503 */ | |
5504 | |
5505 | |
5506 } /* END loop check */ | |
5507 else | |
5508 { | |
5509 /* No more loops to do. | |
5510 * EOF flag should be set. | |
5511 * Just go to next loop and | |
5512 * let things be handled correctly | |
5513 * in future update calls | |
5514 */ | |
1 | 5515 /* |
0 | 5516 fprintf(stderr, "SHOULD BE EOF\n"); |
5517 | |
5518 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
1 | 5519 */ |
0 | 5520 continue; |
5521 } | |
5522 } /* END if bytes_returned == 0 */ | |
5523 /********* Possible trouble point. I might be queueing empty buffers on the mac. | |
5524 * This check doesn't say if the buffer is valid. Only the EOF assumption is a clue at this point | |
5525 */ | |
5526 /* Fall here */ | |
5527 /* Everything is normal. We aren't | |
5528 * at an EOF, but need to simply | |
5529 * queue more data. The data is already checked for good, | |
5530 * so queue it up */ | |
5531 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5532 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5533 { | |
5534 /* Keep count of how many buffers we have | |
5535 * to queue so we can return the value | |
5536 */ | |
5537 retval++; | |
1 | 5538 /* |
0 | 5539 fprintf(stderr, "NOT_EOF???, about to Queue more data for num_buffers (%d) < max_queue (%d)\n", |
5540 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5541 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5542 */ |
0 | 5543 alSourceQueueBuffers( |
5544 ALmixer_Channel_List[i].alsource, | |
5545 1, | |
5546 &ALmixer_Channel_List[i].almixer_data->buffer[ | |
5547 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5548 ); | |
5549 if((error = alGetError()) != AL_NO_ERROR) | |
5550 { | |
5551 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
|
5552 alGetString(error)); |
0 | 5553 } |
5554 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5555 * which buffer to show during callbacks (for things like | |
5556 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5557 * data structure. This code will be called only if | |
5558 * "access_data" was set, indicated by whether the queue is NULL. | |
5559 */ | |
5560 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5561 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5562 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5563 // fprintf(stderr, "56d: CircularQueue_PushBack.\n"); |
0 | 5564 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5565 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5566 ALmixer_Channel_List[i].almixer_data->buffer[ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5567 ); | |
5568 if(0 == queue_ret_flag) | |
5569 { | |
5570 fprintf(stderr, "56aSerious internal error: CircularQueue could not push into queue.\n"); | |
5571 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5572 } | |
5573 /* | |
5574 else | |
5575 { | |
5576 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5577 } | |
5578 */ | |
5579 } | |
5580 } | |
5581 /* for processed > 0 */ | |
5582 else | |
5583 { | |
5584 /* Keep count of how many buffers we have | |
5585 * to queue so we can return the value | |
5586 */ | |
5587 retval++; | |
5588 /* | |
5589 fprintf(stderr, "NOT_EOF, about to Queue more data for filled max_queue (%d)\n", | |
5590 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
5591 */ | |
5592 alSourceQueueBuffers( | |
5593 ALmixer_Channel_List[i].alsource, | |
5594 1, &unqueued_buffer_id); | |
5595 if((error = alGetError()) != AL_NO_ERROR) | |
5596 { | |
5597 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
|
5598 alGetString(error) ); |
0 | 5599 error_flag--; |
5600 continue; | |
5601 } | |
5602 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5603 * which buffer to show during callbacks (for things like | |
5604 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5605 * data structure. This code will be called only if | |
5606 * "access_data" was set, indicated by whether the queue is NULL. | |
5607 */ | |
5608 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5609 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5610 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5611 // fprintf(stderr, "56e: CircularQueue_PushBack.\n"); |
0 | 5612 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5613 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5614 unqueued_buffer_id | |
5615 ); | |
5616 if(0 == queue_ret_flag) | |
5617 { | |
5618 fprintf(stderr, "56bSerious internal error: CircularQueue could not push into queue.\n"); | |
5619 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5620 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5621 #if 0 |
0 | 5622 else |
5623 { | |
5624 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5625 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5626 #endif |
0 | 5627 } |
5628 } | |
5629 /* If we used an available buffer queue, | |
5630 * then we need to update the number of them in use | |
5631 */ | |
5632 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5633 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5634 { | |
5635 /* Increment the number of buffers in use */ | |
5636 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use++; | |
5637 } | |
5638 /* Might want to check state */ | |
5639 /* In case the playback stopped, | |
5640 * we need to resume */ | |
1 | 5641 #if 1 |
5642 /* Try not refetching the state here because I'm getting a duplicate | |
5643 buffer playback (hiccup) */ | |
0 | 5644 alGetSourcei( |
5645 ALmixer_Channel_List[i].alsource, | |
5646 AL_SOURCE_STATE, &state | |
5647 ); | |
1 | 5648 if((error = alGetError()) != AL_NO_ERROR) |
5649 { | |
5650 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
|
5651 alGetString(error)); |
1 | 5652 } |
5653 /* Get the number of buffers processed | |
5654 */ | |
5655 alGetSourcei( | |
5656 ALmixer_Channel_List[i].alsource, | |
5657 AL_BUFFERS_PROCESSED, | |
5658 &buffers_processed | |
5659 ); | |
5660 if((error = alGetError()) != AL_NO_ERROR) | |
5661 { | |
5662 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
|
5663 alGetString(error)); |
1 | 5664 } |
5665 #endif | |
0 | 5666 if(AL_STOPPED == state) |
5667 { | |
1 | 5668 /* |
0 | 5669 fprintf(stderr, "Resuming in not eof\n"); |
1 | 5670 */ |
5671 /* Okay, here's another lately discovered problem: | |
5672 * I can't find it in the spec, but for at least some of the | |
5673 * implementations, if I call play on a stopped source that | |
5674 * has processed buffers, all those buffers get marked as unprocessed | |
5675 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5676 * processed, on resume, the earlier 24 buffers will get replayed, | |
5677 * causing a "hiccup" like sound in the playback. | |
5678 * To avoid this, I must unqueue all processed buffers before | |
5679 * calling play. But to complicate things, I need to worry about resyncing | |
5680 * the circular queue with this since I designed this thing | |
5681 * with some correlation between the two. However, I might | |
5682 * have already handled this, so I will try writing this code without | |
5683 * syncing for now. | |
5684 * There is currently an assumption that a buffer | |
5685 * was queued above so I actually have something | |
5686 * to play. | |
5687 */ | |
5688 ALint temp_count; | |
5689 /* | |
5690 fprintf(stderr, "STOPPED2, need to clear processed, status is:\n"); | |
5691 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5692 */ | |
5693 | |
5694 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5695 { | |
5696 alSourceUnqueueBuffers( | |
5697 ALmixer_Channel_List[i].alsource, | |
5698 1, &unqueued_buffer_id | |
5699 ); | |
5700 if((error = alGetError()) != AL_NO_ERROR) | |
5701 { | |
5702 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
|
5703 alGetString(error)); |
1 | 5704 error_flag--; |
5705 } | |
5706 } | |
5707 /* | |
5708 fprintf(stderr, "After unqueue clear...:\n"); | |
5709 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5710 */ | |
5711 | |
5712 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5713 if((error = alGetError()) != AL_NO_ERROR) | |
5714 { | |
5715 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
|
5716 alGetString(error)); |
1 | 5717 } |
0 | 5718 } |
5719 continue; | |
5720 } /* END if( ! eof) */ | |
5721 /* We have hit EOF in the SDL_Sound sample and there | |
5722 * are no more loops. However, there may still be | |
5723 * buffers in the OpenAL queue which still need to | |
5724 * be played out. The following body of code will | |
5725 * determine if play is still happening or | |
5726 * initiate the stop/cleanup sequenece. | |
5727 */ | |
5728 else | |
5729 { | |
5730 /* Let's continue to remove the used up | |
5731 * buffers as they come in. */ | |
5732 if(buffers_processed > 0) | |
5733 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5734 ALint temp_count; |
0 | 5735 /* Do as a for-loop because I don't want |
5736 * to have to create an array for the | |
5737 * unqueued_buffer_id's | |
5738 */ | |
5739 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5740 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5741 /* |
0 | 5742 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
|
5743 */ |
0 | 5744 alSourceUnqueueBuffers( |
5745 ALmixer_Channel_List[i].alsource, | |
5746 1, &unqueued_buffer_id | |
5747 ); | |
5748 if((error = alGetError()) != AL_NO_ERROR) | |
5749 { | |
5750 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
|
5751 alGetString(error)); |
0 | 5752 } |
5753 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5754 /* |
0 | 5755 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
|
5756 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5757 |
0 | 5758 /* Need to update counts since we removed everything. |
5759 * If we don't update the counts here, we end up in the | |
5760 * "Shouldn't be here section, but maybe it's okay due to race conditions" | |
5761 */ | |
5762 alGetSourcei( | |
5763 ALmixer_Channel_List[i].alsource, | |
5764 AL_BUFFERS_QUEUED, &buffers_still_queued | |
5765 ); | |
5766 if((error = alGetError()) != AL_NO_ERROR) | |
5767 { | |
5768 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
|
5769 alGetString(error)); |
0 | 5770 } |
5771 /* Get the number of buffers processed | |
5772 * so we know if we need to refill | |
5773 */ | |
5774 alGetSourcei( | |
5775 ALmixer_Channel_List[i].alsource, | |
5776 AL_BUFFERS_PROCESSED, &buffers_processed | |
5777 ); | |
5778 if((error = alGetError()) != AL_NO_ERROR) | |
5779 { | |
5780 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
|
5781 alGetString(error)); |
0 | 5782 } |
5783 } | |
5784 | |
5785 | |
5786 /* Else if buffers_processed == 0 | |
5787 * and buffers_still_queued == 0. | |
5788 * then we check to see if the source | |
5789 * is still playing. Quit if stopped | |
5790 * We shouldn't need to worry about | |
5791 * looping because that should have | |
5792 * been handled above. | |
5793 */ | |
5794 if(0 == buffers_still_queued) | |
5795 { | |
5796 /* Make sure playback has stopped before | |
5797 * we shutdown. | |
5798 */ | |
5799 alGetSourcei( | |
5800 ALmixer_Channel_List[i].alsource, | |
5801 AL_SOURCE_STATE, &state | |
5802 ); | |
5803 if((error = alGetError()) != AL_NO_ERROR) | |
5804 { | |
5805 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
|
5806 alGetString(error)); |
0 | 5807 } |
5808 if(AL_STOPPED == state) | |
5809 { | |
5810 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use = 0; | |
5811 /* Playback has ended. | |
5812 * Loop if necessary, or launch callback | |
5813 * and clear channel (or clear channel and | |
5814 * then launch callback?) | |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
5815 * Update: Need to do callback first because I reference the mixer_data and source |
0 | 5816 */ |
10
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
5817 |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
5818 /* Launch callback */ |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
5819 Invoke_Channel_Done_Callback(i, AL_TRUE); |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
5820 |
0 | 5821 Clean_Channel(i); |
5822 /* Subtract counter */ | |
5823 Is_Playing_global--; | |
5824 | |
5825 | |
5826 /* We're done for this loop. | |
5827 * Go to next channel | |
5828 */ | |
5829 continue; | |
5830 } | |
5831 } /* End end-playback */ | |
5832 else | |
5833 { | |
5834 /* Need to run out buffer */ | |
5835 #if 1 | |
5836 /* Might want to check state */ | |
5837 /* In case the playback stopped, | |
5838 * we need to resume */ | |
5839 alGetSourcei( | |
5840 ALmixer_Channel_List[i].alsource, | |
5841 AL_SOURCE_STATE, &state | |
5842 ); | |
5843 if((error = alGetError()) != AL_NO_ERROR) | |
5844 { | |
5845 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
|
5846 alGetString(error)); |
0 | 5847 } |
5848 if(AL_STOPPED == state) | |
5849 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5850 /* |
0 | 5851 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
|
5852 */ |
1 | 5853 /* |
0 | 5854 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 5855 */ |
0 | 5856 /* Rather than force unqueuing the buffer, let's see if |
5857 * setting the buffer to none works (the OpenAL 1.0 | |
5858 * Reference Annotation suggests this should work). | |
5859 */ | |
5860 alSourcei(ALmixer_Channel_List[i].alsource, | |
5861 AL_BUFFER, AL_NONE); | |
5862 /* | |
5863 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5864 */ | |
5865 /* This doesn't work because in some cases, I think | |
5866 * it causes the sound to be replayed | |
5867 */ | |
5868 /* | |
5869 fprintf(stderr, "Resuming in eof (trying to run out buffers\n"); | |
5870 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5871 */ | |
5872 } | |
5873 #endif | |
5874 } /* End trap section */ | |
5875 } /* End POST-EOF use-up buffer section */ | |
5876 } /* END Streamed section */ | |
5877 } /* END channel in use */ | |
5878 } /* END for-loop for each channel */ | |
5879 | |
5880 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
5881 alcProcessContext(alcGetCurrentContext()); | |
5882 if((error = alGetError()) != AL_NO_ERROR) | |
5883 { | |
5884 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
|
5885 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5886 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5887 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5888 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5889 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5890 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5891 #endif |
0 | 5892 /* Return the number of errors */ |
5893 if(error_flag < 0) | |
5894 { | |
5895 return error_flag; | |
5896 } | |
5897 /* Return the number of buffers that were queued */ | |
5898 return retval; | |
5899 } | |
5900 | |
5901 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
5902 /* 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
|
5903 static void my_dummy_audio_callback(void* userdata, ALbyte* stream, int len) |
0 | 5904 { |
5905 } | |
5906 #endif | |
5907 | |
5908 | |
5909 | |
5910 | |
5911 #ifdef ENABLE_ALMIXER_THREADS | |
5912 /* We might need threads. We | |
5913 * must constantly poll OpenAL to find out | |
5914 * if sound is being streamed, if play has | |
5915 * ended, etc. Without threads, this must | |
5916 * be explicitly done by the user. | |
5917 * We could try to do it for them if we | |
5918 * finish the threads. | |
5919 */ | |
5920 | |
5921 static int Stream_Data_Thread_Callback(void* data) | |
5922 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5923 ALint retval; |
0 | 5924 |
5925 while(ALmixer_Initialized) | |
5926 { | |
5927 retval = Update_ALmixer(data); | |
5928 /* 0 means that nothing needed updating and | |
5929 * the function returned quickly | |
5930 */ | |
5931 if(0 == retval) | |
5932 { | |
5933 /* Let's be nice and make the thread sleep since | |
5934 * little work was done in update | |
5935 */ | |
5936 /* Make sure times are multiples of 10 | |
5937 * for optimal performance and accuracy in Linux | |
5938 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5939 ALmixer_Delay(10); |
0 | 5940 } |
5941 else | |
5942 { | |
5943 /* 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
|
5944 ALmixer_Delay(0); |
0 | 5945 } |
5946 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5947 /* |
0 | 5948 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
|
5949 */ |
0 | 5950 return 0; |
5951 } | |
5952 #endif /* End of ENABLE_ALMIXER_THREADS */ | |
5953 | |
5954 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5955 /* 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
|
5956 * 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
|
5957 * so SDL_mixer porting people beware. |
0 | 5958 * Warning: SDL_QuitSubSystem(SDL_INIT_AUDIO) is called which |
5959 * means the SDL audio system will be disabled. It will not | |
5960 * be restored (in case SDL is not actually being used) so | |
5961 * the user will need to restart it if they need it after | |
5962 * OpenAL shuts down. | |
5963 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5964 ALboolean ALmixer_Init(ALuint frequency, ALint num_sources, ALuint refresh) |
0 | 5965 { |
5966 ALCdevice* dev; | |
5967 ALCcontext* context; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5968 ALint i; |
0 | 5969 ALenum error; |
5970 ALuint* source; | |
5971 | |
5972 #ifdef USING_LOKI_AL_DIST | |
5973 /* The Loki dist requires that I set both the | |
5974 * device and context frequency values separately | |
5975 */ | |
5976 /* Hope this won't overflow */ | |
5977 char device_string[256]; | |
5978 #endif | |
5979 | |
5980 /* (Venting frustration) Damn it! Nobody bothered | |
5981 * documenting how you're supposed to use an attribute | |
5982 * list. In fact, the not even the Loki test program | |
5983 * writers seem to know because they use it inconsistently. | |
5984 * For example, how do you terminate that attribute list? | |
5985 * The Loki test code does it 3 different ways. They | |
5986 * set the last value to 0, or they set it to ALC_INVALID, | |
5987 * or they set two final values: ALC_INVALID, 0 | |
5988 * In Loki, 0 and ALC_INVALID happen to be the same, | |
5989 * but with Creative Labs ALC_INVALID is -1. | |
5990 * So something's going to break. Loki's source | |
5991 * code says to terminate with ALC_INVALID. But I | |
5992 * don't know if that's really true, or it happens | |
5993 * to be a coinicidence because it's defined to 0. | |
5994 * Creative provides no source code, so I can't look at how | |
5995 * they terminate it. | |
5996 * So this is really, really ticking me off... | |
5997 * For now, I'm going to use ALC_INVALID. | |
5998 * (Update...after further review of the API spec, | |
5999 * it seems that a NULL terminated string is the correct | |
6000 * termination value to use, so 0 it is.) | |
6001 */ | |
6002 #if 0 | |
6003 ALint attrlist[] = { | |
6004 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6005 /* Don't know anything about these values. | |
6006 * Trust defaults? */ | |
6007 /* Supposed to be the refresh rate in Hz. | |
6008 * I think 15-120 are supposed to be good | |
6009 * values. Though I haven't gotten any effect except | |
6010 * for one strange instance on a Mac. But it was | |
6011 * unrepeatable. | |
6012 */ | |
6013 #if 0 | |
6014 ALC_REFRESH, 15, | |
6015 #endif | |
6016 /* Sync requires a alcProcessContext() call | |
6017 * for every cycle. By default, this is | |
6018 * not used and the value is AL_FALSE | |
6019 * because it will probably perform | |
6020 * pretty badly for me. | |
6021 */ | |
6022 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6023 ALC_SYNC, AL_TRUE, | |
6024 #else | |
6025 ALC_SYNC, AL_FALSE, | |
6026 #endif | |
6027 /* Looking at the API spec, it implies | |
6028 * that the list be a NULL terminated string | |
6029 * so it's probably not safe to use ALC_INVALID | |
6030 */ | |
6031 /* | |
6032 ALC_INVALID }; | |
6033 */ | |
6034 '\0'}; | |
6035 #endif | |
6036 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6037 * However, if no value is specified, I don't | |
6038 * want it in the list so I can get the OpenAL defaults | |
6039 */ | |
6040 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6041 ALsizei current_attrlist_index = 0; |
0 | 6042 |
6043 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6044 /* More problems: I'm getting bit by endian/signedness issues on | |
6045 * different platforms. I can find the endianess easily enough, | |
6046 * but I don't know how to determine what the correct signedness | |
6047 * is (if such a thing exists). I do know that if I try using | |
6048 * unsigned on OSX with an originally signed sample, I get | |
6049 * distortion. However, I don't have any native unsigned samples | |
6050 * to test. But I'm assuming that the platform must be in the | |
6051 * correct signedness no matter what. | |
6052 * I can either assume everybody is signed, or I can try to | |
6053 * determine the value. If I try to determine the values, | |
6054 * I think my only ability to figure it out will be to open | |
6055 * SDL_Audio, and read what the obtained settings were. | |
6056 * Then shutdown everything. However, I don't even know how | |
6057 * reliable this is. | |
6058 * Update: I think I resolved the issues...forgot to update | |
6059 * these comments when it happened. I should check the revision control | |
6060 * log... Anyway, I think the issue was partly related to me not | |
6061 * doing something correctly with the AudioInfo or some kind | |
6062 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6063 * revision control, I think I might have assumed that SDL_Sound would | |
6064 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6065 * and had to fill one out myself. | |
6066 */ | |
6067 SDL_AudioSpec desired; | |
6068 SDL_AudioSpec obtained; | |
6069 #endif | |
6070 | |
6071 | |
6072 /* Make sure ALmixer isn't already initialized */ | |
6073 if(ALmixer_Initialized) | |
6074 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6075 return AL_FALSE; |
0 | 6076 } |
6077 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6078 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6079 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6080 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6081 /* 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
|
6082 /* 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
|
6083 * 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
|
6084 * This is not actually a leak. |
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 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6087 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6088 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6089 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6090 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6091 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6092 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6093 } |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6094 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6095 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6096 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6097 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
|
6098 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
|
6099 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6100 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6101 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6102 |
0 | 6103 /* Set the defaults */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6104 /* |
0 | 6105 attrlist[0] = ALC_FREQUENCY; |
6106 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6107 attrlist[2] = ALC_SYNC; | |
6108 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6109 attrlist[3] = ALC_TRUE; | |
6110 #else | |
6111 attrlist[3] = ALC_FALSE; | |
6112 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6113 */ |
0 | 6114 /* Set frequency value if it is not 0 */ |
6115 if(0 != frequency) | |
6116 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6117 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6118 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6119 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6120 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6121 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6122 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6123 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6124 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6125 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6126 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6127 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6128 #endif |
0 | 6129 |
6130 /* If the user specifies a refresh value, | |
6131 * make room for it | |
6132 */ | |
6133 if(0 != refresh) | |
6134 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6135 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
|
6136 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6137 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6138 current_attrlist_index++; |
0 | 6139 } |
6140 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6141 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6142 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6143 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6144 |
0 | 6145 /* Initialize SDL_Sound */ |
6146 if(! Sound_Init() ) | |
6147 { | |
6148 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6149 return AL_FALSE; |
0 | 6150 } |
6151 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6152 /* Here is the paranoid check that opens | |
6153 * SDL audio in an attempt to find the correct | |
6154 * system values. | |
6155 */ | |
6156 /* Doesn't have to be the actual value I think | |
6157 * (as long as it doesn't influence format, in | |
6158 * which case I'm probably screwed anyway because OpenAL | |
6159 * may easily choose to do something else). | |
6160 */ | |
6161 desired.freq = 44100; | |
6162 desired.channels = 2; | |
6163 desired.format = AUDIO_S16SYS; | |
6164 desired.callback = my_dummy_audio_callback; | |
6165 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6166 { | |
6167 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6168 /* Now to get really paranoid, we should probably | |
6169 * also assume that the 8bit format is also the | |
6170 * same sign type and set that value | |
6171 */ | |
6172 if(AUDIO_S16SYS == obtained.format) | |
6173 { | |
6174 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6175 } | |
6176 /* Should be AUDIO_U16SYS */ | |
6177 else | |
6178 { | |
6179 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6180 } | |
6181 SDL_CloseAudio(); | |
6182 } | |
6183 else | |
6184 { | |
6185 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6186 */ | |
6187 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6188 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6189 } | |
6190 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6191 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6192 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6193 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
6194 * causes OpenAL and SMPEG to conflict. For some reason | |
6195 * if SDL_Init on audio is active, then all the SMPEG | |
6196 * decoded sound comes out silent. Unfortunately, | |
6197 * Sound_Init() invokes SDL_Init on audio. I'm | |
6198 * not sure why it actually needs it... | |
6199 * But we'll attempt to disable it here after the | |
6200 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
6201 */ | |
6202 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6203 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6204 |
0 | 6205 /* I'm told NULL will call the default string |
6206 * and hopefully do the right thing for each platform | |
6207 */ | |
6208 /* | |
6209 dev = alcOpenDevice( NULL ); | |
6210 */ | |
6211 /* Now I'm told I need to set both the device and context | |
6212 * to have the same sampling rate, so I must pass a string | |
6213 * to OpenDevice(). I don't know how portable these strings are. | |
6214 * I don't even know if the format for strings is | |
6215 * compatible | |
6216 * From the testattrib.c in the Loki test section | |
6217 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
6218 */ | |
6219 | |
6220 #ifdef USING_LOKI_AL_DIST | |
6221 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
6222 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
6223 #else | |
6224 dev = alcOpenDevice( NULL ); | |
6225 #endif | |
6226 if(NULL == dev) | |
6227 { | |
6228 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
|
6229 return AL_FALSE; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6232 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6233 /* 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
|
6234 /* 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
|
6235 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6236 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6237 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6238 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6239 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
|
6240 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6241 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
|
6242 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6243 #endif |
0 | 6244 |
6245 context = alcCreateContext(dev, attrlist); | |
6246 if(NULL == context) | |
6247 { | |
6248 ALmixer_SetError("Cannot create a context OpenAL"); | |
6249 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6250 return AL_FALSE; |
0 | 6251 } |
6252 | |
6253 | |
6254 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6255 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6256 * According to Garin Hiebert, this is actually an inconsistency | |
6257 * in the Loki version. The function should return a boolean. | |
6258 * instead of ALC_NO_ERROR. Garin suggested I check via | |
6259 * alcGetError(). | |
6260 */ | |
6261 /* clear the error */ | |
6262 alcGetError(dev); | |
6263 alcMakeContextCurrent(context); | |
6264 | |
6265 error = alcGetError(dev); | |
6266 if( (ALC_NO_ERROR != error) ) | |
6267 { | |
6268 ALmixer_SetError("Could not MakeContextCurrent"); | |
6269 alcDestroyContext(context); | |
6270 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6271 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6272 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6273 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6274 /* 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
|
6275 * 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
|
6276 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6277 * 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
|
6278 * 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
|
6279 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6280 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6281 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6282 ALmixer_Frequency_global = frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6283 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6284 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6285 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
|
6286 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6287 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
|
6288 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6289 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6290 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6291 |
0 | 6292 #if 0 |
6293 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
6294 if(alcGetCurrentContext() != context) | |
6295 { | |
6296 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6297 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6298 * I think this is a bug in the OpenAL implementation. | |
6299 */ | |
6300 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
6301 | |
6302 fprintf(stderr, "Making context current\n"); | |
6303 #ifndef __APPLE__ | |
6304 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
6305 #else | |
6306 if(!alcMakeContextCurrent(context)) | |
6307 #endif | |
6308 { | |
6309 ALmixer_SetError("Could not MakeContextCurrent"); | |
6310 alcDestroyContext(context); | |
6311 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6312 return AL_FALSE; |
0 | 6313 } |
6314 } | |
6315 #endif | |
6316 | |
6317 | |
6318 /* #endif */ | |
6319 /* Saw this in the README with the OS X OpenAL distribution. | |
6320 * It looked interesting and simple, so I thought I might | |
6321 * try it out. | |
6322 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
6323 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
6324 * Audio format, the audio data passed to the | |
6325 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
6326 * usage by removing an audio data conversion | |
6327 * (per source) at render timem at the expense of a larger memory footprint. | |
6328 * | |
6329 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
6330 * setting will be applied to all subsequent | |
6331 * calls to alBufferData(). | |
6332 */ | |
6333 #ifdef __APPLE__ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6334 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6335 #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
|
6336 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6337 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6338 #endif |
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 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
|
6341 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6342 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
|
6343 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6344 if(0 != convert_data_enum) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6345 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6346 alEnable(convert_data_enum); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6347 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6348 if( (AL_NO_ERROR != alGetError()) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6349 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6350 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
|
6351 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
|
6352 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6353 |
0 | 6354 #endif |
6355 | |
6356 | |
6357 | |
6358 | |
6359 ALmixer_Initialized = 1; | |
6360 | |
6361 if(num_sources <= 0) | |
6362 { | |
6363 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
6364 } | |
6365 else | |
6366 { | |
6367 Number_of_Channels_global = num_sources; | |
6368 } | |
6369 Number_of_Reserve_Channels_global = 0; | |
6370 Is_Playing_global = 0; | |
6371 /* Set to Null in case system quit and was reinitialized */ | |
6372 Channel_Done_Callback = NULL; | |
6373 Channel_Done_Callback_Userdata = NULL; | |
6374 Channel_Data_Callback = NULL; | |
1 | 6375 Channel_Data_Callback_Userdata = NULL; |
0 | 6376 |
6377 /* Allocate memory for the list of channels */ | |
6378 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
6379 if(NULL == ALmixer_Channel_List) | |
6380 { | |
6381 ALmixer_SetError("Out of Memory for Channel List"); | |
6382 alcDestroyContext(context); | |
6383 alcCloseDevice(dev); | |
6384 ALmixer_Initialized = 0; | |
6385 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6386 return AL_FALSE; |
0 | 6387 } |
6388 | |
6389 /* Allocate memory for the list of sources that map to the channels */ | |
6390 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
6391 if(NULL == Source_Map_List) | |
6392 { | |
6393 ALmixer_SetError("Out of Memory for Source Map List"); | |
6394 free(ALmixer_Channel_List); | |
6395 alcDestroyContext(context); | |
6396 alcCloseDevice(dev); | |
6397 ALmixer_Initialized = 0; | |
6398 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6399 return AL_FALSE; |
0 | 6400 } |
6401 | |
6402 /* Create array that will hold the sources */ | |
6403 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
6404 if(NULL == source) | |
6405 { | |
6406 ALmixer_SetError("Out of Memory for sources"); | |
6407 free(Source_Map_List); | |
6408 free(ALmixer_Channel_List); | |
6409 alcDestroyContext(context); | |
6410 alcCloseDevice(dev); | |
6411 ALmixer_Initialized = 0; | |
6412 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6413 return AL_FALSE; |
0 | 6414 } |
6415 | |
6416 /* Clear the error state */ | |
6417 alGetError(); | |
6418 /* Generate the OpenAL sources */ | |
6419 alGenSources(Number_of_Channels_global, source); | |
6420 if( (error=alGetError()) != AL_NO_ERROR) | |
6421 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6422 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 6423 free(ALmixer_Channel_List); |
6424 free(Source_Map_List); | |
6425 alcDestroyContext(context); | |
6426 alcCloseDevice(dev); | |
6427 ALmixer_Initialized = 0; | |
6428 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6429 return AL_FALSE; |
0 | 6430 } |
6431 | |
6432 /* Initialize each channel and associate one source to one channel */ | |
6433 for(i=0; i<Number_of_Channels_global; i++) | |
6434 { | |
6435 if(0 == source[i]) | |
6436 { | |
6437 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"); | |
6438 } | |
6439 | |
6440 Init_Channel(i); | |
6441 /* Keeping the source allocation out of the Init function | |
6442 * in case I want to reuse the Init | |
6443 * function for resetting data | |
6444 */ | |
6445 ALmixer_Channel_List[i].alsource = source[i]; | |
6446 /* Now also keep a copy of the source to channel mapping | |
6447 * in case we need to look up a channel from the source | |
6448 * instead of a source from a channel | |
6449 */ | |
6450 Source_Map_List[i].source = source[i]; | |
6451 Source_Map_List[i].channel = i; | |
6452 /* Clean the channel because there are some things that need to | |
6453 * be done that can't happen until the source is set | |
6454 */ | |
6455 Clean_Channel(i); | |
6456 } | |
6457 | |
6458 /* The Source_Map_List must be sorted by source for binary searches | |
6459 */ | |
6460 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
6461 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6462 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6463 ALmixer_OutputDecoders(); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6464 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6465 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6466 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6467 if(NULL == s_simpleLock) |
0 | 6468 { |
6469 /* SDL sets the error message already? */ | |
6470 free(source); | |
6471 free(ALmixer_Channel_List); | |
6472 free(Source_Map_List); | |
6473 alcDestroyContext(context); | |
6474 alcCloseDevice(dev); | |
6475 ALmixer_Initialized = 0; | |
6476 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6477 return AL_FALSE; |
0 | 6478 } |
6479 | |
6480 | |
6481 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
6482 if(NULL == Stream_Thread_global) | |
6483 { | |
6484 /* 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
|
6485 SDL_DestroyMutex(s_simpleLock); |
0 | 6486 free(source); |
6487 free(ALmixer_Channel_List); | |
6488 free(Source_Map_List); | |
6489 alcDestroyContext(context); | |
6490 alcCloseDevice(dev); | |
6491 ALmixer_Initialized = 0; | |
6492 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6493 return AL_FALSE; |
0 | 6494 } |
6495 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6496 /* |
0 | 6497 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6498 */ |
0 | 6499 #endif /* End of ENABLE_ALMIXER_THREADS */ |
6500 | |
6501 /* We don't need this array any more because all the sources | |
6502 * are connected to channels | |
6503 */ | |
6504 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6505 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6506 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6507 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6508 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6509 ALboolean ALmixer_InitContext(ALuint frequency, ALuint refresh) |
0 | 6510 { |
6511 ALCdevice* dev; | |
6512 ALCcontext* context; | |
6513 ALCenum error; | |
6514 | |
6515 #ifdef USING_LOKI_AL_DIST | |
6516 /* The Loki dist requires that I set both the | |
6517 * device and context frequency values separately | |
6518 */ | |
6519 /* Hope this won't overflow */ | |
6520 char device_string[256]; | |
6521 #endif | |
6522 | |
6523 /* (Venting frustration) Damn it! Nobody bothered | |
6524 * documenting how you're supposed to use an attribute | |
6525 * list. In fact, the not even the Loki test program | |
6526 * writers seem to know because they use it inconsistently. | |
6527 * For example, how do you terminate that attribute list? | |
6528 * The Loki test code does it 3 different ways. They | |
6529 * set the last value to 0, or they set it to ALC_INVALID, | |
6530 * or they set two final values: ALC_INVALID, 0 | |
6531 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6532 * but with Creative Labs ALC_INVALID is -1. | |
6533 * So something's going to break. Loki's source | |
6534 * code says to terminate with ALC_INVALID. But I | |
6535 * don't know if that's really true, or it happens | |
6536 * to be a coinicidence because it's defined to 0. | |
6537 * Creative provides no source code, so I can't look at how | |
6538 * they terminate it. | |
6539 * So this is really, really ticking me off... | |
6540 * For now, I'm going to use ALC_INVALID. | |
6541 * (Update...after further review of the API spec, | |
6542 * it seems that a NULL terminated string is the correct | |
6543 * termination value to use, so 0 it is.) | |
6544 */ | |
6545 #if 0 | |
6546 ALint attrlist[] = { | |
6547 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6548 /* Don't know anything about these values. | |
6549 * Trust defaults? */ | |
6550 /* Supposed to be the refresh rate in Hz. | |
6551 * I think 15-120 are supposed to be good | |
6552 * values. Though I haven't gotten any effect except | |
6553 * for one strange instance on a Mac. But it was | |
6554 * unrepeatable. | |
6555 */ | |
6556 #if 0 | |
6557 ALC_REFRESH, 15, | |
6558 #endif | |
6559 /* Sync requires a alcProcessContext() call | |
6560 * for every cycle. By default, this is | |
6561 * not used and the value is AL_FALSE | |
6562 * because it will probably perform | |
6563 * pretty badly for me. | |
6564 */ | |
6565 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6566 ALC_SYNC, AL_TRUE, | |
6567 #else | |
6568 ALC_SYNC, AL_FALSE, | |
6569 #endif | |
6570 /* Looking at the API spec, it implies | |
6571 * that the list be a NULL terminated string | |
6572 * so it's probably not safe to use ALC_INVALID | |
6573 */ | |
6574 /* | |
6575 ALC_INVALID }; | |
6576 */ | |
6577 '\0'}; | |
6578 #endif | |
6579 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6580 * However, if no value is specified, I don't | |
6581 * want it in the list so I can get the OpenAL defaults | |
6582 */ | |
6583 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6584 ALsizei current_attrlist_index = 0; |
0 | 6585 |
6586 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6587 /* More problems: I'm getting bit by endian/signedness issues on | |
6588 * different platforms. I can find the endianess easily enough, | |
6589 * but I don't know how to determine what the correct signedness | |
6590 * is (if such a thing exists). I do know that if I try using | |
6591 * unsigned on OSX with an originally signed sample, I get | |
6592 * distortion. However, I don't have any native unsigned samples | |
6593 * to test. But I'm assuming that the platform must be in the | |
6594 * correct signedness no matter what. | |
6595 * I can either assume everybody is signed, or I can try to | |
6596 * determine the value. If I try to determine the values, | |
6597 * I think my only ability to figure it out will be to open | |
6598 * SDL_Audio, and read what the obtained settings were. | |
6599 * Then shutdown everything. However, I don't even know how | |
6600 * reliable this is. | |
6601 * Update: I think I resolved the issues...forgot to update | |
6602 * these comments when it happened. I should check the revision control | |
6603 * log... Anyway, I think the issue was partly related to me not | |
6604 * doing something correctly with the AudioInfo or some kind | |
6605 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6606 * revision control, I think I might have assumed that SDL_Sound would | |
6607 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6608 * and had to fill one out myself. | |
6609 */ | |
6610 SDL_AudioSpec desired; | |
6611 SDL_AudioSpec obtained; | |
6612 #endif | |
6613 | |
6614 | |
6615 | |
6616 | |
6617 /* Make sure ALmixer isn't already initialized */ | |
6618 if(ALmixer_Initialized) | |
6619 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6620 return AL_FALSE; |
0 | 6621 } |
6622 | |
6623 /* Set the defaults */ | |
6624 attrlist[0] = ALC_FREQUENCY; | |
6625 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6626 attrlist[2] = ALC_SYNC; | |
6627 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6628 attrlist[3] = ALC_TRUE; | |
6629 #else | |
6630 attrlist[3] = ALC_FALSE; | |
6631 #endif | |
6632 /* Set frequency value if it is not 0 */ | |
6633 if(0 != frequency) | |
6634 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6635 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6636 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6637 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6638 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6639 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6640 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6641 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6642 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6643 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6644 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6645 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6646 #endif |
0 | 6647 |
6648 /* If the user specifies a refresh value, | |
6649 * make room for it | |
6650 */ | |
6651 if(0 != refresh) | |
6652 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6653 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
|
6654 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6655 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6656 current_attrlist_index++; |
0 | 6657 } |
6658 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6659 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6660 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6661 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6662 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6663 |
0 | 6664 /* Initialize SDL_Sound */ |
6665 if(! Sound_Init() ) | |
6666 { | |
6667 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6668 return AL_FALSE; |
0 | 6669 } |
6670 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6671 /* Here is the paranoid check that opens | |
6672 * SDL audio in an attempt to find the correct | |
6673 * system values. | |
6674 */ | |
6675 /* Doesn't have to be the actual value I think | |
6676 * (as long as it doesn't influence format, in | |
6677 * which case I'm probably screwed anyway because OpenAL | |
6678 * may easily choose to do something else). | |
6679 */ | |
6680 desired.freq = 44100; | |
6681 desired.channels = 2; | |
6682 desired.format = AUDIO_S16SYS; | |
6683 desired.callback = my_dummy_audio_callback; | |
6684 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6685 { | |
6686 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6687 /* Now to get really paranoid, we should probably | |
6688 * also assume that the 8bit format is also the | |
6689 * same sign type and set that value | |
6690 */ | |
6691 if(AUDIO_S16SYS == obtained.format) | |
6692 { | |
6693 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6694 } | |
6695 /* Should be AUDIO_U16SYS */ | |
6696 else | |
6697 { | |
6698 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6699 } | |
6700 SDL_CloseAudio(); | |
6701 } | |
6702 else | |
6703 { | |
6704 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6705 */ | |
6706 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6707 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6708 } | |
6709 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6710 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6711 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6712 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
6713 * causes OpenAL and SMPEG to conflict. For some reason | |
6714 * if SDL_Init on audio is active, then all the SMPEG | |
6715 * decoded sound comes out silent. Unfortunately, | |
6716 * Sound_Init() invokes SDL_Init on audio. I'm | |
6717 * not sure why it actually needs it... | |
6718 * But we'll attempt to disable it here after the | |
6719 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
6720 */ | |
6721 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6722 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6723 |
0 | 6724 /* I'm told NULL will call the default string |
6725 * and hopefully do the right thing for each platform | |
6726 */ | |
6727 /* | |
6728 dev = alcOpenDevice( NULL ); | |
6729 */ | |
6730 /* Now I'm told I need to set both the device and context | |
6731 * to have the same sampling rate, so I must pass a string | |
6732 * to OpenDevice(). I don't know how portable these strings are. | |
6733 * I don't even know if the format for strings is | |
6734 * compatible | |
6735 * From the testattrib.c in the Loki test section | |
6736 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
6737 */ | |
6738 | |
6739 #ifdef USING_LOKI_AL_DIST | |
6740 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
6741 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
6742 #else | |
6743 dev = alcOpenDevice( NULL ); | |
6744 #endif | |
6745 if(NULL == dev) | |
6746 { | |
6747 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
|
6748 return AL_FALSE; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6751 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6752 /* 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
|
6753 /* 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
|
6754 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6755 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6756 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6757 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6758 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
|
6759 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6760 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
|
6761 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6762 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6763 |
0 | 6764 |
6765 context = alcCreateContext(dev, attrlist); | |
6766 if(NULL == context) | |
6767 { | |
6768 ALmixer_SetError("Cannot create a context OpenAL"); | |
6769 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6770 return AL_FALSE; |
0 | 6771 } |
6772 | |
6773 | |
6774 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6775 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6776 * According to Garin Hiebert, this is actually an inconsistency | |
6777 * in the Loki version. The function should return a boolean. | |
6778 * instead of ALC_NO_ERROR. Garin suggested I check via | |
6779 * alcGetError(). | |
6780 */ | |
6781 /* clear the error */ | |
6782 alcGetError(dev); | |
6783 alcMakeContextCurrent(context); | |
6784 | |
6785 error = alcGetError(dev); | |
6786 if( (ALC_NO_ERROR != error) ) | |
6787 { | |
6788 ALmixer_SetError("Could not MakeContextCurrent"); | |
6789 alcDestroyContext(context); | |
6790 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6791 return AL_FALSE; |
0 | 6792 } |
6793 | |
6794 | |
6795 #if 0 | |
6796 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
6797 if(alcGetCurrentContext() != context) | |
6798 { | |
6799 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6800 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6801 * I think this is a bug in the OpenAL implementation. | |
6802 */ | |
6803 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
6804 | |
6805 fprintf(stderr, "Making context current\n"); | |
6806 #ifndef __APPLE__ | |
6807 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
6808 #else | |
6809 if(!alcMakeContextCurrent(context)) | |
6810 #endif | |
6811 { | |
6812 ALmixer_SetError("Could not MakeContextCurrent"); | |
6813 alcDestroyContext(context); | |
6814 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6815 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6816 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6817 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6818 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6819 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6820 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6821 /* 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
|
6822 * 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
|
6823 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6824 * 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
|
6825 * 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
|
6826 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6827 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6828 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6829 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
|
6830 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6831 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
|
6832 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6833 #endif |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6834 |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6835 |
0 | 6836 |
6837 /* Saw this in the README with the OS X OpenAL distribution. | |
6838 * It looked interesting and simple, so I thought I might | |
6839 * try it out. | |
6840 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
6841 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
6842 * Audio format, the audio data passed to the | |
6843 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
6844 * usage by removing an audio data conversion | |
6845 * (per source) at render timem at the expense of a larger memory footprint. | |
6846 * | |
6847 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
6848 * setting will be applied to all subsequent | |
6849 * calls to alBufferData(). | |
6850 */ | |
6851 #ifdef __APPLE__ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6852 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6853 #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
|
6854 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6855 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6856 #endif |
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 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
|
6859 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6860 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
|
6861 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6862 if(0 != convert_data_enum) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6863 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6864 alEnable(convert_data_enum); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6865 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6866 if( (AL_NO_ERROR != alGetError()) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6867 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6868 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
|
6869 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
|
6870 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6871 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6872 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6873 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6874 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6875 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6876 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6877 ALboolean ALmixer_InitMixer(ALint num_sources) |
0 | 6878 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6879 ALint i; |
0 | 6880 ALenum error; |
6881 ALuint* source; | |
6882 | |
6883 | |
6884 ALmixer_Initialized = 1; | |
6885 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6886 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6887 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6888 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6889 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6890 /* 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
|
6891 /* 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
|
6892 * 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
|
6893 * This is not actually a leak. |
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 if(NULL == s_ALmixerErrorPool) |
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 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6898 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6899 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6900 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6901 return AL_FALSE; |
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 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6904 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6905 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6906 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
|
6907 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
|
6908 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6909 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6910 |
0 | 6911 if(num_sources <= 0) |
6912 { | |
6913 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
6914 } | |
6915 else | |
6916 { | |
6917 Number_of_Channels_global = num_sources; | |
6918 } | |
6919 Number_of_Reserve_Channels_global = 0; | |
6920 Is_Playing_global = 0; | |
6921 /* Set to Null in case system quit and was reinitialized */ | |
6922 Channel_Done_Callback = NULL; | |
6923 Channel_Done_Callback_Userdata = NULL; | |
6924 Channel_Data_Callback = NULL; | |
1 | 6925 Channel_Data_Callback_Userdata = NULL; |
0 | 6926 |
6927 /* Allocate memory for the list of channels */ | |
6928 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
6929 if(NULL == ALmixer_Channel_List) | |
6930 { | |
6931 ALmixer_SetError("Out of Memory for Channel List"); | |
6932 ALmixer_Initialized = 0; | |
6933 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6934 return AL_FALSE; |
0 | 6935 } |
6936 | |
6937 /* Allocate memory for the list of sources that map to the channels */ | |
6938 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
6939 if(NULL == Source_Map_List) | |
6940 { | |
6941 ALmixer_SetError("Out of Memory for Source Map List"); | |
6942 free(ALmixer_Channel_List); | |
6943 ALmixer_Initialized = 0; | |
6944 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6945 return AL_FALSE; |
0 | 6946 } |
6947 | |
6948 /* Create array that will hold the sources */ | |
6949 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
6950 if(NULL == source) | |
6951 { | |
6952 ALmixer_SetError("Out of Memory for sources"); | |
6953 free(Source_Map_List); | |
6954 free(ALmixer_Channel_List); | |
6955 ALmixer_Initialized = 0; | |
6956 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6957 return AL_FALSE; |
0 | 6958 } |
6959 | |
6960 /* Clear the error state */ | |
6961 alGetError(); | |
6962 /* Generate the OpenAL sources */ | |
6963 alGenSources(Number_of_Channels_global, source); | |
6964 if( (error=alGetError()) != AL_NO_ERROR) | |
6965 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6966 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 6967 free(ALmixer_Channel_List); |
6968 free(Source_Map_List); | |
6969 ALmixer_Initialized = 0; | |
6970 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6971 return AL_FALSE; |
0 | 6972 } |
6973 | |
6974 /* Initialize each channel and associate one source to one channel */ | |
6975 for(i=0; i<Number_of_Channels_global; i++) | |
6976 { | |
6977 Init_Channel(i); | |
6978 /* Keeping the source allocation out of the Init function | |
6979 * in case I want to reuse the Init | |
6980 * function for resetting data | |
6981 */ | |
6982 ALmixer_Channel_List[i].alsource = source[i]; | |
6983 /* Now also keep a copy of the source to channel mapping | |
6984 * in case we need to look up a channel from the source | |
6985 * instead of a source from a channel | |
6986 */ | |
6987 Source_Map_List[i].source = source[i]; | |
6988 Source_Map_List[i].channel = i; | |
6989 /* Clean the channel because there are some things that need to | |
6990 * be done that can't happen until the source is set | |
6991 */ | |
6992 Clean_Channel(i); | |
6993 } | |
6994 | |
6995 /* The Source_Map_List must be sorted by source for binary searches | |
6996 */ | |
6997 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
6998 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6999 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7000 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7001 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7002 if(NULL == s_simpleLock) |
0 | 7003 { |
7004 /* SDL sets the error message already? */ | |
7005 free(source); | |
7006 free(ALmixer_Channel_List); | |
7007 free(Source_Map_List); | |
7008 ALmixer_Initialized = 0; | |
7009 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7010 return AL_FALSE; |
0 | 7011 } |
7012 | |
7013 | |
7014 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
7015 if(NULL == Stream_Thread_global) | |
7016 { | |
7017 /* 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
|
7018 SDL_DestroyMutex(s_simpleLock); |
0 | 7019 free(source); |
7020 free(ALmixer_Channel_List); | |
7021 free(Source_Map_List); | |
7022 ALmixer_Initialized = 0; | |
7023 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7024 return AL_FALSE; |
0 | 7025 } |
7026 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7027 /* |
0 | 7028 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7029 */ |
0 | 7030 #endif /* End of ENABLE_ALMIXER_THREADS */ |
7031 | |
7032 /* We don't need this array any more because all the sources | |
7033 * are connected to channels | |
7034 */ | |
7035 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7036 return AL_TRUE; |
0 | 7037 } |
7038 | |
7039 | |
7040 | |
7041 /* Keep the return value void to allow easy use with | |
7042 * atexit() | |
7043 */ | |
7044 void ALmixer_Quit() | |
7045 { | |
7046 ALCcontext* context; | |
7047 ALCdevice* dev; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7048 ALint i; |
0 | 7049 |
7050 if( ! ALmixer_Initialized) | |
7051 { | |
7052 return; | |
7053 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7054 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7055 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7056 #endif |
0 | 7057 /* Shutdown everything before closing context */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7058 Internal_HaltChannel(-1, AL_FALSE); |
0 | 7059 |
7060 /* This flag will cause the thread to terminate */ | |
7061 ALmixer_Initialized = 0; | |
7062 #ifdef ENABLE_ALMIXER_THREADS | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7063 SDL_UnlockMutex(s_simpleLock); |
0 | 7064 SDL_WaitThread(Stream_Thread_global, NULL); |
7065 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7066 SDL_DestroyMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7067 #endif |
0 | 7068 |
7069 /* Delete all the OpenAL sources */ | |
7070 for(i=0; i<Number_of_Channels_global; i++) | |
7071 { | |
7072 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
7073 } | |
7074 /* Delete all the channels */ | |
7075 free(ALmixer_Channel_List); | |
7076 free(Source_Map_List); | |
7077 | |
7078 /* Reset the Number_of_Channels just in case somebody | |
7079 * tries using a ALmixer function. | |
7080 * I probably should put "Initialized" checks everywhere, | |
7081 * but I'm too lazy at the moment. | |
7082 */ | |
7083 Number_of_Channels_global = 0; | |
7084 | |
7085 context = alcGetCurrentContext(); | |
7086 if(NULL == context) | |
7087 { | |
7088 return; | |
7089 } | |
7090 /* Need to get the device before I close the context */ | |
7091 dev = alcGetContextsDevice(context); | |
7092 alcDestroyContext(context); | |
7093 | |
7094 if(NULL == dev) | |
7095 { | |
7096 return; | |
7097 } | |
7098 alcCloseDevice(dev); | |
7099 | |
7100 Sound_Quit(); | |
7101 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7102 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7103 /* 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
|
7104 TError_FreeErrorPool(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7105 s_ALmixerErrorPool = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7106 #endif |
0 | 7107 return; |
7108 } | |
7109 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7110 ALboolean ALmixer_IsInitialized() |
0 | 7111 { |
7112 return ALmixer_Initialized; | |
7113 } | |
7114 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7115 ALuint ALmixer_GetFrequency() |
0 | 7116 { |
7117 return ALmixer_Frequency_global; | |
7118 } | |
7119 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7120 const ALmixer_version* ALmixer_GetLinkedVersion() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7121 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7122 static ALmixer_version linked_mixver; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7123 ALMIXER_GET_COMPILED_VERSION(&linked_mixver); |
0 | 7124 return(&linked_mixver); |
7125 } | |
7126 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7127 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7128 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7129 const char* ALmixer_GetError() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7130 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7131 const char* error_string = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7132 if(NULL == s_ALmixerErrorPool) |
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 "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
|
7135 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7136 error_string = TError_GetLastErrorStr(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7137 /* 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
|
7138 if(NULL == 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 return ""; |
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 else |
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 return error_string; |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7147 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7148 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
|
7149 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7150 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7151 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7152 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
|
7153 return; |
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 va_list argp; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7156 va_start(argp, err_str); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7157 // 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
|
7158 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
|
7159 va_end(argp); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7160 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7161 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7162 #endif |
0 | 7163 |
7164 | |
7165 | |
7166 | |
7167 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7168 void ALmixer_OutputAttributes() |
0 | 7169 { |
7170 ALint num_flags = 0; | |
7171 ALint* flags = 0; | |
7172 int i; | |
7173 ALCdevice* dev = alcGetContextsDevice( alcGetCurrentContext() ); | |
7174 | |
7175 | |
7176 printf("custom context\n"); | |
7177 | |
7178 alcGetIntegerv(dev, ALC_ATTRIBUTES_SIZE, | |
7179 sizeof num_flags, &num_flags ); | |
7180 | |
7181 printf("Number of Flags: %d\n", num_flags); | |
7182 | |
7183 if(num_flags) | |
7184 { | |
7185 flags = malloc(sizeof(num_flags) * sizeof(ALint)); | |
7186 | |
7187 alcGetIntegerv(dev, ALC_ALL_ATTRIBUTES, | |
7188 sizeof num_flags * sizeof(ALint), | |
7189 flags ); | |
7190 } | |
7191 for(i = 0; i < num_flags-1; i += 2) | |
7192 { | |
7193 printf("key 0x%x : value %d\n", | |
7194 flags[i], flags[i+1]); | |
7195 } | |
7196 free(flags); | |
7197 } | |
7198 #endif | |
7199 | |
7200 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7201 void ALmixer_OutputDecoders() |
0 | 7202 { |
7203 Sound_Version sound_compile_version; | |
7204 Sound_Version sound_link_version; | |
7205 | |
7206 const Sound_DecoderInfo **rc = Sound_AvailableDecoders(); | |
7207 const Sound_DecoderInfo **i; | |
7208 const char **ext; | |
7209 FILE* stream = stdout; | |
7210 | |
7211 | |
7212 fprintf(stream, "SDL_sound Information:\n"); | |
7213 | |
7214 SOUND_VERSION(&sound_compile_version); | |
7215 fprintf(stream, "\tCompiled with SDL_sound version: %d.%d.%d\n", | |
7216 sound_compile_version.major, | |
7217 sound_compile_version.minor, | |
7218 sound_compile_version.patch); | |
7219 | |
7220 Sound_GetLinkedVersion(&sound_link_version); | |
7221 fprintf(stream, "\tRunning (linked) with SDL_sound version: %d.%d.%d\n", | |
7222 sound_link_version.major, | |
7223 sound_link_version.minor, | |
7224 sound_link_version.patch); | |
7225 | |
7226 fprintf(stream, "Supported sound formats:\n"); | |
7227 if (rc == NULL) | |
7228 fprintf(stream, " * Apparently, NONE!\n"); | |
7229 else | |
7230 { | |
7231 for (i = rc; *i != NULL; i++) | |
7232 { | |
7233 fprintf(stream, " * %s\n", (*i)->description); | |
7234 | |
7235 for (ext = (*i)->extensions; *ext != NULL; ext++) | |
7236 fprintf(stream, " File extension \"%s\"\n", *ext); | |
7237 | |
7238 fprintf(stream, " Written by %s.\n %s\n\n", | |
7239 (*i)->author, (*i)->url); | |
7240 } /* for */ | |
7241 } /* else */ | |
7242 | |
7243 fprintf(stream, "\n"); | |
7244 } | |
7245 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7246 void ALmixer_OutputOpenALInfo() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7247 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7248 ALmixer_version mixer_compile_version; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7249 const ALmixer_version * mixer_link_version=ALmixer_GetLinkedVersion(); |
0 | 7250 FILE* stream = stdout; |
7251 | |
7252 fprintf(stream, "OpenAL Information:\n"); | |
7253 fprintf(stream, "\tAL_VENDOR: %s\n", alGetString( AL_VENDOR ) ); | |
7254 fprintf(stream, "\tAL_VERSION: %s\n", alGetString( AL_VERSION ) ); | |
7255 fprintf(stream, "\tAL_RENDERER: %s\n", alGetString( AL_RENDERER ) ); | |
7256 fprintf(stream, "\tAL_EXTENSIONS: %s\n", alGetString( AL_EXTENSIONS ) ); | |
7257 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7258 ALMIXER_GET_COMPILED_VERSION(&mixer_compile_version); |
0 | 7259 fprintf(stream, "\nSDL_ALmixer Information:\n"); |
7260 fprintf(stream, "\tCompiled with SDL_ALmixer version: %d.%d.%d\n", | |
7261 mixer_compile_version.major, | |
7262 mixer_compile_version.minor, | |
7263 mixer_compile_version.patch); | |
7264 | |
7265 fprintf(stream, "\tRunning (linked) with SDL_ALmixer version: %d.%d.%d\n", | |
7266 mixer_link_version->major, | |
7267 mixer_link_version->minor, | |
7268 mixer_link_version->patch); | |
7269 | |
7270 fprintf(stream, "\tCompile flags: "); | |
7271 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
7272 fprintf(stream, "ENABLE_LOKI_QUEUE_FIX_HACK "); | |
7273 #endif | |
7274 #ifdef ENABLE_ALMIXER_THREADS | |
7275 fprintf(stream, "ENABLE_ALMIXER_THREADS "); | |
7276 #endif | |
7277 #ifdef ENABLE_ALC_SYNC | |
7278 fprintf(stream, "ENABLE_ALC_SYNC "); | |
7279 #endif | |
7280 fprintf(stream, "\n"); | |
7281 } | |
7282 | |
7283 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7284 ALint ALmixer_AllocateChannels(ALint numchans) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7285 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7286 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7287 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7288 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7289 #endif |
0 | 7290 retval = Internal_AllocateChannels(numchans); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7291 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7292 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7293 #endif |
0 | 7294 return retval; |
7295 } | |
7296 | |
7297 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7298 ALint ALmixer_ReserveChannels(ALint num) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7299 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7300 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7301 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7302 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7303 #endif |
0 | 7304 retval = Internal_ReserveChannels(num); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7305 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7306 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7307 #endif |
0 | 7308 return retval; |
7309 } | |
7310 | |
7311 | |
7312 | |
7313 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7314 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
|
7315 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7316 ALuint bytes_decoded; |
0 | 7317 ALmixer_Data* ret_data; |
7318 ALenum error; | |
7319 | |
7320 /* Allocate memory */ | |
7321 ret_data = (ALmixer_Data *)malloc(sizeof(ALmixer_Data)); | |
7322 if (NULL == ret_data) | |
7323 { | |
7324 ALmixer_SetError("Out of memory"); | |
7325 return(NULL); | |
7326 } | |
7327 | |
7328 /* Initialize the data fields */ | |
7329 | |
7330 /* Set the Sound_Sample pointer */ | |
7331 ret_data->sample = sample; | |
7332 | |
7333 /* Flag the data to note that it is not in use */ | |
7334 ret_data->in_use = 0; | |
7335 | |
7336 /* Initialize remaining flags */ | |
7337 ret_data->total_time = -1; | |
7338 ret_data->eof = 0; | |
7339 | |
7340 /* Just initialize */ | |
7341 ret_data->num_buffers_in_use = 0; | |
7342 | |
7343 /* Just initialize */ | |
7344 ret_data->total_bytes = 0; | |
7345 | |
7346 /* Just initialize */ | |
7347 ret_data->loaded_bytes = 0; | |
7348 | |
7349 /* Set the max queue buffers (minimum must be 2) */ | |
7350 if(max_queue_buffers < 2) | |
7351 { | |
7352 max_queue_buffers = ALMIXER_DEFAULT_QUEUE_BUFFERS; | |
7353 } | |
7354 ret_data->max_queue_buffers = max_queue_buffers; | |
7355 /* Set up the start up buffers */ | |
7356 if(0 == num_startup_buffers) | |
7357 { | |
7358 num_startup_buffers = ALMIXER_DEFAULT_STARTUP_BUFFERS; | |
7359 } | |
7360 /* Make sure start up buffers is less or equal to max_queue_buffers */ | |
7361 if(num_startup_buffers > max_queue_buffers) | |
7362 { | |
7363 num_startup_buffers = max_queue_buffers; | |
7364 } | |
7365 ret_data->num_startup_buffers = num_startup_buffers; | |
7366 | |
7367 ret_data->buffer_map_list = NULL; | |
7368 ret_data->current_buffer = 0; | |
7369 | |
7370 ret_data->circular_buffer_queue = NULL; | |
7371 | |
7372 /* Now decode and load the data into a data chunk */ | |
7373 /* Different cases for Streamed and Predecoded | |
7374 * Streamed might turn into a predecoded if buffersize | |
7375 * is large enough */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7376 if(AL_FALSE == decode_mode_is_predecoded) |
0 | 7377 { |
7378 bytes_decoded = Sound_Decode(sample); | |
7379 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7380 { | |
7381 ALmixer_SetError(Sound_GetError()); | |
7382 Sound_FreeSample(sample); | |
7383 free(ret_data); | |
7384 return NULL; | |
7385 } | |
7386 | |
7387 /* If no data, return an error */ | |
7388 if(0 == bytes_decoded) | |
7389 { | |
7390 ALmixer_SetError("File has no data"); | |
7391 Sound_FreeSample(sample); | |
7392 free(ret_data); | |
7393 return NULL; | |
7394 } | |
7395 | |
7396 /* Note, currently, my Ogg conservative modifications | |
7397 * prevent EOF from being detected in the first read | |
7398 * because of the weird packet behavior of ov_read(). | |
7399 * The EAGAIN will get set, but not the EOF. | |
7400 * I don't know the best way to handle this, | |
7401 * so for now, Ogg's can only be explicitly | |
7402 * predecoded. | |
7403 */ | |
7404 | |
7405 /* Correction: Since we no longer actually keep the | |
7406 * streamed data we read here (we rewind and throw | |
7407 * it away, and start over on Play), it is | |
7408 * safe to read another chunk to see if we've hit EOF | |
7409 */ | |
7410 if(sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
7411 { | |
7412 bytes_decoded = Sound_Decode(sample); | |
7413 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7414 { | |
7415 ALmixer_SetError(Sound_GetError()); | |
7416 Sound_FreeSample(sample); | |
7417 free(ret_data); | |
7418 return NULL; | |
7419 } | |
7420 } | |
7421 | |
7422 | |
7423 /* If we found an EOF, the entire file was | |
7424 * decoded, so we can treat it like one. | |
7425 */ | |
7426 | |
7427 if(sample->flags & SOUND_SAMPLEFLAG_EOF) | |
7428 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7429 /* |
0 | 7430 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
|
7431 */ |
0 | 7432 ret_data->decoded_all = 1; |
7433 /* Need to keep this information around for | |
7434 * seek and rewind abilities. | |
7435 */ | |
7436 ret_data->total_bytes = bytes_decoded; | |
7437 /* For now, the loaded bytes is the same as total bytes, but | |
7438 * this could change during a seek operation | |
7439 */ | |
7440 ret_data->loaded_bytes = bytes_decoded; | |
7441 | |
7442 /* Let's compute the total playing time | |
7443 * SDL_sound does not yet provide this (we're working on | |
7444 * that at the moment...) | |
7445 */ | |
7446 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
7447 | |
7448 /* Create one element in the buffer array for data for OpanAL */ | |
7449 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
7450 if(NULL == ret_data->buffer) | |
7451 { | |
7452 ALmixer_SetError("Out of Memory"); | |
7453 Sound_FreeSample(sample); | |
7454 free(ret_data); | |
7455 return NULL; | |
7456 } | |
7457 /* Clear the error code */ | |
7458 alGetError(); | |
7459 /* Now generate an OpenAL buffer using that first element */ | |
7460 alGenBuffers(1, ret_data->buffer); | |
7461 if( (error = alGetError()) != AL_NO_ERROR) | |
7462 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7463 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7464 Sound_FreeSample(sample); |
7465 free(ret_data->buffer); | |
7466 free(ret_data); | |
7467 return NULL; | |
7468 } | |
7469 | |
7470 | |
7471 /* Now copy the data to the OpenAL buffer */ | |
7472 /* We can't just set a pointer because the API needs | |
7473 * its own copy to assist hardware acceleration */ | |
7474 alBufferData(ret_data->buffer[0], | |
7475 TranslateFormat(&sample->desired), | |
7476 sample->buffer, | |
7477 bytes_decoded, | |
7478 sample->desired.rate | |
7479 ); | |
7480 if( (error = alGetError()) != AL_NO_ERROR) | |
7481 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7482 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 7483 Sound_FreeSample(sample); |
7484 alDeleteBuffers(1, ret_data->buffer); | |
7485 free(ret_data->buffer); | |
7486 free(ret_data); | |
7487 return NULL; | |
7488 } | |
7489 | |
7490 /* We should be done with the sample since it's all | |
7491 * predecoded. So we can free the memory */ | |
7492 | |
7493 /* Additional notes: | |
7494 * We need to keep data around in case Seek() is needed | |
7495 * or other Sound_AudioInfo is needed. | |
7496 * This can either be done by not deleting the sample, | |
7497 * or it can be done by dynamically recreating it | |
7498 * when we need it. | |
7499 */ | |
7500 /* Since OpenAL won't let us retrieve it | |
7501 * (aka dynamically), we have to keep the Sample | |
7502 * around because since the user requested | |
7503 * streamed and we offered predecoded, | |
7504 * we don't want to mess up the user who | |
7505 * was expecting seek support | |
7506 * So Don't Do anything | |
7507 */ | |
7508 /* | |
7509 if(0 == access_data) | |
7510 { | |
7511 Sound_FreeSample(sample); | |
7512 ret_data->sample = NULL; | |
7513 } | |
7514 */ | |
7515 /* Else, We keep a copy of the sample around. | |
7516 * so don't do anything. | |
7517 */ | |
7518 | |
7519 #if 0 | |
7520 #if defined(DISABLE_PREDECODED_SEEK) | |
7521 Sound_FreeSample(sample); | |
7522 ret_data->sample = NULL; | |
7523 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
7524 Sound_FreeSample(sample); | |
7525 ret_data->sample = NULL; | |
7526 #else | |
7527 /* We keep a copy of the sample around. | |
7528 * so don't do anything. | |
7529 */ | |
7530 #endif | |
7531 #endif | |
7532 /* okay we're done here */ | |
7533 | |
7534 } | |
7535 /* Else, we need to stream the data, so we'll | |
7536 * create multple buffers for queuing */ | |
7537 else | |
7538 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7539 /* |
0 | 7540 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
|
7541 */ |
0 | 7542 ret_data->decoded_all = 0; |
7543 | |
7544 /* This information is for predecoded. | |
7545 * Set to 0, since we don't know. | |
7546 */ | |
7547 ret_data->total_bytes = 0; | |
7548 | |
7549 /* Create buffers for data | |
7550 */ | |
7551 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) * max_queue_buffers); | |
7552 if(NULL == ret_data->buffer) | |
7553 { | |
7554 ALmixer_SetError("Out of Memory"); | |
7555 Sound_FreeSample(sample); | |
7556 free(ret_data); | |
7557 return NULL; | |
7558 } | |
7559 | |
7560 /* Clear the error code */ | |
7561 alGetError(); | |
7562 /* Now generate an OpenAL buffer using that first element */ | |
7563 alGenBuffers(max_queue_buffers, ret_data->buffer); | |
7564 if( (error = alGetError()) != AL_NO_ERROR) | |
7565 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7566 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7567 Sound_FreeSample(sample); |
7568 free(ret_data->buffer); | |
7569 free(ret_data); | |
7570 return NULL; | |
7571 } | |
7572 | |
7573 /* Redesign: Okay, because of the unqueuing problems and such, | |
7574 * I've decided to redesign where and how queuing is handled. | |
7575 * Before, everything was queued up here. However, this | |
7576 * placed a penalty on load and made performance inconsistent | |
7577 * when samples had to be rewound. It did make things easier | |
7578 * to queue because I could let OpenAL decide which buffer | |
7579 * needed to be queued next. | |
7580 * Now, I'm going to push off the queuing to the actual | |
7581 * Play() command. I'm going to add some book keeping, | |
7582 * and allow for additional buffers to be filled at later | |
7583 * times. | |
7584 */ | |
7585 | |
7586 | |
7587 /* So first of all, because of I already decoded the sample | |
7588 * for testing, I need to decide what to do with it. | |
7589 * The best thing would be be to alBufferData() it. | |
7590 * The problem is it may conflict with the rest of | |
7591 * the system because everything now assumes buffers | |
7592 * are entirely stripped (because of the unqueing | |
7593 * problem). | |
7594 * So it looks like I have to do the crappy thing | |
7595 * and throw away the data, and rewind. | |
7596 */ | |
7597 | |
7598 if(0 == Sound_Rewind(ret_data->sample)) | |
7599 { | |
7600 ALmixer_SetError("Cannot use sample for streamed data because it must be rewindable: %s", Sound_GetError() ); | |
7601 Sound_FreeSample(sample); | |
7602 free(ret_data->buffer); | |
7603 free(ret_data); | |
7604 return NULL; | |
7605 } | |
7606 | |
7607 | |
7608 /* If the user has selected access_data, we need to | |
7609 * keep copies of the queuing buffers around because | |
7610 * OpenAL won't let us access the data. | |
7611 * Allocate the memory for the buffers here | |
7612 * and initialize the albuffer-index map | |
7613 */ | |
7614 if(access_data) | |
7615 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7616 ALuint j; |
0 | 7617 /* Create buffers for data access |
7618 * Should be the same number as the number of queue buffers | |
7619 */ | |
1 | 7620 ret_data->buffer_map_list = (ALmixer_Buffer_Map*)malloc( sizeof(ALmixer_Buffer_Map) * max_queue_buffers); |
0 | 7621 if(NULL == ret_data->buffer_map_list) |
7622 { | |
7623 ALmixer_SetError("Out of Memory"); | |
7624 Sound_FreeSample(sample); | |
7625 free(ret_data->buffer); | |
7626 free(ret_data); | |
7627 return NULL; | |
7628 } | |
7629 | |
7630 ret_data->circular_buffer_queue = CircularQueueUnsignedInt_CreateQueue(max_queue_buffers); | |
7631 if(NULL == ret_data->circular_buffer_queue) | |
7632 { | |
7633 ALmixer_SetError("Out of Memory"); | |
7634 free(ret_data->buffer_map_list); | |
7635 Sound_FreeSample(sample); | |
7636 free(ret_data->buffer); | |
7637 free(ret_data); | |
7638 return NULL; | |
7639 } | |
7640 | |
7641 | |
7642 for(j=0; j<max_queue_buffers; j++) | |
7643 { | |
7644 ret_data->buffer_map_list[j].albuffer = ret_data->buffer[j]; | |
7645 ret_data->buffer_map_list[j].index = j; | |
7646 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
|
7647 ret_data->buffer_map_list[j].data = (ALbyte*)malloc( sizeof(ALbyte) * buffersize); |
0 | 7648 if(NULL == ret_data->buffer_map_list[j].data) |
7649 { | |
7650 ALmixer_SetError("Out of Memory"); | |
7651 break; | |
7652 } | |
7653 } | |
7654 /* If an error happened, we have to clean up the memory */ | |
7655 if(j < max_queue_buffers) | |
7656 { | |
7657 fprintf(stderr, "################## Buffer allocation failed\n"); | |
7658 for( ; j>=0; j--) | |
7659 { | |
7660 free(ret_data->buffer_map_list[j].data); | |
7661 } | |
7662 free(ret_data->buffer_map_list); | |
7663 CircularQueueUnsignedInt_FreeQueue(ret_data->circular_buffer_queue); | |
7664 Sound_FreeSample(sample); | |
7665 free(ret_data->buffer); | |
7666 free(ret_data); | |
7667 return NULL; | |
7668 } | |
7669 | |
7670 /* The Buffer_Map_List must be sorted by albuffer for binary searches | |
7671 */ | |
1 | 7672 qsort(ret_data->buffer_map_list, max_queue_buffers, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 7673 } /* End if access_data==true */ |
7674 | |
7675 | |
7676 } /* End of do stream */ | |
7677 } /* end of DECODE_STREAM */ | |
7678 /* 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
|
7679 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
|
7680 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7681 #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
|
7682 /* 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
|
7683 * 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
|
7684 * 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
|
7685 * so looping isn't needed. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7686 * 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
|
7687 * 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
|
7688 * 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
|
7689 * 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
|
7690 * 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
|
7691 * 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
|
7692 * to load a file. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7693 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7694 ALint sound_duration = Sound_GetDuration(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7695 if(sound_duration > 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7696 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7697 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
|
7698 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
|
7699 if(0 == buffer_resize_succeeded) |
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 ALmixer_SetError(Sound_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7702 Sound_FreeSample(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7703 free(ret_data); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7704 return NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7705 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7706 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7707 #endif /* ALMIXER_DISABLE_PREDECODED_PRECOMPUTE_BUFFER_SIZE_OPTIMIZATION */ |
0 | 7708 bytes_decoded = Sound_DecodeAll(sample); |
7709 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7710 { | |
7711 ALmixer_SetError(Sound_GetError()); | |
7712 Sound_FreeSample(sample); | |
7713 free(ret_data); | |
7714 return NULL; | |
7715 } | |
7716 | |
7717 /* If no data, return an error */ | |
7718 if(0 == bytes_decoded) | |
7719 { | |
7720 ALmixer_SetError("File has no data"); | |
7721 Sound_FreeSample(sample); | |
7722 free(ret_data); | |
7723 return NULL; | |
7724 } | |
7725 | |
7726 | |
7727 ret_data->decoded_all = 1; | |
7728 /* Need to keep this information around for | |
7729 * seek and rewind abilities. | |
7730 */ | |
7731 ret_data->total_bytes = bytes_decoded; | |
7732 /* For now, the loaded bytes is the same as total bytes, but | |
7733 * this could change during a seek operation | |
7734 */ | |
7735 ret_data->loaded_bytes = bytes_decoded; | |
7736 | |
7737 /* Let's compute the total playing time | |
7738 * SDL_sound does not yet provide this (we're working on | |
7739 * that at the moment...) | |
7740 */ | |
7741 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
7742 | |
7743 /* Create one element in the buffer array for data for OpanAL */ | |
7744 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
7745 if(NULL == ret_data->buffer) | |
7746 { | |
7747 ALmixer_SetError("Out of Memory"); | |
7748 Sound_FreeSample(sample); | |
7749 free(ret_data); | |
7750 return NULL; | |
7751 } | |
7752 /* Clear the error code */ | |
7753 alGetError(); | |
7754 /* Now generate an OpenAL buffer using that first element */ | |
7755 alGenBuffers(1, ret_data->buffer); | |
7756 if( (error = alGetError()) != AL_NO_ERROR) | |
7757 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7758 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7759 Sound_FreeSample(sample); |
7760 free(ret_data->buffer); | |
7761 free(ret_data); | |
7762 return NULL; | |
7763 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7764 /* |
0 | 7765 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
|
7766 */ |
0 | 7767 /* Now copy the data to the OpenAL buffer */ |
7768 /* We can't just set a pointer because the API needs | |
7769 * its own copy to assist hardware acceleration */ | |
7770 alBufferData(ret_data->buffer[0], | |
7771 TranslateFormat(&sample->desired), | |
7772 sample->buffer, | |
7773 bytes_decoded, | |
7774 sample->desired.rate | |
7775 ); | |
7776 if( (error = alGetError()) != AL_NO_ERROR) | |
7777 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7778 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 7779 Sound_FreeSample(sample); |
7780 alDeleteBuffers(1, ret_data->buffer); | |
7781 free(ret_data->buffer); | |
7782 free(ret_data); | |
7783 return NULL; | |
7784 } | |
7785 | |
7786 /* We should be done with the sample since it's all | |
7787 * predecoded. So we can free the memory */ | |
7788 /* Need to keep around because Seek() needs it */ | |
7789 | |
7790 /* Additional notes: | |
7791 * We need to keep data around in case Seek() is needed | |
7792 * or other Sound_AudioInfo is needed. | |
7793 * This can either be done by not deleting the sample, | |
7794 * or it can be done by dynamically recreating it | |
7795 * when we need it. | |
7796 * Update: I think now it's up to the user by passing the | |
7797 * access_data flag. If they set the flag, then they get | |
7798 * data callbacks and seek support. If not, then they can | |
7799 * get all that stuff at the expense of keeping extra memory | |
7800 * around. | |
7801 */ | |
7802 if(0 == access_data) | |
7803 { | |
7804 Sound_FreeSample(sample); | |
7805 ret_data->sample = NULL; | |
7806 } | |
7807 | |
7808 /* Else, We keep a copy of the sample around. | |
7809 * so don't do anything. | |
7810 */ | |
7811 #if 0 | |
7812 #if defined(DISABLE_PREDECODED_SEEK) | |
7813 Sound_FreeSample(sample); | |
7814 ret_data->sample = NULL; | |
7815 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
7816 Sound_FreeSample(sample); | |
7817 ret_data->sample = NULL; | |
7818 #else | |
7819 /* We keep a copy of the sample around. | |
7820 * so don't do anything. | |
7821 */ | |
7822 #endif | |
7823 #endif | |
7824 | |
7825 /* okay we're done here */ | |
7826 } | |
7827 else | |
7828 { | |
7829 /* Shouldn't get here */ | |
7830 ALmixer_SetError("Unknown decode mode"); | |
7831 Sound_FreeSample(sample); | |
7832 free(ret_data); | |
7833 return NULL; | |
7834 } | |
7835 | |
7836 return ret_data; | |
7837 } | |
7838 | |
7839 | |
7840 /* This will load a sample for us. Most of the uglyness is | |
7841 * error checking and the fact that streamed/predecoded files | |
7842 * must be treated differently. | |
7843 * I don't like the AudioInfo parameter. I removed it once, | |
7844 * but the system will fail on RAW samples because the user | |
7845 * must specify it, so I had to bring it back. | |
7846 * Remember I must close the rwops if there is an error before NewSample() | |
7847 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7848 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 | 7849 { |
7850 Sound_Sample* sample = NULL; | |
7851 Sound_AudioInfo target; | |
7852 | |
7853 /* Initialize target values to defaults | |
7854 * 0 tells SDL_sound to use the "actual" values | |
7855 */ | |
7856 target.channels = 0; | |
7857 target.rate = 0; | |
7858 #if 0 | |
7859 /* This requires my new additions to SDL_sound. It will | |
7860 * convert the sample to the proper endian order. | |
7861 * If the actual is 8-bit, it will do unsigned, if | |
7862 * the actual is 16-bit, it will do signed. | |
7863 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
7864 * in this way. | |
7865 */ | |
7866 target.format = AUDIO_U8S16SYS; | |
7867 #else | |
7868 target.format = AUDIO_S16SYS; | |
7869 #endif | |
7870 | |
7871 /* Set a default buffersize if needed */ | |
7872 if(0 == buffersize) | |
7873 { | |
7874 buffersize = ALMIXER_DEFAULT_BUFFERSIZE; | |
7875 } | |
7876 | |
7877 sample = Sound_NewSample(rwops, fileext, &target, buffersize); | |
7878 if(NULL == sample) | |
7879 { | |
7880 ALmixer_SetError(Sound_GetError()); | |
7881 return NULL; | |
7882 } | |
7883 | |
1 | 7884 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 7885 } |
7886 | |
7887 | |
7888 | |
7889 /* This will load a sample for us from | |
7890 * a file (instead of RWops). Most of the uglyness is | |
7891 * error checking and the fact that streamed/predecoded files | |
7892 * must be treated differently. | |
7893 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7894 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 | 7895 { |
7896 Sound_Sample* sample = NULL; | |
7897 Sound_AudioInfo target; | |
7898 | |
7899 /* Initialize target values to defaults | |
7900 * 0 tells SDL_sound to use the "actual" values | |
7901 */ | |
7902 target.channels = 0; | |
7903 target.rate = 0; | |
7904 | |
7905 #if 0 | |
7906 /* This requires my new additions to SDL_sound. It will | |
7907 * convert the sample to the proper endian order. | |
7908 * If the actual is 8-bit, it will do unsigned, if | |
7909 * the actual is 16-bit, it will do signed. | |
7910 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
7911 * in this way. | |
7912 */ | |
7913 target.format = AUDIO_U8S16SYS; | |
7914 #else | |
7915 target.format = AUDIO_S16SYS; | |
7916 #endif | |
7917 | |
7918 #if 0 | |
7919 /* Okay, here's a messy hack. The problem is that we need | |
7920 * to convert the sample to have the correct bitdepth, | |
7921 * endian order, and signedness values. | |
7922 * The bit depth is 8 or 16. | |
7923 * The endian order is the native order of the system. | |
7924 * The signedness depends on what the original value | |
7925 * of the sample. Unfortunately, we can't specify these | |
7926 * values until we after we already know what the original | |
7927 * values were for bitdepth and signedness. | |
7928 * So we must open the file once to get the values, | |
7929 * then close it, and then reopen it with the | |
7930 * correct desired target values. | |
7931 * I tried changing the sample->desired field after | |
7932 * the NewSample call, but it had no effect, so | |
7933 * it looks like it must be set on open. | |
7934 */ | |
7935 /* Pick a small buffersize for the first open to not | |
7936 * waste much time allocating memory */ | |
7937 sample = Sound_NewSampleFromFile(filename, NULL, 512); | |
7938 if(NULL == sample) | |
7939 { | |
7940 ALmixer_SetError(Sound_GetError()); | |
7941 return NULL; | |
7942 } | |
7943 | |
7944 bit_depth = GetBitDepth(sample->actual.format); | |
7945 signedness_value = GetSignednessValue(sample->actual.format); | |
7946 if(8 == bit_depth) | |
7947 { | |
7948 /* If 8 bit, then we don't have to worry about | |
7949 * endian issues. We can just use the actual format | |
7950 * value and it should do the right thing | |
7951 */ | |
7952 target.format = sample->actual.format; | |
7953 } | |
7954 else | |
7955 { | |
7956 /* We'll assume it's 16-bit, and if it's not | |
7957 * hopefully SDL_sound will return an error, | |
7958 * or let us convert to 16-bit | |
7959 */ | |
7960 /* Now we need to get the correct signedness */ | |
7961 if(ALMIXER_UNSIGNED_VALUE == signedness_value) | |
7962 { | |
7963 /* Set to Unsigned 16-bit, system endian order */ | |
7964 target.format = AUDIO_U16SYS; | |
7965 } | |
7966 else | |
7967 { | |
7968 /* Again, we'll assume it's Signed 16-bit system order | |
7969 * or force the conversion and hope it works out | |
7970 */ | |
7971 target.format = AUDIO_S16SYS; | |
7972 } | |
7973 } | |
7974 | |
7975 /* Now we have the correct info. We need to close and reopen */ | |
7976 Sound_FreeSample(sample); | |
7977 #endif | |
7978 | |
7979 sample = Sound_NewSampleFromFile(filename, &target, buffersize); | |
7980 if(NULL == sample) | |
7981 { | |
7982 ALmixer_SetError(Sound_GetError()); | |
7983 return NULL; | |
7984 } | |
7985 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7986 /* |
0 | 7987 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
|
7988 */ |
1 | 7989 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 7990 } |
7991 | |
7992 | |
7993 /* This is a back door for RAW samples or if you need the | |
7994 * AudioInfo field. Use at your own risk. | |
7995 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7996 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 | 7997 { |
7998 Sound_Sample* sample = NULL; | |
1 | 7999 Sound_AudioInfo sound_desired; |
8000 /* Rather than copying the data from struct to struct, I could just | |
8001 * cast the thing since the structs are meant to be identical. | |
8002 * But if SDL_sound changes it's implementation, bad things | |
8003 * will probably happen. (Or if I change my implementation and | |
8004 * forget about the cast, same bad scenario.) Since this is a load | |
8005 * function, performance of this is negligible. | |
8006 */ | |
8007 if(NULL == desired) | |
8008 { | |
8009 sample = Sound_NewSample(rwops, fileext, NULL, buffersize); | |
8010 } | |
8011 else | |
8012 { | |
8013 sound_desired.format = desired->format; | |
8014 sound_desired.channels = desired->channels; | |
8015 sound_desired.rate = desired->rate; | |
8016 sample = Sound_NewSample(rwops, fileext, &sound_desired, buffersize); | |
8017 } | |
0 | 8018 if(NULL == sample) |
8019 { | |
8020 ALmixer_SetError(Sound_GetError()); | |
8021 return NULL; | |
8022 } | |
1 | 8023 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8024 } |
8025 | |
8026 | |
8027 | |
8028 | |
8029 /* This is a back door for RAW samples or if you need the | |
8030 * AudioInfo field. Use at your own risk. | |
8031 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8032 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 | 8033 { |
8034 Sound_Sample* sample = NULL; | |
1 | 8035 Sound_AudioInfo sound_desired; |
8036 /* Rather than copying the data from struct to struct, I could just | |
8037 * cast the thing since the structs are meant to be identical. | |
8038 * But if SDL_sound changes it's implementation, bad things | |
8039 * will probably happen. (Or if I change my implementation and | |
8040 * forget about the cast, same bad scenario.) Since this is a load | |
8041 * function, performance of this is negligible. | |
8042 */ | |
8043 if(NULL == desired) | |
8044 { | |
8045 sample = Sound_NewSampleFromFile(filename, NULL, buffersize); | |
8046 } | |
8047 else | |
8048 { | |
8049 sound_desired.format = desired->format; | |
8050 sound_desired.channels = desired->channels; | |
8051 sound_desired.rate = desired->rate; | |
8052 sample = Sound_NewSampleFromFile(filename, &sound_desired, buffersize); | |
8053 } | |
8054 | |
0 | 8055 if(NULL == sample) |
8056 { | |
8057 ALmixer_SetError(Sound_GetError()); | |
8058 return NULL; | |
8059 } | |
1 | 8060 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8061 } |
8062 | |
8063 | |
8064 | |
8065 | |
8066 void ALmixer_FreeData(ALmixer_Data* data) | |
8067 { | |
8068 ALenum error; | |
8069 if(NULL == data) | |
8070 { | |
8071 return; | |
8072 } | |
8073 | |
8074 if(data->decoded_all) | |
8075 { | |
8076 /* If access_data was enabled, then the Sound_Sample* | |
8077 * still exists. We need to free it | |
8078 */ | |
8079 if(data->sample != NULL) | |
8080 { | |
8081 Sound_FreeSample(data->sample); | |
8082 } | |
8083 alDeleteBuffers(1, data->buffer); | |
8084 if((error = alGetError()) != AL_NO_ERROR) | |
8085 { | |
8086 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
|
8087 alGetString(error)); |
0 | 8088 } |
8089 | |
8090 } | |
8091 else | |
8092 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8093 ALuint i; |
0 | 8094 |
8095 /* Delete buffer copies if access_data was enabled */ | |
8096 if(data->buffer_map_list != NULL) | |
8097 { | |
8098 for(i=0; i<data->max_queue_buffers; i++) | |
8099 { | |
8100 free(data->buffer_map_list[i].data); | |
8101 } | |
8102 free(data->buffer_map_list); | |
8103 } | |
8104 if(data->circular_buffer_queue != NULL) | |
8105 { | |
8106 CircularQueueUnsignedInt_FreeQueue(data->circular_buffer_queue); | |
8107 } | |
8108 | |
8109 Sound_FreeSample(data->sample); | |
8110 alDeleteBuffers(data->max_queue_buffers, data->buffer); | |
8111 if((error = alGetError()) != AL_NO_ERROR) | |
8112 { | |
8113 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
|
8114 alGetString(error)); |
0 | 8115 } |
8116 } | |
8117 free(data->buffer); | |
8118 free(data); | |
8119 } | |
8120 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8121 ALint ALmixer_GetTotalTime(ALmixer_Data* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8122 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8123 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8124 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8125 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8126 } |
0 | 8127 return data->total_time; |
8128 } | |
8129 | |
8130 /* This function will look up the source for the corresponding channel */ | |
8131 /* 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
|
8132 ALuint ALmixer_GetSource(ALint channel) |
0 | 8133 { |
8134 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8135 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8136 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8137 #endif |
0 | 8138 retval = Internal_GetSource(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8139 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8140 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8141 #endif |
0 | 8142 return retval; |
8143 } | |
8144 | |
8145 /* 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
|
8146 ALint ALmixer_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8147 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8148 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8149 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8150 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8151 #endif |
0 | 8152 retval = Internal_GetChannel(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8153 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8154 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8155 #endif |
0 | 8156 return retval; |
8157 } | |
8158 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8159 ALint ALmixer_FindFreeChannel(ALint start_channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8160 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8161 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8162 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8163 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8164 #endif |
0 | 8165 retval = Internal_FindFreeChannel(start_channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8166 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8167 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8168 #endif |
0 | 8169 return retval; |
8170 } | |
8171 | |
8172 | |
8173 | |
8174 /* API update function. | |
8175 * It should return the number of buffers that were | |
8176 * queued during the call. The value might be | |
8177 * used to guage how long you might wait to | |
8178 * call the next update loop in case you are worried | |
8179 * about preserving CPU cycles. The idea is that | |
8180 * when a buffer is queued, there was probably some | |
8181 * CPU intensive looping which took awhile. | |
8182 * 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
|
8183 * Timing the call with ALmixer_GetTicks() would produce |
0 | 8184 * more accurate information. |
8185 * Returns a negative value if there was an error, | |
8186 * the value being the number of errors. | |
8187 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8188 ALint ALmixer_Update() |
0 | 8189 { |
8190 #ifdef ENABLE_ALMIXER_THREADS | |
8191 /* The thread will handle all updates by itself. | |
8192 * Don't allow the user to explicitly call update. | |
8193 */ | |
8194 return 0; | |
8195 #else | |
8196 return( Update_ALmixer(NULL) ); | |
8197 #endif | |
8198 } | |
8199 | |
8200 | |
8201 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8202 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
|
8203 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8204 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8205 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8206 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8207 Channel_Done_Callback = playback_finished_callback; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8208 Channel_Done_Callback_Userdata = user_data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8209 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8210 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8211 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8212 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8213 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8214 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8215 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
|
8216 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8217 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8218 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8219 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8220 Channel_Data_Callback = playback_data_callback; |
1 | 8221 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
|
8222 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8223 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8224 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8225 } |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8228 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8229 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8230 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8231 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
|
8232 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8233 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8234 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8235 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8236 #endif |
0 | 8237 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
|
8238 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8239 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8240 #endif |
0 | 8241 return retval; |
8242 } | |
8243 | |
8244 | |
8245 /* In case the user wants to specify a source instead of a channel, | |
8246 * they may use this function. This function will look up the | |
8247 * source-to-channel map, and convert the call into a | |
8248 * PlayChannelTimed() function call. | |
8249 * Returns the channel it's being played on. | |
8250 * Note: If you are prefer this method, then you need to be careful | |
8251 * about using PlayChannel, particularly if you request the | |
8252 * first available channels because source and channels have | |
8253 * a one-to-one mapping in this API. It is quite easy for | |
8254 * a channel/source to already be in use because of this. | |
8255 * In this event, an error message will be returned to you. | |
8256 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8257 ALuint ALmixer_PlaySourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALint ticks) |
0 | 8258 { |
8259 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8260 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8261 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8262 #endif |
0 | 8263 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
|
8264 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8265 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8266 #endif |
0 | 8267 return retval; |
8268 } | |
8269 | |
8270 | |
8271 /* Will return the number of channels halted | |
8272 * or 0 for error | |
8273 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8274 ALint ALmixer_HaltChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8275 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8276 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8277 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8278 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8279 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8280 retval = Internal_HaltChannel(channel, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8281 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8282 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8283 #endif |
0 | 8284 return retval; |
8285 } | |
8286 | |
8287 /* Will return the number of channels halted | |
8288 * or 0 for error | |
8289 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8290 ALint ALmixer_HaltSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8291 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8292 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8293 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8294 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8295 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8296 retval = Internal_HaltSource(source, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8297 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8298 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8299 #endif |
0 | 8300 return retval; |
8301 } | |
8302 | |
8303 | |
8304 /* This will rewind the SDL_Sound sample for streamed | |
8305 * samples and start buffering up the data for the next | |
8306 * playback. This may require samples to be halted | |
8307 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8308 ALint ALmixer_RewindData(ALmixer_Data* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8309 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8310 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8311 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8312 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8313 #endif |
0 | 8314 retval = Internal_RewindData(data); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8315 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8316 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8317 #endif |
0 | 8318 return retval; |
8319 } | |
8320 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8321 ALint ALmixer_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8322 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8323 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8324 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8325 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8326 #endif |
0 | 8327 retval = Internal_RewindChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8328 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8329 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8330 #endif |
0 | 8331 return retval; |
8332 } | |
8333 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8334 ALint ALmixer_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8335 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8336 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8337 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8338 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8339 #endif |
0 | 8340 retval = Internal_RewindSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8341 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8342 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8343 #endif |
0 | 8344 return retval; |
8345 } | |
8346 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8347 ALint ALmixer_PauseChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8348 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8349 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8350 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8351 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8352 #endif |
0 | 8353 retval = Internal_PauseChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8354 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8355 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8356 #endif |
0 | 8357 return retval; |
8358 } | |
8359 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8360 ALint ALmixer_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8361 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8362 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8363 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8364 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8365 #endif |
0 | 8366 retval = Internal_PauseSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8367 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8368 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8369 #endif |
0 | 8370 return retval; |
8371 } | |
8372 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8373 ALint ALmixer_ResumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8374 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8375 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8376 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8377 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8378 #endif |
0 | 8379 retval = Internal_ResumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8380 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8381 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8382 #endif |
0 | 8383 return retval; |
8384 } | |
8385 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8386 ALint ALmixer_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8387 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8388 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8389 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8390 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8391 #endif |
0 | 8392 retval = Internal_ResumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8393 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8394 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8395 #endif |
0 | 8396 return retval; |
8397 } | |
8398 | |
8399 /* Might consider setting eof to 0 as a "feature" | |
8400 * This will allow seek to end to stay there because | |
8401 * 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
|
8402 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
|
8403 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8404 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8405 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8406 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8407 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8408 retval = Internal_SeekData(data, msec); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8409 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8410 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8411 #endif |
0 | 8412 return retval; |
8413 } | |
8414 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8415 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
|
8416 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8417 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8418 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8419 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8420 #endif |
0 | 8421 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
|
8422 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8423 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8424 #endif |
0 | 8425 return retval; |
8426 } | |
8427 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8428 ALuint ALmixer_FadeInSourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 8429 { |
8430 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8431 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8432 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8433 #endif |
0 | 8434 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
|
8435 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8436 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8437 #endif |
0 | 8438 return retval; |
8439 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8440 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8441 ALint ALmixer_FadeOutChannel(ALint channel, ALuint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8442 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8443 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8444 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8445 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8446 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8447 retval = Internal_FadeOutChannel(channel, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8448 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8449 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8450 #endif |
0 | 8451 return retval; |
8452 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8453 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8454 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
|
8455 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8456 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8457 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8458 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8459 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8460 retval = Internal_FadeOutSource(source, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8461 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8462 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8463 #endif |
0 | 8464 return retval; |
8465 } | |
8466 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8467 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
|
8468 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8469 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8470 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8471 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8472 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8473 retval = Internal_FadeChannel(channel, ticks, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8474 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8475 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8476 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8477 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8478 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8479 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8480 ALint 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
|
8481 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8482 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8483 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8484 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8485 #endif |
0 | 8486 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
|
8487 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8488 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8489 #endif |
0 | 8490 return retval; |
8491 } | |
8492 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8493 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8494 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
|
8495 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8496 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8497 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8498 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8499 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8500 retval = Internal_SetVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8501 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8502 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8503 #endif |
0 | 8504 return retval; |
8505 } | |
8506 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8507 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
|
8508 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8509 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8510 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8511 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8512 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8513 retval = Internal_SetVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8514 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8515 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8516 #endif |
0 | 8517 return retval; |
8518 } | |
8519 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8520 ALfloat ALmixer_GetVolumeChannel(ALint channel) |
0 | 8521 { |
8522 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8523 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8524 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8525 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8526 retval = Internal_GetVolumeChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8527 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8528 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8529 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8530 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8531 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8532 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8533 ALfloat ALmixer_GetVolumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8534 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8535 ALfloat retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8536 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8537 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8538 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8539 retval = Internal_GetVolumeSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8540 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8541 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8542 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8543 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8544 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8545 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8546 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
|
8547 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8548 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8549 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8550 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8551 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8552 retval = Internal_SetMaxVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8553 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8554 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8555 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8556 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8557 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8558 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8559 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
|
8560 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8561 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8562 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8563 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8564 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8565 retval = Internal_SetMaxVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8566 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8567 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8568 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8569 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8570 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8571 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8572 ALfloat ALmixer_GetMaxVolumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8573 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8574 ALfloat retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8575 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8576 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8577 #endif |
0 | 8578 retval = Internal_GetMaxVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8579 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8580 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8581 #endif |
0 | 8582 return retval; |
8583 } | |
8584 | |
8585 ALfloat ALmixer_GetMaxVolumeSource(ALuint source) | |
8586 { | |
8587 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8588 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8589 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8590 #endif |
0 | 8591 retval = Internal_GetMaxVolumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8592 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8593 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8594 #endif |
0 | 8595 return retval; |
8596 } | |
8597 | |
8598 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8599 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
|
8600 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8601 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8602 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8603 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8604 #endif |
0 | 8605 retval = Internal_SetMinVolumeChannel(channel, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8606 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8607 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8608 #endif |
0 | 8609 return retval; |
8610 } | |
8611 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8612 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
|
8613 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8614 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8615 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8616 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8617 #endif |
0 | 8618 retval = Internal_SetMinVolumeSource(source, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8619 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8620 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8621 #endif |
0 | 8622 return retval; |
8623 } | |
8624 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8625 ALfloat ALmixer_GetMinVolumeChannel(ALint channel) |
0 | 8626 { |
8627 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8628 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8629 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8630 #endif |
0 | 8631 retval = Internal_GetMinVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8632 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8633 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8634 #endif |
0 | 8635 return retval; |
8636 } | |
8637 | |
8638 ALfloat ALmixer_GetMinVolumeSource(ALuint source) | |
8639 { | |
8640 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8641 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8642 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8643 #endif |
0 | 8644 retval = Internal_GetMinVolumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8645 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8646 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8647 #endif |
0 | 8648 return retval; |
8649 } | |
8650 | |
8651 | |
8652 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8653 ALboolean ALmixer_SetMasterVolume(ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8654 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8655 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8656 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8657 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8658 #endif |
0 | 8659 retval = Internal_SetMasterVolume(volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8660 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8661 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8662 #endif |
0 | 8663 return retval; |
8664 } | |
8665 | |
8666 ALfloat ALmixer_GetMasterVolume() | |
8667 { | |
8668 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8669 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8670 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8671 #endif |
0 | 8672 retval = Internal_GetMasterVolume(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8673 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8674 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8675 #endif |
0 | 8676 return retval; |
8677 } | |
8678 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8679 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
|
8680 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8681 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8682 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8683 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8684 #endif |
0 | 8685 retval = Internal_ExpireChannel(channel, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8686 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8687 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8688 #endif |
0 | 8689 return retval; |
8690 } | |
8691 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8692 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
|
8693 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8694 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8695 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8696 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8697 #endif |
0 | 8698 retval = Internal_ExpireSource(source, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8699 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8700 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8701 #endif |
0 | 8702 return retval; |
8703 } | |
8704 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8705 ALint ALmixer_IsActiveChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8706 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8707 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8708 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8709 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8710 #endif |
0 | 8711 retval = Internal_QueryChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8712 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8713 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8714 #endif |
0 | 8715 return retval; |
8716 } | |
8717 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8718 ALint ALmixer_IsActiveSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8719 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8720 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8721 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8722 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8723 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8724 retval = Internal_QuerySource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8725 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8726 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8727 #endif |
0 | 8728 return retval; |
8729 } | |
8730 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8731 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8732 ALint ALmixer_IsPlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8733 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8734 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8735 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8736 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8737 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8738 retval = Internal_PlayingChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8739 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8740 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8741 #endif |
0 | 8742 return retval; |
8743 } | |
8744 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8745 ALint ALmixer_IsPlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8746 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8747 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8748 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8749 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8750 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8751 retval = Internal_PlayingSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8752 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8753 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8754 #endif |
0 | 8755 return retval; |
8756 } | |
8757 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8758 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8759 ALint ALmixer_IsPausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8760 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8761 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8762 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8763 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8764 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8765 retval = Internal_PausedChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8766 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8767 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8768 #endif |
0 | 8769 return retval; |
8770 } | |
8771 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8772 ALint ALmixer_IsPausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8773 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8774 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8775 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8776 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8777 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8778 retval = Internal_PausedSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8779 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8780 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8781 #endif |
0 | 8782 return retval; |
8783 } | |
8784 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8785 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8786 ALuint ALmixer_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8787 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8788 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8789 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8790 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8791 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8792 retval = Internal_CountAllFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8793 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8794 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8795 #endif |
0 | 8796 return retval; |
8797 } | |
8798 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8799 ALuint ALmixer_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8800 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8801 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8802 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8803 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8804 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8805 retval = Internal_CountUnreservedFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8806 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8807 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8808 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8809 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8810 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8811 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8812 ALuint ALmixer_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8813 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8814 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8815 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8816 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8817 #endif |
0 | 8818 retval = Internal_CountAllUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8819 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8820 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8821 #endif |
0 | 8822 return retval; |
8823 } | |
8824 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8825 ALuint ALmixer_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8826 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8827 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8828 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8829 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8830 #endif |
0 | 8831 retval = Internal_CountUnreservedUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8832 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8833 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8834 #endif |
0 | 8835 return retval; |
8836 } | |
8837 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8838 ALboolean ALmixer_IsPredecoded(ALmixer_Data* data) |
1 | 8839 { |
8840 if(NULL == data) | |
8841 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8842 return AL_FALSE; |
1 | 8843 } |
8844 return data->decoded_all; | |
8845 } | |
8846 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8847 ALboolean ALmixer_CompiledWithThreadBackend() |
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 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8850 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8851 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8852 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8853 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8854 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8855 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8856 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8857 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8858 |