Mercurial > almixer_isolated
annotate ALmixer.c @ 16:038baa026db3
Fixed bug in LinkedList delete. Shouldn't have both popped list and then called FreeData which would check the list again for the data. Instead, I should just get the data and then call FreeData to let it manipulate the list.
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Sat, 06 Nov 2010 03:59:28 -0700 |
parents | 54aa96ae8912 |
children | 9365e714fc4b 58f03008ea05 |
rev | line source |
---|---|
0 | 1 |
2 /* Here's an OpenAL implementation modeled after | |
3 * the SDL_SoundMixer which was built ontop of SDL_Mixer | |
4 * and SDL_Sound. | |
5 * Eric Wing | |
6 */ | |
7 | |
3
a929285e1db0
Added CMake build system.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
2
diff
changeset
|
8 #include "ALmixer.h" |
0 | 9 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
10 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
11 #include "ALmixer_rwops.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
12 #include "SoundDecoder.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
13 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
14 #include "SDL_sound.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
15 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
16 |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
17 #ifdef ANDROID_NDK |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
18 #include <AL/al.h> |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
19 #include <AL/alc.h> |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
20 #else |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
21 #include "al.h" /* OpenAL */ |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
22 #include "alc.h" /* For creating OpenAL contexts */ |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
23 #endif |
0 | 24 |
1 | 25 #ifdef __APPLE__ |
26 /* For performance things like ALC_CONVERT_DATA_UPON_LOADING */ | |
27 /* Note: ALC_CONVERT_DATA_UPON_LOADING used to be in the alc.h header. | |
28 * But in the Tiger OpenAL 1.1 release (10.4.7 and Xcode 2.4), the | |
29 * define was moved to a new header file and renamed to | |
30 * ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING. | |
31 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
32 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
33 #include <TargetConditionals.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
34 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
35 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
36 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
37 #include <OpenAL/MacOSX_OALExtensions.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
38 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
39 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
40 |
1 | 41 #endif |
42 | |
0 | 43 /* For malloc, bsearch, qsort */ |
44 #include <stdlib.h> | |
45 | |
46 /* For memcpy */ | |
47 #include <string.h> | |
48 | |
49 #if 0 | |
50 /* for toupper */ | |
51 #include <ctype.h> | |
52 /* for strrchr */ | |
53 #include <string.h> | |
54 #endif | |
55 | |
56 /* Currently used in the output debug functions */ | |
57 #include <stdio.h> | |
58 | |
59 /* My own CircularQueue implementation needed | |
60 * to work around the Nvidia problem of the | |
61 * lack of a buffer query. | |
62 */ | |
63 #include "CircularQueue.h" | |
64 | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
65 /* SDL_sound keeps a private linked list of sounds which get auto-deleted |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
66 * on Sound_Quit. This might actually create some leaks for me in certain |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
67 * usage patterns. To be safe, I should do the same. |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
68 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
69 #include "LinkedList.h" |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
70 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
71 #ifdef ENABLE_ALMIXER_THREADS |
0 | 72 /* 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
|
73 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
74 #include "SimpleMutex.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
75 #include "SimpleThread.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
76 typedef struct SimpleMutex SDL_mutex; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
77 typedef struct SimpleThread SDL_Thread; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
78 #define SDL_CreateMutex SimpleMutex_CreateMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
79 #define SDL_DestroyMutex SimpleMutex_DestroyMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
80 #define SDL_LockMutex SimpleMutex_LockMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
81 #define SDL_UnlockMutex SimpleMutex_UnlockMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
82 #define SDL_CreateThread SimpleThread_CreateThread |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
83 #define SDL_WaitThread SimpleThread_WaitThread |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
84 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
85 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
86 #include "SDL_thread.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
87 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
88 #endif |
0 | 89 |
90 /* Because of the API differences between the Loki | |
91 * and Creative distributions, we need to know which | |
92 * version to use. The LOKI distribution currently | |
93 * has AL_BYTE_LOKI defined in altypes.h which | |
94 * I will use as a flag to identify the distributions. | |
95 * If this is ever removed, I might revert back to the | |
96 * if defined(_WIN32) or defined(__APPLE__) test to | |
97 * identify the Creative dist. | |
98 * I'm not sure if or how the Nvidia distribution differs | |
99 * from the Creative distribution. So for | |
100 * now, the Nvidia distribution gets lumped with the | |
101 * 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
|
102 * My alGetString may be the most vulnerable. |
0 | 103 */ |
104 #ifdef AL_BYTE_LOKI | |
105 #define USING_LOKI_AL_DIST | |
106 /* This is a short term fix to get around the | |
107 * queuing problem with non-power of two buffer sizes. | |
108 * Hopefully the maintainers will fix this before | |
109 * we're ready to ship. | |
110 */ | |
111 #define ENABLE_LOKI_QUEUE_FIX_HACK | |
112 | |
113 /* The AL_GAIN in the Loki dist doesn't seem to do | |
114 * what I want/expect it to do. I want to use it for | |
115 * Fading, but it seems to work like an off/on switch. | |
116 * 0 = off, >0 = on. | |
117 * The AL_GAIN_LINEAR_LOKI switch seems to do what | |
118 * I want, so I'll redefine it here so the code is consistent | |
119 */ | |
120 /* Update: I've changed the source volume implementations | |
121 * to use AL_MAX_GAIN, so I don't think I need this block | |
122 * of code anymore. The listener uses AL_GAIN, but I | |
123 * hope they got this one right since there isn't a AL_MAX_GAIN | |
124 * for the listener. | |
125 */ | |
126 /* | |
127 #undef AL_GAIN | |
128 #include "alexttypes.h" | |
129 #define AL_GAIN AL_GAIN_LINEAR_LOKI | |
130 */ | |
131 #else | |
132 /* Might need to run other tests to figure out the DIST */ | |
133 /* I've been told that Nvidia doesn't define constants | |
134 * in the headers like Creative. Instead of | |
135 * #define AL_REFERENCE_DISTANCE 0x1020, | |
136 * Nvidia prefers you query OpenAL for a value. | |
137 * int AL_REFERENCE_DISTANCE = alGetEnumValue(ALubyte*)"AL_REFERNECE_DISTANCE"); | |
138 * So I'm assuming this means the Nvidia lacks this value. | |
139 * If this is the case, | |
140 * I guess we can use it to identify the Nvidia dist | |
141 */ | |
142 #ifdef AL_REFERENCE_DISTANCE | |
143 #define USING_CREATIVE_AL_DIST | |
144 #else | |
145 #define USING_NVIDIA_AL_DIST | |
146 #endif | |
147 #endif | |
148 | |
149 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
150 /* Need memset to zero out data */ | |
151 #include <string.h> | |
152 #endif | |
153 | |
154 | |
155 /* Seek issues for predecoded samples: | |
156 * The problem is that OpenAL makes us copy an | |
157 * entire buffer if we want to use it. This | |
158 * means we potentially have two copies of the | |
159 * same data. For predecoded data, this can be a | |
160 * large amount of memory. However, for seek | |
161 * support, I need to be able to get access to | |
162 * the original data so I can set byte positions. | |
163 * The following flags let you disable seek support | |
164 * if you don't want the memory hit, keep everything, | |
165 * or let you try to minimize the memory wasted by | |
166 * fetching it from the OpenAL buffer if needed | |
167 * and making a copy of it. | |
168 * Update: I don't think I need this flag anymore. I've made the | |
169 * effects of this user customizable by the access_data flag on load. | |
170 * If set to true, then seek and data callbacks work, with the | |
171 * cost of more memory and possibly CPU for copying the data through | |
172 * the callbacks. If false, then the extra memory is freed, but | |
173 * you don't get the features. | |
174 */ | |
175 /* | |
176 #define DISABLE_PREDECODED_SEEK | |
177 */ | |
178 /* Problem: Even though alGetBufferi(., AL_DATA, .) | |
179 * is in the Creative Programmer's reference, | |
180 * it actually isn't in the dist. (Invalid enum | |
181 * in Creative, can't compile in Loki.) | |
182 * So we have to keep it disabled | |
183 */ | |
184 #define DISABLE_SEEK_MEMORY_OPTIMIZATION | |
185 | |
186 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION | |
187 /* Needed for memcpy */ | |
188 #include <string.h> | |
189 #endif | |
190 | |
191 /* Old way of doing things: | |
192 #if defined(_WIN32) || defined(__APPLE__) | |
193 #define USING_CREATIVE_AL_DIST | |
194 #else | |
195 #define USING_LOKI_AL_DIST | |
196 #endif | |
197 */ | |
198 | |
199 /************ REMOVE ME (Don't need anymore) ********/ | |
200 #if 0 | |
201 /* Let's get fancy and see if triple buffering | |
202 * does anything good for us | |
203 * Must be 2 or more or things will probably break | |
204 */ | |
205 #define NUMBER_OF_QUEUE_BUFFERS 5 | |
206 /* This is the number of buffers that are queued up | |
207 * when play first starts up. This should be at least 1 | |
208 * and no more than NUMBER_OF_QUEUE_BUFFERS | |
209 */ | |
210 #define NUMBER_OF_START_UP_BUFFERS 2 | |
211 #endif | |
212 /************ END REMOVE ME (Don't need anymore) ********/ | |
213 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
214 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
215 #include "tErrorLib.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
216 static TErrorPool* s_ALmixerErrorPool = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
217 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
218 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
219 static ALboolean ALmixer_Initialized = 0; |
0 | 220 /* 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
|
221 static ALuint ALmixer_Frequency_global = ALMIXER_DEFAULT_FREQUENCY; |
0 | 222 |
223 /* Will be initialized in Init */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
224 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
|
225 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
|
226 static ALuint Is_Playing_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
227 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
228 #ifdef ENABLE_ALMIXER_THREADS |
0 | 229 /* This is for a simple lock system. It is not meant to be good, |
230 * but just sufficient to minimize/avoid threading issues | |
231 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
232 static SDL_mutex* s_simpleLock; |
0 | 233 static SDL_Thread* Stream_Thread_global = NULL; |
234 #endif | |
235 | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
236 static LinkedList* s_listOfALmixerData = NULL; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
237 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
238 |
0 | 239 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
240 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
241 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
|
242 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
243 static void (*alcMacOSXMixerOutputRateProcPtr)(const ALdouble) = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
244 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
245 if(NULL == alcMacOSXMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
246 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
247 alcMacOSXMixerOutputRateProcPtr = alGetProcAddress((const ALCchar*) "alcMacOSXMixerOutputRate"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
248 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
249 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
250 if(NULL != alcMacOSXMixerOutputRateProcPtr) |
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 alcMacOSXMixerOutputRateProcPtr(sample_rate); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
253 } |
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; |
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 ALdouble Internal_alcMacOSXGetMixerOutputRate() |
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 static ALdouble (*alcMacOSXGetMixerOutputRateProcPtr)(void) = NULL; |
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 if(NULL == alcMacOSXGetMixerOutputRateProcPtr) |
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 alcMacOSXGetMixerOutputRateProcPtr = alGetProcAddress((const ALCchar*) "alcMacOSXGetMixerOutputRate"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
265 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
266 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
267 if(NULL != alcMacOSXGetMixerOutputRateProcPtr) |
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 return alcMacOSXGetMixerOutputRateProcPtr(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
270 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
271 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
272 return 0.0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
273 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
274 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
275 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
276 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
277 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
278 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
279 #include <QuartzCore/QuartzCore.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
280 #include <unistd.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
281 static CFTimeInterval s_ticksBaseTime = 0.0; |
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 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
284 #define WIN32_LEAN_AND_MEAN |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
285 #include <windows.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
286 #include <winbase.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
287 LARGE_INTEGER s_hiResTicksPerSecond; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
288 double s_hiResSecondsPerTick; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
289 LARGE_INTEGER s_ticksBaseTime; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
290 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
291 #include <unistd.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
292 #include <time.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
293 static struct timespec s_ticksBaseTime; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
294 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
295 static void ALmixer_InitTime() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
296 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
297 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
298 s_ticksBaseTime = CACurrentMediaTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
299 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
300 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
301 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
|
302 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
|
303 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
304 QueryPerformanceCounter(&s_ticksBaseTime); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
305 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
|
306 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
307 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
308 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
309 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
|
310 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
|
311 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
312 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
313 /* clock_gettime is POSIX.1-2001 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
314 clock_gettime(CLOCK_MONOTONIC, &s_ticksBaseTime); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
315 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
316 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
317 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
318 static ALuint ALmixer_GetTicks() |
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 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
321 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
|
322 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
323 LARGE_INTEGER current_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
324 QueryPerformanceCounter(¤t_time); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
325 return (ALuint)((current_time.QuadPart - s_ticksBaseTime.QuadPart) * 1000 * s_hiResSecondsPerTick); |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
326 #elif ANDROID_NDK |
2
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 /* assuming POSIX */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
329 /* clock_gettime is POSIX.1-2001 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
330 struct timespec current_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
331 clock_gettime(CLOCK_MONOTONIC, ¤t_time); |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
332 return (ALuint)((current_time.tv_sec - s_ticksBaseTime.tv_sec)*1000.0 + (current_time.tv_nsec - s_ticksBaseTime.tv_nsec) / 1000000); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
333 #endif |
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 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
|
336 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
337 #if defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
338 Sleep(milliseconds_delay); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
339 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
340 usleep(milliseconds_delay); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
341 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
342 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
343 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
344 #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
|
345 #define ALmixer_GetTicks SDL_GetTicks |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
346 #define ALmixer_Delay SDL_Delay |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
347 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
348 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
349 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
350 |
0 | 351 /* If ENABLE_PARANOID_SIGNEDNESS_CHECK is used, |
352 * these values will be reset on Init() | |
353 * Consider these values Read-Only. | |
354 */ | |
355 | |
356 #define ALMIXER_SIGNED_VALUE 127 | |
357 #define ALMIXER_UNSIGNED_VALUE 255 | |
358 | |
359 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
360 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
|
361 static ALushort SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; |
0 | 362 #else |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
363 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
|
364 static const ALushort SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; |
0 | 365 #endif |
366 | |
1 | 367 |
368 /* This can be private instead of being in the header now that I moved | |
369 * ALmixer_Data inside here. | |
370 */ | |
371 typedef struct ALmixer_Buffer_Map ALmixer_Buffer_Map; | |
372 | |
373 | |
374 struct ALmixer_Data | |
375 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
376 ALboolean decoded_all; /* dictates different behaviors */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
377 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
|
378 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
379 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
|
380 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
|
381 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
382 ALuint total_bytes; /* For predecoded */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
383 ALuint loaded_bytes; /* For predecoded (for seek) */ |
1 | 384 |
385 Sound_Sample* sample; /* SDL_Sound provides the data */ | |
386 ALuint* buffer; /* array of OpenAL buffers (at least 1 for predecoded) */ | |
387 | |
388 /* Needed for streamed buffers */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
389 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
|
390 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
|
391 ALuint num_buffers_in_use; /* number of buffers in use */ |
1 | 392 |
393 /* This stuff is for streamed buffers that require data access */ | |
394 ALmixer_Buffer_Map* buffer_map_list; /* translate ALbuffer to index | |
395 and holds pointer to copy of data for | |
396 data access */ | |
397 ALuint current_buffer; /* The current playing buffer */ | |
398 | |
399 /* Nvidia distribution refuses to recognize a simple buffer query command | |
400 * unlike all other distributions. It's forcing me to redo the code | |
401 * to accomodate this Nvidia flaw by making me maintain a "best guess" | |
402 * copy of what I think the buffer queue state looks like. | |
403 * A circular queue would a helpful data structure for this task, | |
404 * but I wanted to avoid making an additional header requirement, | |
405 * so I'm making it a void* | |
406 */ | |
407 void* circular_buffer_queue; | |
408 | |
409 | |
410 }; | |
411 | |
0 | 412 static struct ALmixer_Channel |
413 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
414 ALboolean channel_in_use; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
415 ALboolean callback_update; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
416 ALboolean needs_stream; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
417 ALboolean halted; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
418 ALboolean paused; |
0 | 419 ALuint alsource; |
420 ALmixer_Data* almixer_data; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
421 ALint loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
422 ALint expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
423 ALuint start_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
424 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
425 ALboolean fade_enabled; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
426 ALuint fade_expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
427 ALuint fade_start_time; |
0 | 428 ALfloat fade_inv_time; |
429 ALfloat fade_start_volume; | |
430 ALfloat fade_end_volume; | |
431 ALfloat max_volume; | |
432 ALfloat min_volume; | |
433 | |
434 /* Do we need other flags? | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
435 ALbyte *samples; |
0 | 436 int volume; |
437 int looping; | |
438 int tag; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
439 ALuint expire; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
440 ALuint start_time; |
0 | 441 Mix_Fading fading; |
442 int fade_volume; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
443 ALuint fade_length; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
444 ALuint ticks_fade; |
0 | 445 effect_info *effects; |
446 */ | |
447 } *ALmixer_Channel_List = NULL; | |
448 | |
1 | 449 struct ALmixer_Buffer_Map |
450 { | |
451 ALuint albuffer; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
452 ALint index; /* might not need */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
453 ALbyte* data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
454 ALuint num_bytes; |
1 | 455 }; |
456 | |
0 | 457 /* This will be used to find a channel if the user supplies a source */ |
458 typedef struct Source_Map | |
459 { | |
460 ALuint source; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
461 ALint channel; |
0 | 462 } Source_Map; |
463 /* Keep an array of all sources with their associated channel */ | |
464 static Source_Map* Source_Map_List; | |
465 | |
466 static int Compare_Source_Map(const void* a, const void* b) | |
467 { | |
468 return ( ((Source_Map*)a)->source - ((Source_Map*)b)->source ); | |
469 } | |
470 | |
471 /* Sort by channel instead of source */ | |
472 static int Compare_Source_Map_by_channel(const void* a, const void* b) | |
473 { | |
474 return ( ((Source_Map*)a)->channel - ((Source_Map*)b)->channel ); | |
475 } | |
476 | |
477 /* Compare by albuffer */ | |
478 static int Compare_Buffer_Map(const void* a, const void* b) | |
479 { | |
1 | 480 return ( ((ALmixer_Buffer_Map*)a)->albuffer - ((ALmixer_Buffer_Map*)b)->albuffer ); |
0 | 481 } |
482 | |
483 /* This is for the user defined callback via | |
484 * ALmixer_ChannelFinished() | |
485 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
486 static void (*Channel_Done_Callback)(ALint which_channel, ALuint al_source, ALmixer_Data* almixer_data, ALboolean finished_naturally, void* user_data) = NULL; |
0 | 487 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
|
488 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 | 489 static void* Channel_Data_Callback_Userdata = NULL; |
0 | 490 |
491 | |
492 static void PrintQueueStatus(ALuint source) | |
493 { | |
494 ALint buffers_queued = 0; | |
495 ALint buffers_processed = 0; | |
496 ALenum error; | |
497 | |
498 /* Get the number of buffers still queued */ | |
499 alGetSourcei( | |
500 source, | |
501 AL_BUFFERS_QUEUED, | |
502 &buffers_queued | |
503 ); | |
504 | |
505 if((error = alGetError()) != AL_NO_ERROR) | |
506 { | |
507 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
|
508 alGetString(error)); |
0 | 509 } |
510 /* Get the number of buffers processed | |
511 * so we know if we need to refill | |
512 */ | |
513 alGetSourcei( | |
514 source, | |
515 AL_BUFFERS_PROCESSED, | |
516 &buffers_processed | |
517 ); | |
518 if((error = alGetError()) != AL_NO_ERROR) | |
519 { | |
520 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
|
521 alGetString(error)); |
0 | 522 } |
523 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
524 /* |
0 | 525 fprintf(stderr, "For source: %d, buffers_queued=%d, buffers_processed=%d\n", |
526 source, | |
527 buffers_queued, | |
528 buffers_processed); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
529 */ |
0 | 530 } |
531 | |
532 | |
533 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
534 static void Init_Channel(ALint channel) |
0 | 535 { |
536 ALmixer_Channel_List[channel].channel_in_use = 0; | |
537 ALmixer_Channel_List[channel].callback_update = 0; | |
538 ALmixer_Channel_List[channel].needs_stream = 0; | |
539 ALmixer_Channel_List[channel].paused = 0; | |
540 ALmixer_Channel_List[channel].halted = 0; | |
541 ALmixer_Channel_List[channel].loops = 0; | |
542 | |
543 ALmixer_Channel_List[channel].expire_ticks = 0; | |
544 ALmixer_Channel_List[channel].start_time = 0; | |
545 | |
546 ALmixer_Channel_List[channel].fade_enabled = 0; | |
547 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
548 ALmixer_Channel_List[channel].fade_start_time = 0; | |
549 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
550 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
551 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
552 ALmixer_Channel_List[channel].max_volume = 1.0f; | |
553 ALmixer_Channel_List[channel].min_volume = 0.0f; | |
554 | |
555 ALmixer_Channel_List[channel].almixer_data = NULL; | |
556 } | |
557 /* Quick helper function to clean up a channel | |
558 * after it's done playing */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
559 static void Clean_Channel(ALint channel) |
0 | 560 { |
561 ALenum error; | |
562 ALmixer_Channel_List[channel].channel_in_use = 0; | |
563 ALmixer_Channel_List[channel].callback_update = 0; | |
564 ALmixer_Channel_List[channel].needs_stream = 0; | |
565 ALmixer_Channel_List[channel].paused = 0; | |
566 ALmixer_Channel_List[channel].halted = 0; | |
567 ALmixer_Channel_List[channel].loops = 0; | |
568 | |
569 | |
570 ALmixer_Channel_List[channel].expire_ticks = 0; | |
571 ALmixer_Channel_List[channel].start_time = 0; | |
572 | |
573 ALmixer_Channel_List[channel].fade_enabled = 0; | |
574 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
575 ALmixer_Channel_List[channel].fade_start_time = 0; | |
576 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
577 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
578 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
579 | |
580 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MAX_GAIN, | |
581 ALmixer_Channel_List[channel].max_volume); | |
582 | |
583 if((error = alGetError()) != AL_NO_ERROR) | |
584 { | |
585 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
|
586 alGetString(error)); |
0 | 587 } |
588 | |
589 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MIN_GAIN, | |
590 ALmixer_Channel_List[channel].min_volume); | |
591 if((error = alGetError()) != AL_NO_ERROR) | |
592 { | |
593 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
|
594 alGetString(error)); |
0 | 595 } |
596 | |
597 if(ALmixer_Channel_List[channel].almixer_data != NULL) | |
598 { | |
599 if(ALmixer_Channel_List[channel].almixer_data->in_use > 0) | |
600 { | |
601 ALmixer_Channel_List[channel].almixer_data->in_use--; | |
602 } | |
603 } | |
604 /* Needed to determine if rewind is needed, can't reset */ | |
605 /* | |
606 ALmixer_Channel_List[channel].almixer_data->eof = 0; | |
607 */ | |
608 | |
609 ALmixer_Channel_List[channel].almixer_data = NULL; | |
610 } | |
611 | |
612 | |
613 #if 0 | |
614 /* Not needed anymore because not doing any fileext checks. | |
615 * | |
616 * Unfortunately, strcasecmp isn't portable so here's a | |
617 * reimplementation of it (taken from SDL_sound) | |
618 */ | |
619 static int ALmixer_strcasecmp(const char* x, const char* y) | |
620 { | |
621 int ux, uy; | |
622 | |
623 if (x == y) /* same pointer? Both NULL? */ | |
624 return(0); | |
625 | |
626 if (x == NULL) | |
627 return(-1); | |
628 | |
629 if (y == NULL) | |
630 return(1); | |
631 | |
632 do | |
633 { | |
634 ux = toupper((int) *x); | |
635 uy = toupper((int) *y); | |
636 if (ux > uy) | |
637 return(1); | |
638 else if (ux < uy) | |
639 return(-1); | |
640 x++; | |
641 y++; | |
642 } while ((ux) && (uy)); | |
643 | |
644 return(0); | |
645 } | |
646 #endif | |
647 | |
648 | |
649 /* What shoud this return? | |
650 * 127 for signed, 255 for unsigned | |
651 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
652 static ALubyte GetSignednessValue(ALushort format) |
0 | 653 { |
654 switch(format) | |
655 { | |
656 case AUDIO_U8: | |
657 case AUDIO_U16LSB: | |
658 case AUDIO_U16MSB: | |
659 return ALMIXER_UNSIGNED_VALUE; | |
660 break; | |
661 case AUDIO_S8: | |
662 case AUDIO_S16LSB: | |
663 case AUDIO_S16MSB: | |
664 return ALMIXER_SIGNED_VALUE; | |
665 break; | |
666 default: | |
667 return 0; | |
668 } | |
669 return 0; | |
670 } | |
671 | |
672 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
673 static ALubyte GetBitDepth(ALushort format) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
674 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
675 ALubyte bit_depth = 16; |
0 | 676 |
677 switch(format) | |
678 { | |
679 case AUDIO_U8: | |
680 case AUDIO_S8: | |
681 bit_depth = 8; | |
682 break; | |
683 | |
684 case AUDIO_U16LSB: | |
685 /* | |
686 case AUDIO_U16: | |
687 */ | |
688 case AUDIO_S16LSB: | |
689 /* | |
690 case AUDIO_S16: | |
691 */ | |
692 case AUDIO_U16MSB: | |
693 case AUDIO_S16MSB: | |
694 /* | |
695 case AUDIO_U16SYS: | |
696 case AUDIO_S16SYS: | |
697 */ | |
698 bit_depth = 16; | |
699 break; | |
700 default: | |
701 bit_depth = 0; | |
702 } | |
703 return bit_depth; | |
704 } | |
705 | |
706 /* Need to translate between SDL/SDL_Sound audiospec | |
707 * and OpenAL conventions */ | |
708 static ALenum TranslateFormat(Sound_AudioInfo* info) | |
709 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
710 ALubyte bit_depth; |
0 | 711 |
712 bit_depth = GetBitDepth(info->format); | |
713 if(0 == bit_depth) | |
714 { | |
715 fprintf(stderr, "Warning: Unknown bit depth. Setting to 16\n"); | |
716 bit_depth = 16; | |
717 } | |
718 | |
719 if(2 == info->channels) | |
720 { | |
721 if(16 == bit_depth) | |
722 { | |
723 return AL_FORMAT_STEREO16; | |
724 } | |
725 else | |
726 { | |
727 return AL_FORMAT_STEREO8; | |
728 } | |
729 } | |
730 else | |
731 { | |
732 if(16 == bit_depth) | |
733 { | |
734 return AL_FORMAT_MONO16; | |
735 } | |
736 else | |
737 { | |
738 return AL_FORMAT_MONO8; | |
739 } | |
740 } | |
741 /* Make compiler happy. Shouldn't get here */ | |
742 return AL_FORMAT_STEREO16; | |
743 } | |
744 | |
1 | 745 |
746 /* This will compute the total playing time | |
747 * based upon the number of bytes and audio info. | |
748 * (In prinicple, it should compute the time for any given length) | |
749 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
750 static ALuint Compute_Total_Time_Decomposed(ALuint bytes_per_sample, ALuint frequency, ALubyte channels, size_t total_bytes) |
1 | 751 { |
752 double total_sec; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
753 ALuint total_msec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
754 ALuint bytes_per_sec; |
1 | 755 |
756 if(0 == total_bytes) | |
757 { | |
758 return 0; | |
759 } | |
760 /* To compute Bytes per second, do | |
761 * samples_per_sec * bytes_per_sample * number_of_channels | |
762 */ | |
763 bytes_per_sec = frequency * bytes_per_sample * channels; | |
764 | |
765 /* Now to get total time (sec), do | |
766 * total_bytes / bytes_per_sec | |
767 */ | |
768 total_sec = total_bytes / (double)bytes_per_sec; | |
769 | |
770 /* Now convert seconds to milliseconds | |
771 * Add .5 to the float to do rounding before the final cast | |
772 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
773 total_msec = (ALuint) ( (total_sec * 1000) + 0.5 ); |
1 | 774 /* |
775 fprintf(stderr, "freq=%d, bytes_per_sample=%d, channels=%d, total_msec=%d\n", frequency, bytes_per_sample, channels, total_msec); | |
776 */ | |
777 return total_msec; | |
778 } | |
779 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
780 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
|
781 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
782 ALuint bytes_per_sample; |
1 | 783 |
784 if(0 == total_bytes) | |
785 { | |
786 return 0; | |
787 } | |
788 /* 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
|
789 * 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
|
790 * 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
|
791 * 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
|
792 * 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
|
793 * 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
|
794 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
795 bytes_per_sample = (ALuint) ((info->format & 0xFF) / 8); |
1 | 796 |
797 return Compute_Total_Time_Decomposed(bytes_per_sample, info->rate, info->channels, total_bytes); | |
798 } /* End Compute_Total_Time */ | |
799 | |
800 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
801 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
|
802 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
803 double total_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
804 ALuint bytes_per_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
805 size_t total_bytes; |
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 if(0 >= total_msec) |
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 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
810 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
811 /* To compute Bytes per second, do |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
812 * 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
|
813 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
814 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
|
815 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
816 /* convert milliseconds to seconds */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
817 total_sec = total_msec / 1000.0; |
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 /* Now to get total bytes */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
820 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
|
821 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
822 /* 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
|
823 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
824 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
825 return total_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
826 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
827 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
828 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
|
829 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
830 ALuint bytes_per_sample; |
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 if(0 >= total_msec) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
833 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
834 return 0; |
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 /* 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
|
837 * 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
|
838 * 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
|
839 * 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
|
840 * 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
|
841 * 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
|
842 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
843 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
|
844 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
845 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
|
846 } |
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 /* 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
|
849 * 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
|
850 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
851 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
|
852 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
853 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
854 ALuint bytes_per_frame; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
855 size_t evenly_divisible_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
856 size_t remainder_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
857 size_t return_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
858 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
859 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
|
860 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
861 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
|
862 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
863 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
|
864 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
865 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
|
866 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
|
867 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
868 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
|
869 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
870 /* 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
|
871 * 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
|
872 * 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
|
873 * 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
|
874 * 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
|
875 * 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
|
876 * 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
|
877 * 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
|
878 * 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
|
879 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
880 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
881 return_bytes += 64; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
882 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
883 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
884 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
|
885 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
886 return return_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
887 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
888 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
889 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
890 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
891 |
1 | 892 |
0 | 893 /**************** REMOVED ****************************/ |
894 /* This was removed because I originally thought | |
895 * OpenAL could return a pointer to the buffer data, | |
896 * but I was wrong. If something like that is ever | |
897 * implemented, then this might become useful. | |
898 */ | |
899 #if 0 | |
900 /* Reconstruct_Sound_Sample and Set_AudioInfo only | |
901 * are needed if the Seek memory optimization is | |
902 * used. Also, the Loki dist doesn't seem to support | |
903 * AL_DATA which I need for it. | |
904 */ | |
905 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION | |
906 | |
907 static void Set_AudioInfo(Sound_AudioInfo* info, ALint frequency, ALint bits, ALint channels) | |
908 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
909 info->rate = (ALuint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
910 info->channels = (ALubyte)channels; |
0 | 911 |
912 /* Not sure if it should be signed or unsigned. Hopefully | |
913 * that detail won't be needed. | |
914 */ | |
915 if(8 == bits) | |
916 { | |
917 info->format = AUDIO_U8; | |
918 } | |
919 else | |
920 { | |
921 info->format = AUDIO_U16SYS; | |
922 } | |
923 fprintf(stderr, "Audio info: freq=%d, chan=%d, format=%d\n", | |
924 info->rate, info->channels, info->format); | |
925 | |
926 } | |
927 | |
928 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
929 static ALint Reconstruct_Sound_Sample(ALmixer_Data* data) |
0 | 930 { |
931 ALenum error; | |
932 ALint* data_from_albuffer; | |
933 ALint freq; | |
934 ALint bits; | |
935 ALint channels; | |
936 ALint size; | |
937 | |
938 /* Create memory all initiallized to 0. */ | |
939 data->sample = (Sound_Sample*)calloc(1, sizeof(Sound_Sample)); | |
940 if(NULL == data->sample) | |
941 { | |
942 ALmixer_SetError("Out of memory for Sound_Sample"); | |
943 return -1; | |
944 } | |
945 | |
946 /* Clear errors */ | |
947 alGetError(); | |
948 | |
949 alGetBufferi(data->buffer[0], AL_FREQUENCY, &freq); | |
950 if((error = alGetError()) != AL_NO_ERROR) | |
951 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
952 ALmixer_SetError("alGetBufferi(AL_FREQUENCY): %s", alGetString(error) ); |
0 | 953 free(data->sample); |
954 data->sample = NULL; | |
955 return -1; | |
956 } | |
957 | |
958 alGetBufferi(data->buffer[0], AL_BITS, &bits); | |
959 if((error = alGetError()) != AL_NO_ERROR) | |
960 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
961 ALmixer_SetError("alGetBufferi(AL_BITS): %s", alGetString(error) ); |
0 | 962 free(data->sample); |
963 data->sample = NULL; | |
964 return -1; | |
965 } | |
966 | |
967 alGetBufferi(data->buffer[0], AL_CHANNELS, &channels); | |
968 if((error = alGetError()) != AL_NO_ERROR) | |
969 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
970 ALmixer_SetError("alGetBufferi(AL_CHANNELS): %s", alGetString(error) ); |
0 | 971 free(data->sample); |
972 data->sample = NULL; | |
973 return -1; | |
974 } | |
975 | |
976 alGetBufferi(data->buffer[0], AL_SIZE, &size); | |
977 if((error = alGetError()) != AL_NO_ERROR) | |
978 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
979 ALmixer_SetError("alGetBufferi(AL_SIZE): %s", alGetString(error) ); |
0 | 980 free(data->sample); |
981 data->sample = NULL; | |
982 return -1; | |
983 } | |
984 | |
985 alGetBufferi(data->buffer[0], AL_DATA, data_from_albuffer); | |
986 if((error = alGetError()) != AL_NO_ERROR) | |
987 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
988 ALmixer_SetError("alGetBufferi(AL_DATA): %s", alGetString(error) ); |
0 | 989 free(data->sample); |
990 data->sample = NULL; | |
991 return -1; | |
992 } | |
993 | |
994 if(size <= 0) | |
995 { | |
996 ALmixer_SetError("No data in al buffer"); | |
997 free(data->sample); | |
998 data->sample = NULL; | |
999 return -1; | |
1000 } | |
1001 | |
1002 /* Now that we have all the attributes, we need to | |
1003 * allocate memory for the buffer and reconstruct | |
1004 * the AudioInfo attributes. | |
1005 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1006 data->sample->buffer = malloc(size*sizeof(ALbyte)); |
0 | 1007 if(NULL == data->sample->buffer) |
1008 { | |
1009 ALmixer_SetError("Out of memory for sample->buffer"); | |
1010 free(data->sample); | |
1011 data->sample = NULL; | |
1012 return -1; | |
1013 } | |
1014 | |
1015 memcpy(data->sample->buffer, data_from_albuffer, size); | |
1016 data->sample->buffer_size = size; | |
1017 | |
1018 /* Fill up the Sound_AudioInfo structures */ | |
1019 Set_AudioInfo(&data->sample->desired, freq, bits, channels); | |
1020 Set_AudioInfo(&data->sample->actual, freq, bits, channels); | |
1021 | |
1022 return 0; | |
1023 } | |
1024 | |
1025 #endif /* End DISABLE_SEEK_MEMORY_OPTIMIZATION */ | |
1026 #endif | |
1027 /*************** END REMOVED *************************/ | |
1028 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1029 static void Invoke_Channel_Done_Callback(ALint which_channel, ALboolean did_finish_naturally) |
0 | 1030 { |
1031 if(NULL == Channel_Done_Callback) | |
1032 { | |
1033 return; | |
1034 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1035 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
|
1036 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1037 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1038 static ALint LookUpBuffer(ALuint buffer, ALmixer_Buffer_Map* buffer_map_list, ALuint num_items_in_list) |
0 | 1039 { |
1040 /* Only the first value is used for the key */ | |
1 | 1041 ALmixer_Buffer_Map key = { 0, 0, NULL, 0 }; |
1042 ALmixer_Buffer_Map* found_item = NULL; | |
0 | 1043 key.albuffer = buffer; |
1044 | |
1045 /* Use the ANSI C binary search feature (yea!) */ | |
1 | 1046 found_item = (ALmixer_Buffer_Map*)bsearch(&key, buffer_map_list, num_items_in_list, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 1047 if(NULL == found_item) |
1048 { | |
1049 ALmixer_SetError("Can't find buffer"); | |
1050 return -1; | |
1051 } | |
1052 return found_item->index; | |
1053 } | |
1054 | |
1055 | |
1056 /* FIXME: Need to pass back additional info to be useful. | |
1057 * Bit rate, stereo/mono (num chans), time in msec? | |
1058 * Precoded/streamed flag so user can plan for future data? | |
1059 */ | |
1 | 1060 /* |
1061 * channels: 1 for mono, 2 for stereo | |
1062 * | |
1063 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1064 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
|
1065 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1066 ALboolean is_unsigned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1067 ALubyte bits_per_sample = GetBitDepth(format); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1068 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1069 ALuint length_in_msec; |
1 | 1070 |
1071 if(GetSignednessValue(format) == ALMIXER_UNSIGNED_VALUE) | |
1072 { | |
1073 is_unsigned = 1; | |
1074 } | |
1075 else | |
1076 { | |
1077 is_unsigned = 0; | |
1078 } | |
1079 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1080 bytes_per_sample = (ALuint) (bits_per_sample / 8); |
1 | 1081 |
1082 length_in_msec = Compute_Total_Time_Decomposed(bytes_per_sample, frequency, channels, num_bytes); | |
1083 | |
0 | 1084 /* |
1085 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); | |
1086 */ | |
1087 if(NULL == Channel_Data_Callback) | |
1088 { | |
1089 return; | |
1090 } | |
1 | 1091 /* |
1092 * Channel_Data_Callback(which_channel, data, num_bytes, frequency, channels, GetBitDepth(format), format, decode_mode_is_predecoded); | |
1093 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1094 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
|
1095 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1096 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1097 static void Invoke_Predecoded_Channel_Data_Callback(ALint channel, ALmixer_Data* data) |
0 | 1098 { |
1099 if(NULL == data->sample) | |
1100 { | |
1101 return; | |
1102 } | |
1103 /* The buffer position is complicated because if the current data was seeked, | |
1104 * we must adjust the buffer to the seek position | |
1105 */ | |
1106 Invoke_Channel_Data_Callback(channel, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1107 (((ALbyte*) data->sample->buffer) + (data->total_bytes - data->loaded_bytes) ), |
0 | 1108 data->loaded_bytes, |
1109 data->sample->desired.rate, | |
1110 data->sample->desired.channels, | |
1111 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1112 AL_TRUE |
0 | 1113 ); |
1114 } | |
1115 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1116 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
|
1117 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1118 ALint index; |
0 | 1119 if(NULL == data->buffer_map_list) |
1120 { | |
1121 return; | |
1122 } | |
1123 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1124 /* This should catch the case where all buffers are unqueued | |
1125 * and the "current" buffer is id: 0 | |
1126 */ | |
1127 if(-1 == index) | |
1128 { | |
1129 return; | |
1130 } | |
1131 Invoke_Channel_Data_Callback(channel, | |
1132 data->buffer_map_list[index].data, | |
1133 data->buffer_map_list[index].num_bytes, | |
1134 data->sample->desired.rate, | |
1135 data->sample->desired.channels, | |
1136 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1137 AL_FALSE |
0 | 1138 ); |
1139 } | |
1140 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1141 /* Converts milliseconds to byte positions. |
0 | 1142 * This is needed for seeking on predecoded samples |
1143 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1144 static ALuint Convert_Msec_To_Byte_Pos(Sound_AudioInfo *info, ALuint ms) |
0 | 1145 { |
1146 float frames_per_ms; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1147 ALuint frame_offset; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1148 ALuint frame_size; |
0 | 1149 if(info == NULL) |
1150 { | |
1151 fprintf(stderr, "Error, info is NULL\n"); | |
1152 } | |
1153 | |
1154 /* "frames" == "sample frames" */ | |
1155 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
|
1156 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
|
1157 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
|
1158 return frame_offset * frame_size; |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1159 } |
0 | 1160 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1161 static ALint Set_Predecoded_Seek_Position(ALmixer_Data* data, ALuint byte_position) |
0 | 1162 { |
1163 ALenum error; | |
1164 /* clear error */ | |
1165 alGetError(); | |
1166 | |
1167 /* Is it greater than, or greater-than or equal to ?? */ | |
1168 if(byte_position > data->total_bytes) | |
1169 { | |
1170 /* 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
|
1171 /* |
0 | 1172 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
|
1173 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1174 |
0 | 1175 /* In case the below thing doesn't work, |
1176 * just rewind the whole thing. | |
1177 * | |
1178 alBufferData(data->buffer[0], | |
1179 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1180 (ALbyte*) data->sample->buffer, |
0 | 1181 data->total_bytes, |
1182 data->sample->desired.rate | |
1183 ); | |
1184 */ | |
1185 | |
1186 /* I was trying to set to the end, (1 byte remaining), | |
1187 * but I was getting freezes. I'm thinking it might be | |
1188 * another Power of 2 bug in the Loki dist. I tried 2, | |
1189 * and it still hung. 4 didn't hang, but I got a clip | |
1190 * artifact. 8 seemed to work okay. | |
1191 */ | |
1192 alBufferData(data->buffer[0], | |
1193 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1194 (((ALbyte*) data->sample->buffer) + (data->total_bytes - 8) ), |
0 | 1195 8, |
1196 data->sample->desired.rate | |
1197 ); | |
1198 if( (error = alGetError()) != AL_NO_ERROR) | |
1199 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1200 ALmixer_SetError("Can't seek past end and alBufferData failed: %s\n", alGetString(error)); |
0 | 1201 return -1; |
1202 } | |
1203 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1204 * query command to work because I don't know if it will mutilate the | |
1205 * size for its own purposes or return the original size | |
1206 */ | |
1207 data->loaded_bytes = 8; | |
1208 | |
1209 /* Not sure if this should be an error or not */ | |
1210 /* | |
1211 ALmixer_SetError("Can't Seek past end"); | |
1212 return -1; | |
1213 */ | |
1214 return 0; | |
1215 } | |
1216 | |
1217 alBufferData(data->buffer[0], | |
1218 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1219 &(((ALbyte*)data->sample->buffer)[byte_position]), |
0 | 1220 data->total_bytes - byte_position, |
1221 data->sample->desired.rate | |
1222 ); | |
1223 if( (error = alGetError()) != AL_NO_ERROR) | |
1224 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1225 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1226 return -1; |
1227 } | |
1228 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1229 * query command to work because I don't know if it will mutilate the | |
1230 * size for its own purposes or return the original size | |
1231 */ | |
1232 data->loaded_bytes = data->total_bytes - byte_position; | |
1233 | |
1234 return 0; | |
1235 } | |
1236 | |
1237 /* Because we have multiple queue buffers and OpenAL won't let | |
1238 * us access them, we need to keep copies of each buffer around | |
1239 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1240 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
|
1241 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1242 ALint index; |
0 | 1243 /* We only want to copy if access_data is true. |
1244 * This is determined by whether memory has been | |
1245 * allocated in the buffer_map_list or not | |
1246 */ | |
1247 if(NULL == data->buffer_map_list) | |
1248 { | |
1249 return -1; | |
1250 } | |
1251 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1252 if(-1 == index) | |
1253 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1254 /* |
0 | 1255 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
|
1256 */ |
0 | 1257 return -1; |
1258 } | |
1259 /* Copy the data to the access buffer */ | |
1260 memcpy(data->buffer_map_list[index].data, data->sample->buffer, num_bytes); | |
1261 data->buffer_map_list[index].num_bytes = data->sample->buffer_size; | |
1262 | |
1263 return 0; | |
1264 } | |
1265 | |
1266 | |
1267 /* For streamed data, gets more data | |
1268 * and prepares it in the active Mix_chunk | |
1269 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1270 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
|
1271 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1272 ALuint bytes_decoded; |
0 | 1273 ALenum error; |
1274 if(NULL == data) | |
1275 { | |
1276 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1277 return 0; | |
1278 } | |
1279 | |
1280 bytes_decoded = Sound_Decode(data->sample); | |
1281 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1282 { | |
1283 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1284 ALmixer_SetError(Sound_GetError()); | |
1285 /* Force cleanup through FreeData | |
1286 Sound_FreeSample(data->sample); | |
1287 */ | |
1288 return 0; | |
1289 } | |
1290 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1291 /* 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
|
1292 |
0 | 1293 /* Don't forget to add check for EOF */ |
1294 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1295 if(0 == bytes_decoded) | |
1296 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1297 data->eof = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1298 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1299 #if 0 |
0 | 1300 fprintf(stderr, "Hit eof while trying to buffer\n"); |
1301 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1302 { | |
1303 fprintf(stderr, "\tEOF flag\n"); | |
1304 } | |
1305 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1306 { | |
1307 fprintf(stderr, "\tCanSeek flag\n"); | |
1308 } | |
1309 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1310 { | |
1311 fprintf(stderr, "\tEAGAIN flag\n"); | |
1312 } | |
1313 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1314 { | |
1315 fprintf(stderr, "\tNONE flag\n"); | |
1316 } | |
1317 #endif | |
1318 return 0; | |
1319 } | |
1320 | |
1321 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
1322 /******* REMOVE ME ********************************/ | |
1323 /***************** ANOTHER EXPERIEMENT *******************/ | |
1324 /* The PROBLEM: It seems that the Loki distribution has problems | |
1325 * with Queuing when the buffer size is not a power of two | |
1326 * and additional buffers must come after it. | |
1327 * The behavior is inconsistent, but one of several things | |
1328 * usually happens: | |
1329 * Playback is normal | |
1330 * Playback immediately stops after the non-pow2 buffer | |
1331 * Playback gets distorted on the non-pow2 buffer | |
1332 * The entire program segfaults. | |
1333 * The workaround is to always specify a power of two buffer size | |
1334 * and hope that SDL_sound always fill it. (By lucky coincidence, | |
1335 * I already submitted the Ogg fix.) However, this won't catch | |
1336 * cases where a loop happens because the read at the end of the | |
1337 * file is typically less than the buffer size. | |
1338 * | |
1339 * This fix addresses this issue, however it may break in | |
1340 * other conditions. Always decode in buffer sizes of powers of 2. | |
1341 * | |
1342 * The HACK: | |
1343 * If the buffer is short, try filling it up with 0's | |
1344 * to meet the user requested buffer_size which | |
1345 * is probably a nice number OpenAL likes, in | |
1346 * hopes to avoid a possible Loki bug with | |
1347 * short buffers. If looping (which is the main | |
1348 * reason for this), the negative side effect is | |
1349 * that it may take longer for the loop to start | |
1350 * because it must play dead silence. Or if the decoder | |
1351 * doesn't guarantee to return the requested bytes | |
1352 * (like Ogg), then you will get breakup in between | |
1353 * packets. | |
1354 */ | |
1355 if( (bytes_decoded) < data->sample->buffer_size) | |
1356 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1357 ALubyte bit_depth; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1358 ALubyte signedness_value; |
0 | 1359 int silence_value; |
1360 /* Crap, memset value needs to be the "silent" value, | |
1361 * but it will differ for signed/unsigned and bit depth | |
1362 */ | |
1363 bit_depth = GetBitDepth(data->sample->desired.format); | |
1364 signedness_value = GetSignednessValue(data->sample->desired.format); | |
1365 if(ALMIXER_SIGNED_VALUE == signedness_value) | |
1366 { | |
1367 /* I'm guessing that if it's signed, then 0 is the | |
1368 * "silent" value */ | |
1369 silence_value = 0; | |
1370 } | |
1371 else | |
1372 { | |
1373 if(8 == bit_depth) | |
1374 { | |
1375 /* If 8 bit, I'm guessing it's (2^7)-1 = 127 */ | |
1376 silence_value = 127; | |
1377 } | |
1378 else | |
1379 { | |
1380 /* For 16 bit, I'm guessing it's (2^15)-1 = 32767 */ | |
1381 silence_value = 32767; | |
1382 } | |
1383 } | |
1384 /* Now fill up the rest of the data buffer with the | |
1385 * silence_value. | |
1386 * I don't think I have to worry about endian issues for | |
1387 * this part since the data is for internal use only | |
1388 * at this point. | |
1389 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1390 memset( &( ((ALbyte*)(data->sample->buffer))[bytes_decoded] ), silence_value, data->sample->buffer_size - bytes_decoded); |
0 | 1391 /* Now reset the bytes_decoded to reflect the entire |
1392 * buffer to tell alBufferData what our full size is. | |
1393 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1394 /* |
0 | 1395 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
|
1396 */ |
0 | 1397 bytes_decoded = data->sample->buffer_size; |
1398 } | |
1399 /*********** END EXPERIMENT ******************************/ | |
1400 /******* END REMOVE ME ********************************/ | |
1401 #endif | |
1402 | |
1403 /* Now copy the data to the OpenAL buffer */ | |
1404 /* We can't just set a pointer because the API needs | |
1405 * its own copy to assist hardware acceleration */ | |
1406 alBufferData(buffer, | |
1407 TranslateFormat(&data->sample->desired), | |
1408 data->sample->buffer, | |
1409 bytes_decoded, | |
1410 data->sample->desired.rate | |
1411 ); | |
1412 if( (error = alGetError()) != AL_NO_ERROR) | |
1413 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1414 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1415 return 0; |
1416 } | |
1417 | |
1418 /* If we need to, copy the data also to the access area | |
1419 * (the function will do the check for us) | |
1420 */ | |
1421 CopyDataToAccessBuffer(data, bytes_decoded, buffer); | |
1422 return bytes_decoded; | |
1423 } | |
1424 | |
1425 | |
1426 | |
1427 | |
1428 /******************** EXPERIEMENT **************************** | |
1429 * Test function to force maximum buffer filling during loops | |
1430 * REMOVE LATER | |
1431 *********************************************/ | |
1432 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1433 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
|
1434 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1435 ALint bytes_decoded; |
0 | 1436 ALenum error; |
1437 if(NULL == data) | |
1438 { | |
1439 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1440 return -1; | |
1441 } | |
1442 | |
1443 if(AL_FALSE == alIsBuffer(buffer)) | |
1444 { | |
1445 fprintf(stderr, "NOT A BUFFER>>>>>>>>>>>>>>>\n"); | |
1446 return -1; | |
1447 } | |
1448 fprintf(stderr, "Entered GetMoreData222222: buffer id is %d\n", buffer); | |
1449 | |
1450 /* | |
1451 fprintf(stderr, "Decode in GetMoreData\n"); | |
1452 */ | |
1453 | |
1454 #if 0 | |
1455 if(buffer%2 == 1) | |
1456 { | |
1457 fprintf(stderr, "Setting buffer size to 16384\n"); | |
1458 Sound_SetBufferSize(data->sample, 16384); | |
1459 } | |
1460 else | |
1461 { | |
1462 fprintf(stderr, "Setting buffer size to 8192\n"); | |
1463 Sound_SetBufferSize(data->sample, 8192); | |
1464 } | |
1465 #endif | |
1466 | |
1467 bytes_decoded = Sound_Decode(data->sample); | |
1468 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1469 { | |
1470 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1471 ALmixer_SetError(Sound_GetError()); | |
1472 /* | |
1473 Sound_FreeSample(data->sample); | |
1474 */ | |
1475 return -1; | |
1476 } | |
1477 /* Don't forget to add check for EOF */ | |
1478 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1479 if(0 == bytes_decoded) | |
1480 { | |
1481 #if 1 | |
1482 fprintf(stderr, "Hit eof while trying to buffer\n"); | |
1483 data->eof = 1; | |
1484 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1485 { | |
1486 fprintf(stderr, "\tEOF flag\n"); | |
1487 } | |
1488 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1489 { | |
1490 fprintf(stderr, "\tCanSeek flag\n"); | |
1491 } | |
1492 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1493 { | |
1494 fprintf(stderr, "\tEAGAIN flag\n"); | |
1495 } | |
1496 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1497 { | |
1498 fprintf(stderr, "\tNONE flag\n"); | |
1499 } | |
1500 #endif | |
1501 return 0; | |
1502 } | |
1503 | |
1504 if(bytes_decoded < 16384) | |
1505 { | |
1506 char* tempbuffer1 = (char*)malloc(16384); | |
1507 char* tempbuffer2 = (char*)malloc(16384); | |
1508 int retval; | |
1509 memcpy(tempbuffer1, data->sample->buffer, bytes_decoded); | |
1510 retval = Sound_SetBufferSize(data->sample, 16384-bytes_decoded); | |
1511 if(retval == 1) | |
1512 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1513 ALuint new_bytes; |
0 | 1514 Sound_Rewind(data->sample); |
1515 new_bytes = Sound_Decode(data->sample); | |
1516 fprintf(stderr, "Orig bytes: %d, Make up bytes_decoded=%d, total=%d\n", bytes_decoded, new_bytes, new_bytes+bytes_decoded); | |
1517 | |
1518 memcpy(tempbuffer2, data->sample->buffer, new_bytes); | |
1519 | |
1520 retval = Sound_SetBufferSize(data->sample, 16384); | |
1521 fprintf(stderr, "Finished reset...now danger copy\n"); | |
1522 memcpy(data->sample->buffer, tempbuffer1,bytes_decoded); | |
1523 | |
1524 fprintf(stderr, "Finished reset...now danger copy2\n"); | |
1525 memcpy( &( ((char*)(data->sample->buffer))[bytes_decoded] ), tempbuffer2, new_bytes); | |
1526 | |
1527 fprintf(stderr, "Finished \n"); | |
1528 | |
1529 free(tempbuffer1); | |
1530 free(tempbuffer2); | |
1531 bytes_decoded += new_bytes; | |
1532 fprintf(stderr, "ASSERT bytes should equal 16384: %d\n", bytes_decoded); | |
1533 } | |
1534 else | |
1535 { | |
1536 fprintf(stderr, "Experiment failed: %s\n", Sound_GetError()); | |
1537 } | |
1538 } | |
1539 | |
1540 /* Now copy the data to the OpenAL buffer */ | |
1541 /* We can't just set a pointer because the API needs | |
1542 * its own copy to assist hardware acceleration */ | |
1543 alBufferData(buffer, | |
1544 TranslateFormat(&data->sample->desired), | |
1545 data->sample->buffer, | |
1546 bytes_decoded, | |
1547 data->sample->desired.rate | |
1548 ); | |
1549 if( (error = alGetError()) != AL_NO_ERROR) | |
1550 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1551 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1552 return -1; |
1553 } | |
1554 | |
1555 fprintf(stderr, "GetMoreData2222 returning %d bytes decoded\n", bytes_decoded); | |
1556 return bytes_decoded; | |
1557 } | |
1558 #endif | |
1559 | |
1560 /************ END EXPERIEMENT - REMOVE ME *************************/ | |
1561 | |
1562 | |
1563 | |
1564 | |
1565 | |
1566 | |
1567 | |
1568 | |
1569 | |
1570 /* This function will look up the source for the corresponding channel */ | |
1571 /* 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
|
1572 static ALuint Internal_GetSource(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1573 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1574 ALint i; |
0 | 1575 /* Make sure channel is in bounds */ |
1576 if(channel >= Number_of_Channels_global) | |
1577 { | |
1578 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); | |
1579 return 0; | |
1580 } | |
1581 /* If the user specified -1, then return the an available source */ | |
1582 if(channel < 0) | |
1583 { | |
1584 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1585 { | |
1586 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1587 { | |
1588 return ALmixer_Channel_List[i].alsource; | |
1589 } | |
1590 } | |
1591 /* If we get here, all sources are in use */ | |
1592 /* Error message seems too harsh | |
1593 ALmixer_SetError("All sources are in use"); | |
1594 */ | |
1595 return 0; | |
1596 } | |
1597 /* Last case: Return the source for the channel */ | |
1598 return ALmixer_Channel_List[channel].alsource; | |
1599 } | |
1600 | |
1601 /* 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
|
1602 static ALint Internal_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1603 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1604 ALint i; |
0 | 1605 /* Only the first value is used for the key */ |
1606 Source_Map key = { 0, 0 }; | |
1607 Source_Map* found_item = NULL; | |
1608 key.source = source; | |
1609 | |
1610 /* If the source is 0, look up the first available channel */ | |
1611 if(0 == source) | |
1612 { | |
1613 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1614 { | |
1615 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1616 { | |
1617 return i; | |
1618 } | |
1619 } | |
1620 /* If we get here, all sources are in use */ | |
1621 /* Error message seems too harsh | |
1622 ALmixer_SetError("All channels are in use"); | |
1623 */ | |
1624 return -1; | |
1625 } | |
1626 | |
1627 | |
1628 /* Else, look up the source and return the channel */ | |
1629 if(AL_FALSE == alIsSource(source)) | |
1630 { | |
1631 ALmixer_SetError("Is not a source"); | |
1632 return -1; | |
1633 } | |
1634 | |
1635 /* Use the ANSI C binary search feature (yea!) */ | |
1636 found_item = (Source_Map*)bsearch(&key, Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
1637 if(NULL == found_item) | |
1638 { | |
1639 ALmixer_SetError("Source is valid but not registered with ALmixer (to a channel)"); | |
1640 return -1; | |
1641 } | |
1642 return found_item->channel; | |
1643 } | |
1644 | |
1645 | |
1646 | |
1647 /* This function will find the first available channel (not in use) | |
1648 * from the specified start channel. Reserved channels to not qualify | |
1649 * as available. | |
1650 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1651 static ALint Internal_FindFreeChannel(ALint start_channel) |
0 | 1652 { |
1653 /* Start at the number of reserved so we skip over | |
1654 * all the reserved channels. | |
1655 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1656 ALint i = Number_of_Reserve_Channels_global; |
0 | 1657 /* Quick check to see if we're out of bounds */ |
1658 if(start_channel >= Number_of_Channels_global) | |
1659 { | |
1660 return -1; | |
1661 } | |
1662 | |
1663 /* If the start channel is even higher than the reserved, | |
1664 * then start at the higher value. | |
1665 */ | |
1666 if(start_channel > Number_of_Reserve_Channels_global) | |
1667 { | |
1668 i = start_channel; | |
1669 } | |
1670 | |
1671 /* i has already been set */ | |
1672 for( ; i<Number_of_Channels_global; i++) | |
1673 { | |
1674 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1675 { | |
1676 return i; | |
1677 } | |
1678 } | |
1679 /* If we get here, all sources are in use */ | |
1680 return -1; | |
1681 } | |
1682 | |
1683 | |
1684 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1685 /* 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
|
1686 * or 0 for error |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1687 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1688 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
|
1689 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1690 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1691 ALint counter = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1692 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1693 ALint buffers_still_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1694 ALint buffers_processed; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1695 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1696 if(channel >= Number_of_Channels_global) |
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 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
|
1699 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1700 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1701 /* 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
|
1702 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1703 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1704 /* 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
|
1705 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
|
1706 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1707 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1708 if((error = alGetError()) != AL_NO_ERROR) |
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 fprintf(stderr, "14Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1711 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1712 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1713 /* 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
|
1714 * 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
|
1715 * 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
|
1716 * 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
|
1717 * 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
|
1718 * 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
|
1719 * 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
|
1720 * 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
|
1721 * 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
|
1722 * 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
|
1723 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1724 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1725 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1726 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1727 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1728 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1729 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1730 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1731 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
|
1732 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1733 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
|
1734 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1735 retval = -1; |
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 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1738 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1739 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1740 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1741 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1742 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1743 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
|
1744 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1745 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
|
1746 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1747 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1748 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1749 /* 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
|
1750 * to clear the source |
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 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
|
1753 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1754 alSourcei(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1755 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1756 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1757 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1758 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1759 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
|
1760 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1761 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
|
1762 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1763 retval = -1; |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1766 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1767 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
|
1768 |
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
|
1769 /* 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
|
1770 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
|
1771 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1772 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1773 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1774 counter++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1775 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1776 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1777 /* 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
|
1778 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1779 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1780 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1781 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
|
1782 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1783 /* 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
|
1784 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
|
1785 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1786 alSourceStop(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1787 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1788 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1789 fprintf(stderr, "19Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1790 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1791 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1792 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1793 /* 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
|
1794 * 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
|
1795 * 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
|
1796 * 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
|
1797 * 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
|
1798 * 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
|
1799 * 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
|
1800 * 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
|
1801 * 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
|
1802 * 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
|
1803 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1804 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1805 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1806 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1807 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1808 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1809 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1810 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1811 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
|
1812 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1813 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
|
1814 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1815 retval = -1; |
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 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1818 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1819 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1820 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1821 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1822 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1823 fprintf(stderr, "17Testing Error with buffers_processed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1824 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1825 ALmixer_SetError("Failed detecting still processed buffers: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1826 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1827 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1828 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1829 /* 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
|
1830 * to clear the source |
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 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
|
1833 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1834 alSourcei(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1835 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1836 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1837 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1838 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1839 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
|
1840 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1841 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
|
1842 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1843 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1844 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1845 } |
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 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
|
1848 |
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
|
1849 /* 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
|
1850 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
|
1851 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1852 Clean_Channel(i); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1853 Is_Playing_global--; |
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 /* Increment the counter */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1856 counter++; |
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 /* 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
|
1859 * are bugs. |
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 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1862 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1863 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1864 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1865 / * 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
|
1866 * data will get messed up * / |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1867 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1868 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1869 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1870 /* Just in case */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1871 Is_Playing_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1872 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1873 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1874 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1875 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1876 return -1; |
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 return counter; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1879 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1880 |
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 /* 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
|
1883 * 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
|
1884 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1885 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
|
1886 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1887 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1888 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1889 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1890 /* 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
|
1891 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
|
1892 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1893 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1894 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1895 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1896 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1897 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
|
1898 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1899 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1900 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
|
1901 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1902 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1903 |
0 | 1904 |
1905 /* Note: Behaves, almost like SDL_mixer, but keep in mind | |
1906 * that there is no "music" channel anymore, so 0 | |
1907 * will remove everything. (Note, I no longer allow 0 | |
1908 * so it gets set to the default number.) | |
1909 * Also, callbacks for deleted channels will not be called. | |
1910 * I really need to do error checking, for realloc and | |
1911 * GenSources, but reversing the damage is too painful | |
1912 * for me to think about at the moment, so it's not in here. | |
1913 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1914 static ALint Internal_AllocateChannels(ALint numchans) |
0 | 1915 { |
1916 ALenum error; | |
1917 int i; | |
1918 /* Return info */ | |
1919 if(numchans < 0) | |
1920 { | |
1921 return Number_of_Channels_global; | |
1922 } | |
1923 if(0 == numchans) | |
1924 { | |
1925 numchans = ALMIXER_DEFAULT_NUM_CHANNELS; | |
1926 } | |
1927 /* No change */ | |
1928 if(numchans == Number_of_Channels_global) | |
1929 { | |
1930 return Number_of_Channels_global; | |
1931 } | |
1932 /* We need to increase the number of channels */ | |
1933 if(numchans > Number_of_Channels_global) | |
1934 { | |
1935 /* Not sure how safe this is, but SDL_mixer does it | |
1936 * the same way */ | |
1937 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1938 | |
1939 /* Allocate memory for the list of sources that map to the channels */ | |
1940 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
1941 | |
1942 for(i=Number_of_Channels_global; i<numchans; i++) | |
1943 { | |
1944 Init_Channel(i); | |
1945 /* Generate a new source and associate it with the channel */ | |
1946 alGenSources(1, &ALmixer_Channel_List[i].alsource); | |
1947 if((error = alGetError()) != AL_NO_ERROR) | |
1948 { | |
1949 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
|
1950 alGetString(error)); |
0 | 1951 } |
1952 /* Copy the source so the SourceMap has it too */ | |
1953 Source_Map_List[i].source = ALmixer_Channel_List[i].alsource; | |
1954 Source_Map_List[i].channel = i; | |
1955 /* Clean the channel because there are some things that need to | |
1956 * be done that can't happen until the source is set | |
1957 */ | |
1958 Clean_Channel(i); | |
1959 } | |
1960 | |
1961 /* The Source_Map_List must be sorted by source for binary searches | |
1962 */ | |
1963 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
1964 | |
1965 Number_of_Channels_global = numchans; | |
1966 return numchans; | |
1967 } | |
1968 /* Need to remove channels. This might be dangerous */ | |
1969 if(numchans < Number_of_Channels_global) | |
1970 { | |
1971 for(i=numchans; i<Number_of_Channels_global; i++) | |
1972 { | |
1973 /* Halt the channel */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1974 Internal_HaltChannel(i, AL_FALSE); |
0 | 1975 |
1976 /* Delete source associated with the channel */ | |
1977 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
1978 if((error = alGetError()) != AL_NO_ERROR) | |
1979 { | |
1980 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
|
1981 alGetString(error)); |
0 | 1982 } |
1983 } | |
1984 | |
1985 | |
1986 /* Not sure how safe this is, but SDL_mixer does it | |
1987 * the same way */ | |
1988 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1989 | |
1990 /* The tricky part is that we must remove the entries | |
1991 * in the source map that correspond to the deleted channels. | |
1992 * We'll resort the map by channels so we can pick them off | |
1993 * in order. | |
1994 */ | |
1995 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map_by_channel); | |
1996 | |
1997 /* Deallocate memory for the list of sources that map to the channels */ | |
1998 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
1999 | |
2000 /* Now resort the map by source and the correct num of chans */ | |
2001 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
2002 | |
2003 /* Reset the number of channels */ | |
2004 Number_of_Channels_global = numchans; | |
2005 return numchans; | |
2006 } | |
2007 /* Shouldn't ever reach here */ | |
2008 return -1; | |
2009 | |
2010 } | |
2011 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2012 static ALint Internal_ReserveChannels(ALint num) |
0 | 2013 { |
2014 /* Can't reserve more than the max num of channels */ | |
2015 /* Actually, I'll allow it for people who just want to | |
2016 * set the value really high to effectively disable | |
2017 * auto-assignment | |
2018 */ | |
2019 | |
2020 /* Return the current number of reserved channels */ | |
2021 if(num < 0) | |
2022 { | |
2023 return Number_of_Reserve_Channels_global; | |
2024 } | |
2025 Number_of_Reserve_Channels_global = num; | |
2026 return Number_of_Reserve_Channels_global; | |
2027 } | |
2028 | |
2029 | |
2030 /* This will rewind the SDL_Sound sample for streamed | |
2031 * samples and start buffering up the data for the next | |
2032 * playback. This may require samples to be halted | |
2033 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2034 static ALboolean Internal_RewindData(ALmixer_Data* data) |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2035 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2036 ALint retval = 0; |
0 | 2037 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2038 ALint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2039 ALint i; |
0 | 2040 */ |
2041 if(NULL == data) | |
2042 { | |
2043 ALmixer_SetError("Cannot rewind because data is NULL\n"); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2044 return AL_FALSE; |
0 | 2045 } |
2046 | |
2047 | |
2048 /* Might have to require Halt */ | |
2049 /* Okay, we assume Halt or natural stop has already | |
2050 * cleared the data buffers | |
2051 */ | |
2052 if(data->in_use) | |
2053 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2054 /* |
0 | 2055 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
|
2056 */ |
0 | 2057 /* |
2058 ALmixer_SetError("Data is in use. Cannot rewind unless all sources using the data are halted\n"); | |
2059 return -1; | |
2060 */ | |
2061 } | |
2062 | |
2063 | |
2064 /* Because Seek can alter things even in predecoded data, | |
2065 * decoded data must also be rewound | |
2066 */ | |
2067 if(data->decoded_all) | |
2068 { | |
2069 data->eof = 0; | |
2070 | |
2071 #if 0 | |
2072 #if defined(DISABLE_PREDECODED_SEEK) | |
2073 /* Since we can't seek predecoded stuff, it should be rewound */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2074 return AL_TRUE; |
0 | 2075 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) |
2076 /* This case is if the Sound_Sample has been deleted. | |
2077 * It assumes the data is already at the beginning. | |
2078 */ | |
2079 if(NULL == data->sample) | |
2080 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2081 return AL_TRUE; |
0 | 2082 } |
2083 /* Else, the sample has already been reallocated, | |
2084 * and we can fall to normal behavior | |
2085 */ | |
2086 #endif | |
2087 #endif | |
2088 /* If access_data, was enabled, the sound sample | |
2089 * still exists and we can do stuff. | |
2090 * If it's NULL, we can't do anything, but | |
2091 * it should already be "rewound". | |
2092 */ | |
2093 if(NULL == data->sample) | |
2094 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2095 return AL_TRUE; |
0 | 2096 } |
2097 /* Else, the sample has already been reallocated, | |
2098 * and we can fall to normal behavior | |
2099 */ | |
2100 | |
2101 Set_Predecoded_Seek_Position(data, 0); | |
2102 /* | |
2103 return data->total_bytes; | |
2104 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2105 return AL_TRUE; |
0 | 2106 } |
2107 | |
2108 /* Remaining stuff for streamed data */ | |
2109 | |
2110 data->eof = 0; | |
2111 retval = Sound_Rewind(data->sample); | |
2112 if(0 == retval) | |
2113 { | |
2114 ALmixer_SetError( Sound_GetError() ); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2115 return AL_FALSE; |
0 | 2116 } |
2117 #if 0 | |
2118 /* Clear error */ | |
2119 alGetError(); | |
2120 for(i=0; i<data->num_buffers; i++) | |
2121 { | |
2122 bytes_returned = GetMoreData(data, data->buffer[i]); | |
2123 if(-1 == bytes_returned) | |
2124 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2125 return AL_FALSE; |
0 | 2126 } |
2127 else if(0 == bytes_returned) | |
2128 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2129 return AL_FALSE; |
0 | 2130 } |
2131 retval += bytes_returned; | |
2132 | |
2133 } | |
2134 #endif | |
2135 | |
2136 | |
2137 | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2138 return AL_TRUE; |
0 | 2139 } |
2140 | |
2141 | |
2142 | |
2143 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2144 static ALint Internal_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2145 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2146 ALint retval = 0; |
0 | 2147 ALenum error; |
2148 ALint state; | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2149 ALint running_count = 0; |
0 | 2150 |
2151 if(channel >= Number_of_Channels_global) | |
2152 { | |
2153 ALmixer_SetError("Cannot rewind channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2154 return -1; | |
2155 } | |
2156 | |
2157 if((error = alGetError()) != AL_NO_ERROR) | |
2158 { | |
2159 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
|
2160 alGetString(error)); |
0 | 2161 } |
2162 /* Clear error */ | |
2163 alGetError(); | |
2164 | |
2165 /* If the user specified a specific channel */ | |
2166 if(channel >= 0) | |
2167 { | |
2168 /* only need to process channel if in use */ | |
2169 if(ALmixer_Channel_List[channel].channel_in_use) | |
2170 { | |
2171 | |
2172 /* What should I do? Do I just rewind the channel | |
2173 * or also rewind the data? Since the data is | |
2174 * shared, let's make it the user's responsibility | |
2175 * to rewind the data. | |
2176 */ | |
2177 if(ALmixer_Channel_List[channel].almixer_data->decoded_all) | |
2178 { | |
2179 alGetSourcei( | |
2180 ALmixer_Channel_List[channel].alsource, | |
2181 AL_SOURCE_STATE, &state | |
2182 ); | |
2183 if((error = alGetError()) != AL_NO_ERROR) | |
2184 { | |
2185 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
|
2186 alGetString(error)); |
0 | 2187 } |
2188 alSourceRewind(ALmixer_Channel_List[channel].alsource); | |
2189 if((error = alGetError()) != AL_NO_ERROR) | |
2190 { | |
2191 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2192 alGetString(error) ); |
0 | 2193 retval = -1; |
2194 } | |
2195 /* Need to resume playback if it was originally playing */ | |
2196 if(AL_PLAYING == state) | |
2197 { | |
2198 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2199 if((error = alGetError()) != AL_NO_ERROR) | |
2200 { | |
2201 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2202 alGetString(error) ); |
0 | 2203 retval = -1; |
2204 } | |
2205 } | |
2206 else if(AL_PAUSED == state) | |
2207 { | |
2208 /* HACK: The problem is that when paused, after | |
2209 * the Rewind, I can't get it off the INITIAL | |
2210 * state without restarting | |
2211 */ | |
2212 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2213 if((error = alGetError()) != AL_NO_ERROR) | |
2214 { | |
2215 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
|
2216 alGetString(error)); |
0 | 2217 } |
2218 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2219 if((error = alGetError()) != AL_NO_ERROR) | |
2220 { | |
2221 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2222 alGetString(error) ); |
0 | 2223 retval = -1; |
2224 } | |
2225 } | |
2226 } | |
2227 else | |
2228 { | |
2229 /* Streamed data is different. Rewinding the channel | |
2230 * does no good. Rewinding the data will have an | |
2231 * effect, but it will be lagged based on how | |
2232 * much data is queued. Recommend users call Halt | |
2233 * before rewind if they want immediate results. | |
2234 */ | |
2235 retval = Internal_RewindData(ALmixer_Channel_List[channel].almixer_data); | |
2236 } | |
2237 } | |
2238 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2239 /* The user wants to rewind all channels */ |
0 | 2240 else |
2241 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2242 ALint i; |
0 | 2243 for(i=0; i<Number_of_Channels_global; i++) |
2244 { | |
2245 /* only need to process channel if in use */ | |
2246 if(ALmixer_Channel_List[i].channel_in_use) | |
2247 { | |
2248 /* What should I do? Do I just rewind the channel | |
2249 * or also rewind the data? Since the data is | |
2250 * shared, let's make it the user's responsibility | |
2251 * to rewind the data. | |
2252 */ | |
2253 if(ALmixer_Channel_List[i].almixer_data->decoded_all) | |
2254 { | |
2255 alGetSourcei( | |
2256 ALmixer_Channel_List[i].alsource, | |
2257 AL_SOURCE_STATE, &state | |
2258 ); | |
2259 if((error = alGetError()) != AL_NO_ERROR) | |
2260 { | |
2261 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
|
2262 alGetString(error)); |
0 | 2263 } |
2264 alSourceRewind(ALmixer_Channel_List[i].alsource); | |
2265 if((error = alGetError()) != AL_NO_ERROR) | |
2266 { | |
2267 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2268 alGetString(error) ); |
0 | 2269 retval = -1; |
2270 } | |
2271 /* Need to resume playback if it was originally playing */ | |
2272 if(AL_PLAYING == state) | |
2273 { | |
2274 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2275 if((error = alGetError()) != AL_NO_ERROR) | |
2276 { | |
2277 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2278 alGetString(error) ); |
0 | 2279 retval = -1; |
2280 } | |
2281 } | |
2282 else if(AL_PAUSED == state) | |
2283 { | |
2284 /* HACK: The problem is that when paused, after | |
2285 * the Rewind, I can't get it off the INITIAL | |
2286 * state without restarting | |
2287 */ | |
2288 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2289 if((error = alGetError()) != AL_NO_ERROR) | |
2290 { | |
2291 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
|
2292 alGetString(error)); |
0 | 2293 } |
2294 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2295 if((error = alGetError()) != AL_NO_ERROR) | |
2296 { | |
2297 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2298 alGetString(error) ); |
0 | 2299 retval = -1; |
2300 } | |
2301 } | |
2302 } | |
2303 else | |
2304 { | |
2305 /* Streamed data is different. Rewinding the channel | |
2306 * does no good. Rewinding the data will have an | |
2307 * effect, but it will be lagged based on how | |
2308 * much data is queued. Recommend users call Halt | |
2309 * before rewind if they want immediate results. | |
2310 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2311 running_count += Internal_RewindData(ALmixer_Channel_List[i].almixer_data); |
0 | 2312 } |
2313 } | |
2314 } | |
2315 } | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2316 if(-1 == retval) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2317 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2318 return -1; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2319 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2320 else |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2321 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2322 return running_count; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2323 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2324 |
0 | 2325 } |
2326 | |
2327 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2328 static ALint Internal_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2329 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2330 ALint channel; |
0 | 2331 if(0 == source) |
2332 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2333 return Internal_RewindChannel(-1) + 1; |
0 | 2334 } |
2335 | |
2336 channel = Internal_GetChannel(source); | |
2337 if(-1 == channel) | |
2338 { | |
2339 ALmixer_SetError("Cannot rewind source: %s", ALmixer_GetError()); | |
2340 return 0; | |
2341 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2342 return Internal_RewindChannel(channel) + 1; |
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 |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2347 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2348 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2349 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
|
2350 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2351 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2352 int ret_flag = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2353 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2354 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2355 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
|
2356 return -1; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2359 /* 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
|
2360 * 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
|
2361 * 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
|
2362 * 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
|
2363 * 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
|
2364 * to prevent sharing |
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 if(0 == data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2367 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2368 if(data->in_use) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2369 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2370 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
|
2371 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2372 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2373 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2374 /* 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
|
2375 * This mainly affects streamed files, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2376 * so the check is placed here |
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 if(data->eof) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2379 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2380 if( -1 == Internal_RewindData(data) ) |
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 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
|
2383 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2384 } |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2387 /* 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
|
2388 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2389 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2390 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2391 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
|
2392 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2393 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
|
2394 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2395 channel = i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2396 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2397 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2398 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2399 /* 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
|
2400 if(i == Number_of_Channels_global) |
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 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
|
2403 return -1; |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2406 /* 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
|
2407 * out of bounds or in use */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2408 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2409 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2410 if(channel >= Number_of_Channels_global) |
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_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
|
2413 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2414 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2415 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
|
2416 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2417 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
|
2418 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2419 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2420 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2421 /* 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
|
2422 if(loops < -1) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2423 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2424 loops = -1; |
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 /* 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
|
2428 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2429 /* 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
|
2430 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
|
2431 data->in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2432 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2433 /* 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
|
2434 * (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
|
2435 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2436 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
|
2437 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
|
2438 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
|
2439 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2440 /* 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
|
2441 if(ticks < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2442 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2443 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
|
2444 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2445 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2446 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2447 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
|
2448 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2449 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2450 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2451 ALmixer_Channel_List[channel].halted = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2452 ALmixer_Channel_List[channel].paused = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2453 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2454 /* 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
|
2455 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2456 if( (-1 == loops) && (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 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
|
2459 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2460 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2461 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2462 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
|
2463 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2464 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2465 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2466 fprintf(stderr, "13Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2467 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2468 } |
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 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2471 /* Because of the corner case, predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2472 * 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
|
2473 * Streams do not have this problem |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2474 * 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
|
2475 * avoid the conflict. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2476 * 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
|
2477 * Since streams, cannot share, only predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2478 * files are affected |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2479 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2480 if(data->decoded_all) |
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 /* 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
|
2483 * 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
|
2484 * 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
|
2485 * must be +1 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2486 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2487 if(-1 == loops) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2488 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2489 /* -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
|
2490 * to add +1 to it */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2491 ALmixer_Channel_List[channel].loops = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2492 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
|
2493 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2494 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2495 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2496 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
|
2497 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
|
2498 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2499 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2500 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2501 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2502 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2503 /* 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
|
2504 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
|
2505 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2506 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2507 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2508 /* 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
|
2509 /* 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
|
2510 * 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
|
2511 * 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
|
2512 * 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
|
2513 * 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
|
2514 * 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
|
2515 * easier to maintain. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2516 */ |
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 /* Clear the error flag */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2519 alGetError(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2520 if(data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2521 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2522 /* Bind the data to the source */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2523 alSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2524 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2525 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2526 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2527 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2528 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2529 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
|
2530 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2531 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2532 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2533 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2534 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2535 /* 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
|
2536 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
|
2537 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2538 else |
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 /* 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
|
2541 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2542 ALuint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2543 ALuint j; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2544 data->num_buffers_in_use=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2545 /****** MODIFICATION must go here *********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2546 /* 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
|
2547 * 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
|
2548 * 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
|
2549 * 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
|
2550 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2551 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2552 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2553 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2554 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2555 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2556 /* No data or error */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2557 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
|
2558 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2559 return -1; |
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 /* 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
|
2562 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2563 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2564 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2565 /* 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
|
2566 * 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
|
2567 * before the last buffer is filled. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2568 * 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
|
2569 * 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
|
2570 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2571 |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2572 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2573 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
|
2574 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2575 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
|
2576 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2577 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2578 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
|
2579 fprintf(stderr, ">>>>>>>>>>>>>>>>>>HACK for GetMoreData2\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2580 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2581 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2582 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2583 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2584 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2585 * 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
|
2586 * 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
|
2587 * 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
|
2588 * 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
|
2589 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2590 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2591 if(bytes_returned < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2592 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2593 /* Error found */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2594 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
|
2595 /* 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
|
2596 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2597 break; |
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 else if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2600 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2601 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2602 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2603 /* No more data to buffer */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2604 /* Check for loops */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2605 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
|
2606 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2607 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2608 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
|
2609 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2610 if(0 == Sound_Rewind(data->sample)) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2611 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2612 fprintf(stderr, "error in rewind\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2613 ALmixer_SetError( Sound_GetError() ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2614 ALmixer_Channel_List[channel].loops = 0; |
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 /* 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
|
2617 break; |
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 /* 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
|
2620 data->eof = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2621 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
|
2622 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2623 ALmixer_Channel_List[channel].loops--; |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2624 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2625 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
|
2626 */ |
2
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 /* 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
|
2629 * 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
|
2630 * into an infinite loop |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2631 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2632 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2633 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2634 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2635 if(bytes_returned <= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2636 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2637 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
|
2638 /* 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
|
2639 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2640 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2641 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2642 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2643 else |
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 /* 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
|
2646 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2647 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2648 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2649 /* 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
|
2650 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2651 } |
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 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
|
2654 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2655 data->num_buffers_in_use); |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2658 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2659 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2660 data->num_buffers_in_use, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2661 data->buffer); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2662 if((error = alGetError()) != AL_NO_ERROR) |
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 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
|
2665 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2666 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2667 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2668 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2669 /* 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
|
2670 * 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
|
2671 * 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
|
2672 * 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
|
2673 * "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
|
2674 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2675 if(data->circular_buffer_queue != NULL) |
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 ALuint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2678 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2679 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
|
2680 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2681 // fprintf(stderr, "56c: CircularQueue_PushBack.\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2682 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
|
2683 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2684 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2685 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
|
2686 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
|
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2690 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2691 fprintf(stderr, "Queue in PlayTimed\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2692 CircularQueueUnsignedInt_Print(data->circular_buffer_queue); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2693 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2694 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2695 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2696 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2697 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2698 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2699 /****** END **********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2700 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2701 /* 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
|
2702 * so now we can play |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2703 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2704 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2705 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2706 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2707 ALmixer_SetError("Play failed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2708 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2709 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2710 return -1; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2713 /* 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
|
2714 Is_Playing_global++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2715 if(-1 == ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2716 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2717 fprintf(stderr, "BACKDOOR ERROR >>>>>>>>>>>>>>>>>>\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2718 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2719 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2720 return channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2721 } |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2724 /* 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
|
2725 * 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
|
2726 * 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
|
2727 * PlayChannelTimed() function call. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2728 * 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
|
2729 * 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
|
2730 * 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
|
2731 * 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
|
2732 * 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
|
2733 * 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
|
2734 * 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
|
2735 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2736 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
|
2737 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2738 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2739 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2740 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2741 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2742 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
|
2743 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2744 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2745 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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2748 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2749 return Internal_GetSource(retval); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2750 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2751 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2752 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2753 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2754 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2755 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2756 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
|
2757 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2758 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2759 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
|
2760 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2761 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2762 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2763 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2764 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2765 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2766 return source; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2767 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2768 /* make compiler happy */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2769 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2770 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2771 |
0 | 2772 |
2773 | |
2774 | |
2775 /* Returns the channel or number of channels actually paused */ | |
2776 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2777 static ALint Internal_PauseChannel(ALint channel) |
0 | 2778 { |
2779 ALenum error; | |
2780 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2781 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2782 ALint counter = 0; |
0 | 2783 |
2784 if(channel >= Number_of_Channels_global) | |
2785 { | |
2786 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2787 return -1; | |
2788 } | |
2789 | |
2790 if((error = alGetError()) != AL_NO_ERROR) | |
2791 { | |
2792 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
|
2793 alGetString(error)); |
0 | 2794 } |
2795 /* Clear error */ | |
2796 alGetError(); | |
2797 | |
2798 /* If the user specified a specific channel */ | |
2799 if(channel >= 0) | |
2800 { | |
2801 /* only need to process channel if in use */ | |
2802 if(ALmixer_Channel_List[channel].channel_in_use) | |
2803 { | |
2804 /* We don't want to repause if already | |
2805 * paused because the fadeout/expire | |
2806 * timing will get messed up | |
2807 */ | |
2808 alGetSourcei( | |
2809 ALmixer_Channel_List[channel].alsource, | |
2810 AL_SOURCE_STATE, &state | |
2811 ); | |
2812 if((error = alGetError()) != AL_NO_ERROR) | |
2813 { | |
2814 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
|
2815 alGetString(error)); |
0 | 2816 } |
2817 if(AL_PLAYING == state) | |
2818 { | |
2819 /* Count the actual number of channels being paused */ | |
2820 counter++; | |
2821 | |
2822 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2823 if((error = alGetError()) != AL_NO_ERROR) | |
2824 { | |
2825 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2826 alGetString(error) ); |
0 | 2827 retval = -1; |
2828 } | |
2829 /* We need to pause the expire time count down */ | |
2830 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
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].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].expire_ticks = | |
2843 ALmixer_Channel_List[channel].expire_ticks - | |
2844 diff_time; | |
2845 /* Because -1 is a special value, we can't | |
2846 * allow the time to go negative | |
2847 */ | |
2848 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2849 { | |
2850 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2851 } | |
2852 } | |
2853 /* Do the same as expire time for fading */ | |
2854 if(ALmixer_Channel_List[channel].fade_enabled) | |
2855 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2856 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2857 ALuint diff_time; |
0 | 2858 diff_time = current_time - |
2859 ALmixer_Channel_List[channel].fade_start_time; | |
2860 /* When we unpause, we will want to reset | |
2861 * the start time so we can continue | |
2862 * to base calculations off GetTicks(). | |
2863 * This means we need to subtract the amount | |
2864 * of time already used up from expire_ticks. | |
2865 */ | |
2866 ALmixer_Channel_List[channel].fade_expire_ticks = | |
2867 ALmixer_Channel_List[channel].fade_expire_ticks - | |
2868 diff_time; | |
2869 /* Don't allow the time to go negative */ | |
2870 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2871 { | |
2872 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2873 } | |
2874 } /* End fade check */ | |
2875 } /* End if PLAYING */ | |
2876 } /* End If in use */ | |
2877 } /* End specific channel */ | |
2878 /* The user wants to halt all channels */ | |
2879 else | |
2880 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2881 ALint i; |
0 | 2882 for(i=0; i<Number_of_Channels_global; i++) |
2883 { | |
2884 /* only need to process channel if in use */ | |
2885 if(ALmixer_Channel_List[i].channel_in_use) | |
2886 { | |
2887 /* We don't want to repause if already | |
2888 * paused because the fadeout/expire | |
2889 * timing will get messed up | |
2890 */ | |
2891 alGetSourcei( | |
2892 ALmixer_Channel_List[i].alsource, | |
2893 AL_SOURCE_STATE, &state | |
2894 ); | |
2895 if((error = alGetError()) != AL_NO_ERROR) | |
2896 { | |
2897 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
|
2898 alGetString(error)); |
0 | 2899 } |
2900 if(AL_PLAYING == state) | |
2901 { | |
2902 /* Count the actual number of channels being paused */ | |
2903 counter++; | |
2904 | |
2905 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2906 if((error = alGetError()) != AL_NO_ERROR) | |
2907 { | |
2908 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2909 alGetString(error) ); |
0 | 2910 retval = -1; |
2911 } | |
2912 /* We need to pause the expire time count down */ | |
2913 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
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].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].expire_ticks = | |
2926 ALmixer_Channel_List[i].expire_ticks - | |
2927 diff_time; | |
2928 /* Because -1 is a special value, we can't | |
2929 * allow the time to go negative | |
2930 */ | |
2931 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2932 { | |
2933 ALmixer_Channel_List[i].expire_ticks = 0; | |
2934 } | |
2935 } | |
2936 /* Do the same as expire time for fading */ | |
2937 if(ALmixer_Channel_List[i].fade_enabled) | |
2938 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2939 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2940 ALuint diff_time; |
0 | 2941 diff_time = current_time - |
2942 ALmixer_Channel_List[i].fade_start_time; | |
2943 /* When we unpause, we will want to reset | |
2944 * the start time so we can continue | |
2945 * to base calculations off GetTicks(). | |
2946 * This means we need to subtract the amount | |
2947 * of time already used up from expire_ticks. | |
2948 */ | |
2949 ALmixer_Channel_List[i].fade_expire_ticks = | |
2950 ALmixer_Channel_List[i].fade_expire_ticks - | |
2951 diff_time; | |
2952 /* Don't allow the time to go negative */ | |
2953 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2954 { | |
2955 ALmixer_Channel_List[i].expire_ticks = 0; | |
2956 } | |
2957 } /* End fade check */ | |
2958 } /* End if PLAYING */ | |
2959 } /* End channel in use */ | |
2960 } /* End for-loop */ | |
2961 } | |
2962 if(-1 == retval) | |
2963 { | |
2964 return -1; | |
2965 } | |
2966 return counter; | |
2967 } | |
2968 | |
2969 /* 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
|
2970 static ALint Internal_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2971 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2972 ALint channel; |
0 | 2973 if(0 == source) |
2974 { | |
2975 return Internal_PauseChannel(-1); | |
2976 } | |
2977 | |
2978 channel = Internal_GetChannel(source); | |
2979 if(-1 == channel) | |
2980 { | |
2981 ALmixer_SetError("Cannot pause source: %s", ALmixer_GetError()); | |
2982 return -1; | |
2983 } | |
2984 return Internal_PauseChannel(channel); | |
2985 } | |
2986 | |
2987 | |
2988 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2989 static ALint Internal_ResumeChannel(ALint channel) |
0 | 2990 { |
2991 ALint state; | |
2992 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2993 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2994 ALint counter = 0; |
0 | 2995 |
2996 if(channel >= Number_of_Channels_global) | |
2997 { | |
2998 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2999 return -1; | |
3000 } | |
3001 | |
3002 if((error = alGetError()) != AL_NO_ERROR) | |
3003 { | |
3004 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
|
3005 alGetString(error)); |
0 | 3006 } |
3007 /* Clear error */ | |
3008 alGetError(); | |
3009 | |
3010 /* If the user specified a specific channel */ | |
3011 if(channel >= 0) | |
3012 { | |
3013 /* only need to process channel if in use */ | |
3014 if(ALmixer_Channel_List[channel].channel_in_use) | |
3015 { | |
3016 alGetSourcei( | |
3017 ALmixer_Channel_List[channel].alsource, | |
3018 AL_SOURCE_STATE, &state | |
3019 ); | |
3020 if((error = alGetError()) != AL_NO_ERROR) | |
3021 { | |
3022 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
|
3023 alGetString(error)); |
0 | 3024 } |
3025 if(AL_PAUSED == state) | |
3026 { | |
3027 /* Count the actual number of channels resumed */ | |
3028 counter++; | |
3029 | |
3030 /* We need to resume the expire time count down */ | |
3031 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
3032 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3033 ALmixer_Channel_List[channel].start_time = ALmixer_GetTicks(); |
0 | 3034 } |
3035 /* Do the same as expire time for fading */ | |
3036 if(ALmixer_Channel_List[channel].fade_enabled) | |
3037 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3038 ALmixer_Channel_List[channel].fade_start_time = ALmixer_GetTicks(); |
0 | 3039 } |
3040 | |
3041 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
3042 if((error = alGetError()) != AL_NO_ERROR) | |
3043 { | |
3044 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3045 alGetString(error) ); |
0 | 3046 retval = -1; |
3047 } | |
3048 } | |
3049 } | |
3050 } | |
3051 /* The user wants to halt all channels */ | |
3052 else | |
3053 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3054 ALint i; |
0 | 3055 for(i=0; i<Number_of_Channels_global; i++) |
3056 { | |
3057 /* only need to process channel if in use */ | |
3058 if(ALmixer_Channel_List[i].channel_in_use) | |
3059 { | |
3060 alGetSourcei( | |
3061 ALmixer_Channel_List[i].alsource, | |
3062 AL_SOURCE_STATE, &state | |
3063 ); | |
3064 if((error = alGetError()) != AL_NO_ERROR) | |
3065 { | |
3066 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
|
3067 alGetString(error)); |
0 | 3068 } |
3069 if(AL_PAUSED == state) | |
3070 { | |
3071 /* Count the actual number of channels resumed */ | |
3072 counter++; | |
3073 | |
3074 /* We need to resume the expire time count down */ | |
3075 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
3076 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3077 ALmixer_Channel_List[i].start_time = ALmixer_GetTicks(); |
0 | 3078 } |
3079 /* Do the same as expire time for fading */ | |
3080 if(ALmixer_Channel_List[i].fade_enabled) | |
3081 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3082 ALmixer_Channel_List[i].fade_start_time = ALmixer_GetTicks(); |
0 | 3083 } |
3084 | |
3085 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
3086 if((error = alGetError()) != AL_NO_ERROR) | |
3087 { | |
3088 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3089 alGetString(error) ); |
0 | 3090 retval = -1; |
3091 } | |
3092 } | |
3093 } | |
3094 } | |
3095 } | |
3096 if(-1 == retval) | |
3097 { | |
3098 return -1; | |
3099 } | |
3100 return counter; | |
3101 } | |
3102 | |
3103 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3104 static ALint Internal_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3105 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3106 ALint channel; |
0 | 3107 if(0 == source) |
3108 { | |
3109 return Internal_ResumeChannel(-1); | |
3110 } | |
3111 | |
3112 channel = Internal_GetChannel(source); | |
3113 if(-1 == channel) | |
3114 { | |
3115 ALmixer_SetError("Cannot resume source: %s", ALmixer_GetError()); | |
3116 return -1; | |
3117 } | |
3118 return Internal_ResumeChannel(channel); | |
3119 } | |
3120 | |
3121 | |
3122 /* Might consider setting eof to 0 as a "feature" | |
3123 * This will allow seek to end to stay there because | |
3124 * Play automatically rewinds if at the end */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3125 static ALboolean Internal_SeekData(ALmixer_Data* data, ALuint msec) |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3126 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3127 ALint retval; |
0 | 3128 |
3129 if(NULL == data) | |
3130 { | |
3131 ALmixer_SetError("Cannot Seek because data is NULL"); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3132 return AL_FALSE; |
0 | 3133 } |
3134 | |
3135 /* Seek for predecoded files involves moving the chunk pointer around */ | |
3136 if(data->decoded_all) | |
3137 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3138 ALuint byte_position; |
0 | 3139 |
3140 /* OpenAL doesn't seem to like it if I change the buffer | |
3141 * while playing (crashes), so I must require that Seek only | |
3142 * be done when the data is not in use. | |
3143 * Since data may be shared among multiple sources, | |
3144 * I can't shut them down myself, so I have to return an error. | |
3145 */ | |
3146 if(data->in_use) | |
3147 { | |
3148 ALmixer_SetError("Cannot seek on predecoded data while instances are playing"); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3149 return AL_FALSE; |
0 | 3150 } |
3151 #if 0 | |
3152 #if defined(DISABLE_PREDECODED_SEEK) | |
3153 ALmixer_SetError("Seek support for predecoded samples was not compiled in"); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3154 return AL_FALSE; |
0 | 3155 |
3156 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
3157 /* By default, ALmixer frees the Sound_Sample for predecoded | |
3158 * samples because of the potential memory waste. | |
3159 * However, to seek a sample, we need to have a full | |
3160 * copy of the data around. So the strategy is to | |
3161 * recreate a hackish Sound_Sample to be used for seeking | |
3162 * purposes. If Sound_Sample is NULL, we will reallocate | |
3163 * memory for it and then procede as if everything | |
3164 * was normal. | |
3165 */ | |
3166 if(NULL == data->sample) | |
3167 { | |
3168 if( -1 == Reconstruct_Sound_Sample(data) ) | |
3169 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3170 return AL_FALSE; |
0 | 3171 } |
3172 } | |
3173 #endif | |
3174 #endif | |
3175 /* If access_data was set, then we still have the | |
3176 * Sound_Sample and we can move around in the data. | |
3177 * If it was not set, the data has been freed and we | |
3178 * cannot do anything because there is no way to | |
3179 * recover the data because OpenAL won't let us | |
3180 * get access to the buffers | |
3181 */ | |
3182 if(NULL == data->sample) | |
3183 { | |
3184 ALmixer_SetError("Cannot seek because access_data flag was set false when data was initialized"); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3185 return AL_FALSE; |
0 | 3186 } |
3187 | |
3188 byte_position = Convert_Msec_To_Byte_Pos(&data->sample->desired, msec); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3189 retval = Set_Predecoded_Seek_Position(data, byte_position); |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3190 if(-1 == retval) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3191 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3192 return AL_FALSE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3193 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3194 else |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3195 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3196 return AL_TRUE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3197 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3198 |
0 | 3199 } |
3200 else | |
3201 { | |
3202 /* Reset eof flag?? */ | |
3203 data->eof = 0; | |
3204 retval = Sound_Seek(data->sample, msec); | |
3205 if(0 == retval) | |
3206 { | |
3207 ALmixer_SetError(Sound_GetError()); | |
3208 | |
3209 fprintf(stderr, "Sound seek error: %s\n", ALmixer_GetError()); | |
3210 /* Try rewinding to clean up? */ | |
3211 /* | |
3212 Internal_RewindData(data); | |
3213 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3214 return AL_FALSE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3215 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3216 return AL_TRUE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3217 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3218 |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3219 return AL_TRUE; |
0 | 3220 } |
3221 | |
3222 | |
3223 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3224 static ALint Internal_FadeInChannelTimed(ALint channel, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 3225 { |
3226 ALfloat value; | |
3227 ALenum error; | |
3228 ALfloat original_value; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3229 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3230 ALint retval; |
0 | 3231 |
3232 | |
3233 | |
3234 if(channel >= Number_of_Channels_global) | |
3235 { | |
3236 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); | |
3237 return -1; | |
3238 } | |
3239 /* Let's call PlayChannelTimed to do the job. | |
3240 * There are two catches: | |
3241 * First is that we must set the volumes before the play call(s). | |
3242 * Second is that we must initialize the channel values | |
3243 */ | |
3244 | |
3245 if(channel < 0) | |
3246 { | |
3247 /* This might cause a problem for threads/race conditions. | |
3248 * We need to set the volume on an unknown channel, | |
3249 * so we need to request a channel first. Remember | |
3250 * that requesting a channel doesn't lock and it | |
3251 * could be surrendered to somebody else before we claim it. | |
3252 */ | |
3253 channel = Internal_GetChannel(0); | |
3254 if(-1 == channel) | |
3255 { | |
3256 return -1; | |
3257 } | |
3258 } | |
3259 else if(ALmixer_Channel_List[channel].channel_in_use) | |
3260 { | |
3261 ALmixer_SetError("Channel %d is already in use", channel); | |
3262 return -1; | |
3263 } | |
3264 | |
3265 | |
3266 /* Get the original volume in case of a problem */ | |
3267 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
|
3268 AL_GAIN, &original_value); |
0 | 3269 |
3270 if((error = alGetError()) != AL_NO_ERROR) | |
3271 { | |
3272 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
|
3273 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3274 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3275 ALmixer_Channel_List[channel].fade_end_volume = original_value; |
0 | 3276 |
3277 /* Get the Min volume */ | |
3278 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3279 AL_MIN_GAIN, &value); | |
3280 if((error = alGetError()) != AL_NO_ERROR) | |
3281 { | |
3282 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
|
3283 alGetString(error)); |
0 | 3284 } |
3285 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3286 | |
3287 /* Set the actual volume */ | |
3288 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
|
3289 AL_GAIN, value); |
0 | 3290 if((error = alGetError()) != AL_NO_ERROR) |
3291 { | |
3292 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
|
3293 alGetString(error)); |
0 | 3294 } |
3295 | |
3296 | |
3297 /* Now call PlayChannelTimed */ | |
3298 retval = Internal_PlayChannelTimed(channel, data, loops, expire_ticks); | |
3299 if(-1 == retval) | |
3300 { | |
3301 /* Chance of failure is actually pretty high since | |
3302 * a channel might already be in use or streamed | |
3303 * data can be shared | |
3304 */ | |
3305 /* Restore the original value to avoid accidental | |
3306 * distruption of playback | |
3307 */ | |
3308 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
|
3309 AL_GAIN, original_value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3310 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3311 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3312 fprintf(stderr, "38Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3313 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3314 } |
0 | 3315 return retval; |
3316 } | |
3317 | |
3318 /* We can't accept 0 as a value because of div-by-zero. | |
3319 * If zero, just call PlayChannelTimed at normal | |
3320 * volume | |
3321 */ | |
3322 if(0 == fade_ticks) | |
3323 { | |
3324 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
|
3325 AL_GAIN, |
0 | 3326 ALmixer_Channel_List[channel].fade_end_volume |
3327 ); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3328 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3329 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3330 fprintf(stderr, "39Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3331 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3332 } |
0 | 3333 |
3334 return retval; | |
3335 } | |
3336 | |
3337 /* Enable fading effects via the flag */ | |
3338 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3339 /* Set fade start time */ | |
3340 ALmixer_Channel_List[channel].fade_start_time | |
3341 = ALmixer_Channel_List[channel].start_time; | |
3342 /* Set the fade expire ticks */ | |
3343 ALmixer_Channel_List[channel].fade_expire_ticks = fade_ticks; | |
3344 | |
3345 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3346 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / fade_ticks; | |
3347 | |
3348 return retval; | |
3349 | |
3350 } | |
3351 | |
3352 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3353 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
|
3354 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3355 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3356 ALint retval; |
0 | 3357 if(0 == source) |
3358 { | |
3359 retval = Internal_FadeInChannelTimed(-1, data, loops, fade_ticks, expire_ticks); | |
3360 if(-1 == retval) | |
3361 { | |
3362 return 0; | |
3363 } | |
3364 else | |
3365 { | |
3366 return Internal_GetSource(retval); | |
3367 } | |
3368 } | |
3369 | |
3370 channel = Internal_GetChannel(source); | |
3371 if(-1 == channel) | |
3372 { | |
3373 ALmixer_SetError("Cannot FadeIn source: %s", ALmixer_GetError()); | |
3374 return 0; | |
3375 } | |
3376 retval = Internal_FadeInChannelTimed(channel, data, loops, fade_ticks, expire_ticks); | |
3377 if(-1 == retval) | |
3378 { | |
3379 return 0; | |
3380 } | |
3381 else | |
3382 { | |
3383 return source; | |
3384 } | |
3385 /* make compiler happy */ | |
3386 return 0; | |
3387 } | |
3388 | |
3389 | |
3390 | |
3391 | |
3392 /* Will fade out currently playing channels. | |
3393 * 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
|
3394 static ALint Internal_FadeOutChannel(ALint channel, ALuint ticks) |
0 | 3395 { |
3396 ALfloat value; | |
3397 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3398 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3399 ALuint counter = 0; |
0 | 3400 |
3401 /* We can't accept 0 as a value because of div-by-zero. | |
3402 * If zero, just call Halt at normal | |
3403 * volume | |
3404 */ | |
3405 if(0 == ticks) | |
3406 { | |
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
|
3407 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 3408 } |
3409 | |
3410 | |
3411 if(channel >= Number_of_Channels_global) | |
3412 { | |
3413 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); | |
3414 return -1; | |
3415 } | |
3416 | |
3417 if(channel >= 0) | |
3418 { | |
3419 if(ALmixer_Channel_List[channel].channel_in_use) | |
3420 { | |
3421 /* Get the current volume */ | |
3422 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
|
3423 AL_GAIN, &value); |
0 | 3424 ALmixer_Channel_List[channel].fade_start_volume = value; |
3425 if((error = alGetError()) != AL_NO_ERROR) | |
3426 { | |
3427 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
|
3428 alGetString(error)); |
0 | 3429 } |
3430 | |
3431 /* Get the Min volume */ | |
3432 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3433 AL_MIN_GAIN, &value); | |
3434 if((error = alGetError()) != AL_NO_ERROR) | |
3435 { | |
3436 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
|
3437 alGetString(error)); |
0 | 3438 } |
3439 ALmixer_Channel_List[channel].fade_end_volume = value; | |
3440 | |
3441 /* Set expire start time */ | |
3442 ALmixer_Channel_List[channel].start_time = current_time; | |
3443 /* Set the expire ticks */ | |
3444 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
3445 /* Set fade start time */ | |
3446 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3447 /* Set the fade expire ticks */ | |
3448 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3449 /* Enable fading effects via the flag */ | |
3450 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3451 | |
3452 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3453 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3454 | |
3455 counter++; | |
3456 } | |
3457 } | |
3458 /* Else need to fade out all channels */ | |
3459 else | |
3460 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3461 ALint i; |
0 | 3462 for(i=0; i<Number_of_Channels_global; i++) |
3463 { | |
3464 if(ALmixer_Channel_List[i].channel_in_use) | |
3465 { | |
3466 /* Get the current volume */ | |
3467 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
|
3468 AL_GAIN, &value); |
0 | 3469 ALmixer_Channel_List[i].fade_start_volume = value; |
3470 if((error = alGetError()) != AL_NO_ERROR) | |
3471 { | |
3472 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
|
3473 alGetString(error)); |
0 | 3474 } |
3475 | |
3476 /* Get the Min volume */ | |
3477 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
3478 AL_MIN_GAIN, &value); | |
3479 if((error = alGetError()) != AL_NO_ERROR) | |
3480 { | |
3481 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
|
3482 alGetString(error)); |
0 | 3483 } |
3484 ALmixer_Channel_List[i].fade_end_volume = value; | |
3485 | |
3486 /* Set expire start time */ | |
3487 ALmixer_Channel_List[i].start_time = current_time; | |
3488 /* Set the expire ticks */ | |
3489 ALmixer_Channel_List[i].expire_ticks = ticks; | |
3490 /* Set fade start time */ | |
3491 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3492 /* Set the fade expire ticks */ | |
3493 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3494 /* Enable fading effects via the flag */ | |
3495 ALmixer_Channel_List[i].fade_enabled = 1; | |
3496 | |
3497 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3498 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3499 | |
3500 counter++; | |
3501 } | |
3502 } /* End for loop */ | |
3503 } | |
3504 return counter; | |
3505 } | |
3506 | |
3507 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3508 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
|
3509 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3510 ALint channel; |
0 | 3511 if(0 == source) |
3512 { | |
3513 return Internal_FadeOutChannel(-1, ticks); | |
3514 } | |
3515 | |
3516 channel = Internal_GetChannel(source); | |
3517 if(-1 == channel) | |
3518 { | |
3519 ALmixer_SetError("Cannot FadeOut source: %s", ALmixer_GetError()); | |
3520 return -1; | |
3521 } | |
3522 return Internal_FadeOutChannel(channel, ticks); | |
3523 } | |
3524 | |
3525 | |
3526 /* Will fade currently playing channels. | |
3527 * It starts at the current volume level and go to target | |
3528 * Only affects channels that are playing | |
3529 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3530 static ALint Internal_FadeChannel(ALint channel, ALuint ticks, ALfloat volume) |
0 | 3531 { |
3532 ALfloat value; | |
3533 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3534 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3535 ALuint counter = 0; |
0 | 3536 |
3537 if(channel >= Number_of_Channels_global) | |
3538 { | |
3539 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); | |
3540 return -1; | |
3541 } | |
3542 | |
3543 if(channel >= 0) | |
3544 { | |
3545 if(volume < ALmixer_Channel_List[channel].min_volume) | |
3546 { | |
3547 volume = ALmixer_Channel_List[channel].min_volume; | |
3548 } | |
3549 else if(volume > ALmixer_Channel_List[channel].max_volume) | |
3550 { | |
3551 volume = ALmixer_Channel_List[channel].max_volume; | |
3552 } | |
3553 | |
3554 if(ALmixer_Channel_List[channel].channel_in_use) | |
3555 { | |
3556 if(ticks > 0) | |
3557 { | |
3558 /* Get the current volume */ | |
3559 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
|
3560 AL_GAIN, &value); |
0 | 3561 if((error = alGetError()) != AL_NO_ERROR) |
3562 { | |
3563 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
|
3564 alGetString(error)); |
0 | 3565 } |
3566 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3567 | |
3568 /* Set the target volume */ | |
3569 ALmixer_Channel_List[channel].fade_end_volume = volume; | |
3570 | |
3571 /* Set fade start time */ | |
3572 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3573 /* Set the fade expire ticks */ | |
3574 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3575 /* Enable fading effects via the flag */ | |
3576 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3577 | |
3578 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3579 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3580 } | |
3581 else | |
3582 { | |
3583 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
|
3584 AL_GAIN, volume); |
0 | 3585 if((error = alGetError()) != AL_NO_ERROR) |
3586 { | |
3587 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
|
3588 alGetString(error)); |
0 | 3589 } |
3590 } | |
3591 counter++; | |
3592 } | |
3593 } | |
3594 /* Else need to fade out all channels */ | |
3595 else | |
3596 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3597 ALint i; |
0 | 3598 for(i=0; i<Number_of_Channels_global; i++) |
3599 { | |
3600 if(volume < ALmixer_Channel_List[i].min_volume) | |
3601 { | |
3602 volume = ALmixer_Channel_List[i].min_volume; | |
3603 } | |
3604 else if(volume > ALmixer_Channel_List[i].max_volume) | |
3605 { | |
3606 volume = ALmixer_Channel_List[i].max_volume; | |
3607 } | |
3608 | |
3609 if(ALmixer_Channel_List[i].channel_in_use) | |
3610 { | |
3611 if(ticks > 0) | |
3612 { | |
3613 /* Get the current volume */ | |
3614 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
|
3615 AL_GAIN, &value); |
0 | 3616 if((error = alGetError()) != AL_NO_ERROR) |
3617 { | |
3618 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
|
3619 alGetString(error)); |
0 | 3620 } |
3621 ALmixer_Channel_List[i].fade_start_volume = value; | |
3622 | |
3623 /* Set target volume */ | |
3624 ALmixer_Channel_List[i].fade_end_volume = volume; | |
3625 | |
3626 /* Set fade start time */ | |
3627 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3628 /* Set the fade expire ticks */ | |
3629 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3630 /* Enable fading effects via the flag */ | |
3631 ALmixer_Channel_List[i].fade_enabled = 1; | |
3632 | |
3633 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3634 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3635 } | |
3636 else | |
3637 { | |
3638 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
|
3639 AL_GAIN, volume); |
0 | 3640 if((error = alGetError()) != AL_NO_ERROR) |
3641 { | |
3642 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
|
3643 alGetString(error)); |
0 | 3644 } |
3645 } | |
3646 counter++; | |
3647 } | |
3648 } /* End for loop */ | |
3649 } | |
3650 return counter; | |
3651 } | |
3652 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3653 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
|
3654 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3655 ALint channel; |
0 | 3656 if(0 == source) |
3657 { | |
3658 return Internal_FadeChannel(-1, ticks, volume); | |
3659 } | |
3660 | |
3661 channel = Internal_GetChannel(source); | |
3662 if(-1 == channel) | |
3663 { | |
3664 ALmixer_SetError("Cannot Fade source: %s", ALmixer_GetError()); | |
3665 return -1; | |
3666 } | |
3667 return Internal_FadeChannel(channel, ticks, volume); | |
3668 } | |
3669 | |
3670 | |
3671 | |
3672 | |
3673 /* Set a volume regardless if it's in use or not. | |
3674 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3675 static ALboolean Internal_SetVolumeChannel(ALint channel, ALfloat volume) |
0 | 3676 { |
3677 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3678 ALboolean retval = AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3679 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3680 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3681 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3682 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
|
3683 return AL_FALSE; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3686 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3687 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3688 if(volume < 0.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3689 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3690 volume = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3691 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3692 else if(volume > 1.0f) |
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 volume = 1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3695 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3696 alSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3697 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3698 if((error = alGetError()) != AL_NO_ERROR) |
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 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3701 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3702 retval = AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3703 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3704 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3705 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3706 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3707 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3708 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
|
3709 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3710 if(volume < 0.0f) |
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 volume = 0.0f; |
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 else if(volume > 1.0f) |
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 volume = 1.0f; |
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 alSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3719 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3720 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3721 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3722 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3723 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3724 retval = AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3725 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3726 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3727 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3728 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3729 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3730 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3731 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
|
3732 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3733 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3734 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3735 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3736 return Internal_SetVolumeChannel(-1, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3737 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3738 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3739 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3740 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3741 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3742 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
|
3743 return AL_FALSE; |
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 return Internal_SetVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3746 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3747 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3748 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3749 static ALfloat Internal_GetVolumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3750 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3751 ALfloat value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3752 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3753 ALfloat running_total = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3754 ALfloat retval = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3755 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3756 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3757 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3758 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
|
3759 return -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3760 } |
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 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3763 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3764 alGetSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3765 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3766 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3767 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3768 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3769 retval = -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3770 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3771 else |
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 retval = value; |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3776 else |
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 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3779 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
|
3780 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3781 alGetSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3782 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3783 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3784 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3785 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3786 retval = -1; |
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 else |
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 running_total += value; |
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 if(0 == Number_of_Channels_global) |
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 ALmixer_SetError("No channels are allocated"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3796 retval = -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3797 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3798 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3799 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3800 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
|
3801 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3802 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3803 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3804 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3805 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3806 static ALfloat Internal_GetVolumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3807 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3808 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3809 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3810 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3811 return Internal_GetVolumeChannel(-1); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3812 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3813 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3814 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3815 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3816 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3817 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
|
3818 return -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3819 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3820 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3821 return Internal_GetVolumeChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3822 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3823 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3824 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3825 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3826 /* 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
|
3827 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3828 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
|
3829 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3830 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3831 ALboolean retval = AL_TRUE; |
0 | 3832 |
3833 if(channel >= Number_of_Channels_global) | |
3834 { | |
3835 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
|
3836 return AL_FALSE; |
0 | 3837 } |
3838 | |
3839 if(channel >= 0) | |
3840 { | |
3841 if(volume < 0.0f) | |
3842 { | |
3843 volume = 0.0f; | |
3844 } | |
3845 else if(volume > 1.0f) | |
3846 { | |
3847 volume = 1.0f; | |
3848 } | |
3849 ALmixer_Channel_List[channel].max_volume = volume; | |
3850 alSourcef(ALmixer_Channel_List[channel].alsource, | |
3851 AL_MAX_GAIN, volume); | |
3852 if((error = alGetError()) != AL_NO_ERROR) | |
3853 { | |
3854 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3855 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3856 retval = AL_FALSE; |
0 | 3857 } |
3858 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
3859 { | |
3860 ALmixer_Channel_List[channel].min_volume = volume; | |
3861 alSourcef(ALmixer_Channel_List[channel].alsource, | |
3862 AL_MIN_GAIN, volume); | |
3863 if((error = alGetError()) != AL_NO_ERROR) | |
3864 { | |
3865 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3866 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3867 retval = AL_FALSE; |
0 | 3868 } |
3869 } | |
3870 } | |
3871 else | |
3872 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3873 ALint i; |
0 | 3874 for(i=0; i<Number_of_Channels_global; i++) |
3875 { | |
3876 if(volume < 0.0f) | |
3877 { | |
3878 volume = 0.0f; | |
3879 } | |
3880 else if(volume > 1.0f) | |
3881 { | |
3882 volume = 1.0f; | |
3883 } | |
3884 ALmixer_Channel_List[i].max_volume = volume; | |
3885 alSourcef(ALmixer_Channel_List[i].alsource, | |
3886 AL_MAX_GAIN, volume); | |
3887 if((error = alGetError()) != AL_NO_ERROR) | |
3888 { | |
3889 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3890 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3891 retval = AL_FALSE; |
0 | 3892 } |
3893 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
3894 { | |
3895 ALmixer_Channel_List[i].min_volume = volume; | |
3896 alSourcef(ALmixer_Channel_List[i].alsource, | |
3897 AL_MIN_GAIN, volume); | |
3898 if((error = alGetError()) != AL_NO_ERROR) | |
3899 { | |
3900 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3901 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3902 retval = AL_FALSE; |
0 | 3903 } |
3904 } | |
3905 } | |
3906 } | |
3907 return retval; | |
3908 } | |
3909 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3910 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
|
3911 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3912 ALint channel; |
0 | 3913 if(0 == source) |
3914 { | |
3915 return Internal_SetMaxVolumeChannel(-1, volume); | |
3916 } | |
3917 | |
3918 channel = Internal_GetChannel(source); | |
3919 if(-1 == channel) | |
3920 { | |
3921 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
|
3922 return AL_FALSE; |
0 | 3923 } |
3924 return Internal_SetMaxVolumeChannel(channel, volume); | |
3925 } | |
3926 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3927 static ALfloat Internal_GetMaxVolumeChannel(ALint channel) |
0 | 3928 { |
3929 /* | |
3930 ALfloat value; | |
3931 ALenum error; | |
3932 */ | |
3933 ALfloat running_total = 0.0f; | |
3934 ALfloat retval = 0.0f; | |
3935 | |
3936 if(channel >= Number_of_Channels_global) | |
3937 { | |
3938 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); | |
3939 return -1.0f; | |
3940 } | |
3941 | |
3942 if(channel >= 0) | |
3943 { | |
3944 /* | |
3945 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3946 AL_GAIN, &value); | |
3947 if((error = alGetError()) != AL_NO_ERROR) | |
3948 { | |
3949 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3950 alGetString(error) ); |
0 | 3951 retval = -1.0f; |
3952 } | |
3953 else | |
3954 { | |
3955 retval = value; | |
3956 } | |
3957 */ | |
3958 retval = ALmixer_Channel_List[channel].max_volume; | |
3959 | |
3960 } | |
3961 else | |
3962 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3963 ALint i; |
0 | 3964 for(i=0; i<Number_of_Channels_global; i++) |
3965 { | |
3966 /* | |
3967 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
3968 AL_GAIN, &value); | |
3969 if((error = alGetError()) != AL_NO_ERROR) | |
3970 { | |
3971 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3972 alGetString(error) ); |
0 | 3973 retval = -1; |
3974 } | |
3975 else | |
3976 { | |
3977 running_total += value; | |
3978 } | |
3979 */ | |
3980 running_total += ALmixer_Channel_List[i].max_volume; | |
3981 } | |
3982 if(0 == Number_of_Channels_global) | |
3983 { | |
3984 ALmixer_SetError("No channels are allocated"); | |
3985 retval = -1.0f; | |
3986 } | |
3987 else | |
3988 { | |
3989 retval = running_total / Number_of_Channels_global; | |
3990 } | |
3991 } | |
3992 return retval; | |
3993 } | |
3994 | |
3995 static ALfloat Internal_GetMaxVolumeSource(ALuint source) | |
3996 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3997 ALint channel; |
0 | 3998 if(0 == source) |
3999 { | |
4000 return Internal_GetMaxVolumeChannel(-1); | |
4001 } | |
4002 | |
4003 channel = Internal_GetChannel(source); | |
4004 if(-1 == channel) | |
4005 { | |
4006 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
4007 return -1.0f; | |
4008 } | |
4009 | |
4010 return Internal_GetMaxVolumeChannel(channel); | |
4011 } | |
4012 | |
4013 | |
4014 /* Set a volume regardless if it's in use or not. | |
4015 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4016 static ALboolean Internal_SetMinVolumeChannel(ALint channel, ALfloat volume) |
0 | 4017 { |
4018 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4019 ALboolean retval = AL_TRUE; |
0 | 4020 |
4021 if(channel >= Number_of_Channels_global) | |
4022 { | |
4023 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
|
4024 return AL_FALSE; |
0 | 4025 } |
4026 | |
4027 if(channel >= 0) | |
4028 { | |
4029 if(volume < 0.0f) | |
4030 { | |
4031 volume = 0.0f; | |
4032 } | |
4033 else if(volume > 1.0f) | |
4034 { | |
4035 volume = 1.0f; | |
4036 } | |
4037 ALmixer_Channel_List[channel].min_volume = volume; | |
4038 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4039 AL_MIN_GAIN, volume); | |
4040 if((error = alGetError()) != AL_NO_ERROR) | |
4041 { | |
4042 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4043 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4044 retval = AL_FALSE; |
0 | 4045 } |
4046 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
4047 { | |
4048 ALmixer_Channel_List[channel].max_volume = volume; | |
4049 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4050 AL_MAX_GAIN, volume); | |
4051 if((error = alGetError()) != AL_NO_ERROR) | |
4052 { | |
4053 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4054 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4055 retval = AL_FALSE; |
0 | 4056 } |
4057 } | |
4058 } | |
4059 else | |
4060 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4061 ALint i; |
0 | 4062 for(i=0; i<Number_of_Channels_global; i++) |
4063 { | |
4064 if(volume < 0.0f) | |
4065 { | |
4066 volume = 0.0f; | |
4067 } | |
4068 else if(volume > 1.0f) | |
4069 { | |
4070 volume = 1.0f; | |
4071 } | |
4072 ALmixer_Channel_List[i].min_volume = volume; | |
4073 alSourcef(ALmixer_Channel_List[i].alsource, | |
4074 AL_MIN_GAIN, volume); | |
4075 if((error = alGetError()) != AL_NO_ERROR) | |
4076 { | |
4077 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4078 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4079 retval = AL_FALSE; |
0 | 4080 } |
4081 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
4082 { | |
4083 ALmixer_Channel_List[i].max_volume = volume; | |
4084 alSourcef(ALmixer_Channel_List[i].alsource, | |
4085 AL_MAX_GAIN, volume); | |
4086 if((error = alGetError()) != AL_NO_ERROR) | |
4087 { | |
4088 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4089 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4090 retval = AL_FALSE; |
0 | 4091 } |
4092 } | |
4093 } | |
4094 } | |
4095 return retval; | |
4096 } | |
4097 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4098 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
|
4099 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4100 ALint channel; |
0 | 4101 if(0 == source) |
4102 { | |
4103 return Internal_SetMinVolumeChannel(-1, volume); | |
4104 } | |
4105 | |
4106 channel = Internal_GetChannel(source); | |
4107 if(-1 == channel) | |
4108 { | |
4109 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
|
4110 return AL_FALSE; |
0 | 4111 } |
4112 return Internal_SetMinVolumeChannel(channel, volume); | |
4113 } | |
4114 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4115 static ALfloat Internal_GetMinVolumeChannel(ALint channel) |
0 | 4116 { |
4117 /* | |
4118 ALfloat value; | |
4119 ALenum error; | |
4120 */ | |
4121 ALfloat running_total = 0.0f; | |
4122 ALfloat retval = 0.0f; | |
4123 | |
4124 if(channel >= Number_of_Channels_global) | |
4125 { | |
4126 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); | |
4127 return -1.0f; | |
4128 } | |
4129 | |
4130 if(channel >= 0) | |
4131 { | |
4132 /* | |
4133 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
4134 AL_GAIN, &value); | |
4135 if((error = alGetError()) != AL_NO_ERROR) | |
4136 { | |
4137 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4138 alGetString(error) ); |
0 | 4139 retval = -1.0f; |
4140 } | |
4141 else | |
4142 { | |
4143 retval = value; | |
4144 } | |
4145 */ | |
4146 retval = ALmixer_Channel_List[channel].min_volume; | |
4147 | |
4148 } | |
4149 else | |
4150 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4151 ALint i; |
0 | 4152 for(i=0; i<Number_of_Channels_global; i++) |
4153 { | |
4154 /* | |
4155 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
4156 AL_GAIN, &value); | |
4157 if((error = alGetError()) != AL_NO_ERROR) | |
4158 { | |
4159 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4160 alGetString(error) ); |
0 | 4161 retval = -1; |
4162 } | |
4163 else | |
4164 { | |
4165 running_total += value; | |
4166 } | |
4167 */ | |
4168 running_total += ALmixer_Channel_List[i].min_volume; | |
4169 } | |
4170 if(0 == Number_of_Channels_global) | |
4171 { | |
4172 ALmixer_SetError("No channels are allocated"); | |
4173 retval = -1.0f; | |
4174 } | |
4175 else | |
4176 { | |
4177 retval = running_total / Number_of_Channels_global; | |
4178 } | |
4179 } | |
4180 return retval; | |
4181 } | |
4182 | |
4183 static ALfloat Internal_GetMinVolumeSource(ALuint source) | |
4184 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4185 ALint channel; |
0 | 4186 if(0 == source) |
4187 { | |
4188 return Internal_GetMinVolumeChannel(-1); | |
4189 } | |
4190 | |
4191 channel = Internal_GetChannel(source); | |
4192 if(-1 == channel) | |
4193 { | |
4194 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
4195 return -1.0f; | |
4196 } | |
4197 | |
4198 return Internal_GetMinVolumeChannel(channel); | |
4199 } | |
4200 | |
4201 | |
4202 /* Changes the listener volume */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4203 static ALboolean Internal_SetMasterVolume(ALfloat volume) |
0 | 4204 { |
4205 ALenum error; | |
4206 alListenerf(AL_GAIN, volume); | |
4207 if((error = alGetError()) != AL_NO_ERROR) | |
4208 { | |
4209 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4210 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4211 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4212 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4213 return AL_TRUE; |
0 | 4214 } |
4215 | |
4216 static ALfloat Internal_GetMasterVolume() | |
4217 { | |
4218 ALenum error; | |
4219 ALfloat volume; | |
4220 alGetListenerf(AL_GAIN, &volume); | |
4221 if((error = alGetError()) != AL_NO_ERROR) | |
4222 { | |
4223 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4224 alGetString(error) ); |
0 | 4225 return -1.0f; |
4226 } | |
4227 return volume; | |
4228 } | |
4229 | |
4230 | |
4231 | |
4232 | |
4233 /* Will fade out currently playing channels. | |
4234 * 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
|
4235 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
|
4236 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4237 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4238 ALuint counter = 0; |
0 | 4239 |
4240 /* We can't accept 0 as a value because of div-by-zero. | |
4241 * If zero, just call Halt at normal | |
4242 * volume | |
4243 */ | |
4244 if(0 == ticks) | |
4245 { | |
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
|
4246 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 4247 } |
4248 if(ticks < -1) | |
4249 { | |
4250 ticks = -1; | |
4251 } | |
4252 | |
4253 | |
4254 if(channel >= Number_of_Channels_global) | |
4255 { | |
4256 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); | |
4257 return -1; | |
4258 } | |
4259 | |
4260 if(channel >= 0) | |
4261 { | |
4262 if(ALmixer_Channel_List[channel].channel_in_use) | |
4263 { | |
4264 /* Set expire start time */ | |
4265 ALmixer_Channel_List[channel].start_time = current_time; | |
4266 /* Set the expire ticks */ | |
4267 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
4268 | |
4269 counter++; | |
4270 } | |
4271 } | |
4272 /* Else need to fade out all channels */ | |
4273 else | |
4274 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4275 ALint i; |
0 | 4276 for(i=0; i<Number_of_Channels_global; i++) |
4277 { | |
4278 if(ALmixer_Channel_List[i].channel_in_use) | |
4279 { | |
4280 /* Set expire start time */ | |
4281 ALmixer_Channel_List[i].start_time = current_time; | |
4282 /* Set the expire ticks */ | |
4283 ALmixer_Channel_List[i].expire_ticks = ticks; | |
4284 | |
4285 counter++; | |
4286 } | |
4287 } /* End for loop */ | |
4288 } | |
4289 return counter; | |
4290 } | |
4291 | |
4292 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4293 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
|
4294 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4295 ALint channel; |
0 | 4296 if(0 == source) |
4297 { | |
4298 return Internal_ExpireChannel(-1, ticks); | |
4299 } | |
4300 | |
4301 channel = Internal_GetChannel(source); | |
4302 if(-1 == channel) | |
4303 { | |
4304 ALmixer_SetError("Cannot Expire source: %s", ALmixer_GetError()); | |
4305 return -1; | |
4306 } | |
4307 return Internal_ExpireChannel(channel, ticks); | |
4308 } | |
4309 | |
4310 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4311 static ALint Internal_QueryChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4312 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4313 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4314 ALint counter = 0; |
0 | 4315 if(channel >= Number_of_Channels_global) |
4316 { | |
4317 ALmixer_SetError("Invalid channel: %d", channel); | |
4318 return -1; | |
4319 } | |
4320 | |
4321 if(channel >= 0) | |
4322 { | |
4323 return ALmixer_Channel_List[channel].channel_in_use; | |
4324 } | |
4325 | |
4326 /* Else, return the number of channels in use */ | |
4327 for(i=0; i<Number_of_Channels_global; i++) | |
4328 { | |
4329 if(ALmixer_Channel_List[i].channel_in_use) | |
4330 { | |
4331 counter++; | |
4332 } | |
4333 } | |
4334 return counter; | |
4335 } | |
4336 | |
4337 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4338 static ALint Internal_QuerySource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4339 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4340 ALint channel; |
0 | 4341 if(0 == source) |
4342 { | |
4343 return Internal_QueryChannel(-1); | |
4344 } | |
4345 | |
4346 channel = Internal_GetChannel(source); | |
4347 if(-1 == channel) | |
4348 { | |
4349 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4350 return -1; | |
4351 } | |
4352 | |
4353 return Internal_QueryChannel(channel); | |
4354 } | |
4355 | |
4356 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4357 static ALuint Internal_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4358 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4359 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4360 ALuint counter = 0; |
0 | 4361 |
4362 | |
4363 /* Else, return the number of channels in use */ | |
4364 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4365 { | |
4366 if(ALmixer_Channel_List[i].channel_in_use) | |
4367 { | |
4368 counter++; | |
4369 } | |
4370 } | |
4371 return counter; | |
4372 } | |
4373 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4374 static ALuint Internal_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4375 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4376 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4377 ALuint counter = 0; |
0 | 4378 |
4379 | |
4380 /* Else, return the number of channels in use */ | |
4381 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4382 { | |
4383 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4384 { | |
4385 counter++; | |
4386 } | |
4387 } | |
4388 return counter; | |
4389 } | |
4390 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4391 static ALuint Internal_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4392 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4393 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4394 ALuint counter = 0; |
0 | 4395 |
4396 | |
4397 /* Else, return the number of channels in use */ | |
4398 for(i=0; i<Number_of_Channels_global; i++) | |
4399 { | |
4400 if(ALmixer_Channel_List[i].channel_in_use) | |
4401 { | |
4402 counter++; | |
4403 } | |
4404 } | |
4405 return counter; | |
4406 } | |
4407 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4408 static ALuint Internal_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4409 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4410 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4411 ALuint counter = 0; |
0 | 4412 |
4413 | |
4414 /* Else, return the number of channels in use */ | |
4415 for(i=0; i<Number_of_Channels_global; i++) | |
4416 { | |
4417 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4418 { | |
4419 counter++; | |
4420 } | |
4421 } | |
4422 return counter; | |
4423 } | |
4424 | |
4425 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4426 static ALint Internal_PlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4427 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4428 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4429 ALint counter = 0; |
0 | 4430 ALint state; |
4431 | |
4432 if(channel >= Number_of_Channels_global) | |
4433 { | |
4434 ALmixer_SetError("Invalid channel: %d", channel); | |
4435 return -1; | |
4436 } | |
4437 | |
4438 if(channel >= 0) | |
4439 { | |
4440 if(ALmixer_Channel_List[channel].channel_in_use) | |
4441 { | |
4442 alGetSourcei( | |
4443 ALmixer_Channel_List[channel].alsource, | |
4444 AL_SOURCE_STATE, &state | |
4445 ); | |
4446 if(AL_PLAYING == state) | |
4447 { | |
4448 return 1; | |
4449 } | |
4450 } | |
4451 return 0; | |
4452 } | |
4453 | |
4454 /* Else, return the number of channels in use */ | |
4455 for(i=0; i<Number_of_Channels_global; i++) | |
4456 { | |
4457 if(ALmixer_Channel_List[i].channel_in_use) | |
4458 { | |
4459 alGetSourcei( | |
4460 ALmixer_Channel_List[i].alsource, | |
4461 AL_SOURCE_STATE, &state | |
4462 ); | |
4463 if(AL_PLAYING == state) | |
4464 { | |
4465 counter++; | |
4466 } | |
4467 } | |
4468 } | |
4469 return counter; | |
4470 } | |
4471 | |
4472 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4473 static ALint Internal_PlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4474 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4475 ALint channel; |
0 | 4476 if(0 == source) |
4477 { | |
4478 return Internal_PlayingChannel(-1); | |
4479 } | |
4480 | |
4481 channel = Internal_GetChannel(source); | |
4482 if(-1 == channel) | |
4483 { | |
4484 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4485 return -1; | |
4486 } | |
4487 | |
4488 return Internal_PlayingChannel(channel); | |
4489 } | |
4490 | |
4491 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4492 static ALint Internal_PausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4493 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4494 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4495 ALint counter = 0; |
0 | 4496 ALint state; |
4497 | |
4498 if(channel >= Number_of_Channels_global) | |
4499 { | |
4500 ALmixer_SetError("Invalid channel: %d", channel); | |
4501 return -1; | |
4502 } | |
4503 | |
4504 if(channel >= 0) | |
4505 { | |
4506 if(ALmixer_Channel_List[channel].channel_in_use) | |
4507 { | |
4508 alGetSourcei( | |
4509 ALmixer_Channel_List[channel].alsource, | |
4510 AL_SOURCE_STATE, &state | |
4511 ); | |
4512 if(AL_PAUSED == state) | |
4513 { | |
4514 return 1; | |
4515 } | |
4516 } | |
4517 return 0; | |
4518 } | |
4519 | |
4520 /* Else, return the number of channels in use */ | |
4521 for(i=0; i<Number_of_Channels_global; i++) | |
4522 { | |
4523 if(ALmixer_Channel_List[i].channel_in_use) | |
4524 { | |
4525 alGetSourcei( | |
4526 ALmixer_Channel_List[i].alsource, | |
4527 AL_SOURCE_STATE, &state | |
4528 ); | |
4529 if(AL_PAUSED == state) | |
4530 { | |
4531 counter++; | |
4532 } | |
4533 } | |
4534 } | |
4535 return counter; | |
4536 } | |
4537 | |
4538 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4539 static ALint Internal_PausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4540 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4541 ALint channel; |
0 | 4542 if(0 == source) |
4543 { | |
4544 return Internal_PausedChannel(-1); | |
4545 } | |
4546 | |
4547 channel = Internal_GetChannel(source); | |
4548 if(-1 == channel) | |
4549 { | |
4550 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4551 return -1; | |
4552 } | |
4553 | |
4554 return Internal_PausedChannel(channel); | |
4555 } | |
4556 | |
4557 | |
4558 | |
4559 | |
4560 | |
4561 | |
4562 /* Private function for Updating ALmixer. | |
4563 * This is a very big and ugly function. | |
4564 * It should return the number of buffers that were | |
4565 * queued during the call. The value might be | |
4566 * used to guage how long you might wait to | |
4567 * call the next update loop in case you are worried | |
4568 * about preserving CPU cycles. The idea is that | |
4569 * when a buffer is queued, there was probably some | |
4570 * CPU intensive looping which took awhile. | |
4571 * 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
|
4572 * Timing the call with ALmixer_GetTicks() would produce |
0 | 4573 * more accurate information. |
4574 * Returns a negative value if there was an error, | |
4575 * the value being the number of errors. | |
4576 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4577 static ALint Update_ALmixer(void* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4578 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4579 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4580 ALint error_flag = 0; |
0 | 4581 ALenum error; |
4582 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4583 ALint i=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4584 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4585 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4586 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4587 #endif |
0 | 4588 if(0 == ALmixer_Initialized) |
4589 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4590 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4591 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4592 #endif |
0 | 4593 return 0; |
4594 } | |
4595 | |
4596 /* Check the quick flag to see if anything needs updating */ | |
4597 /* If anything is playing, then we have to do work */ | |
4598 if( 0 == Is_Playing_global) | |
4599 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4600 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4601 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4602 #endif |
0 | 4603 return 0; |
4604 } | |
4605 /* Clear error */ | |
4606 if((error = alGetError()) != AL_NO_ERROR) | |
4607 { | |
4608 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
|
4609 alGetString(error)); |
0 | 4610 } |
4611 alGetError(); | |
4612 | |
4613 for(i=0; i<Number_of_Channels_global; i++) | |
4614 { | |
4615 if( ALmixer_Channel_List[i].channel_in_use ) | |
4616 { | |
4617 | |
4618 /* For simplicity, before we do anything else, | |
4619 * we can check the timeout and fading values | |
4620 * and do the appropriate things | |
4621 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4622 ALuint current_time = ALmixer_GetTicks(); |
0 | 4623 |
4624 /* Check to see if we need to halt due to Timed play */ | |
4625 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
4626 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4627 ALuint target_time = (ALuint)ALmixer_Channel_List[i].expire_ticks |
0 | 4628 + ALmixer_Channel_List[i].start_time; |
4629 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4630 AL_SOURCE_STATE, &state); | |
4631 if((error = alGetError()) != AL_NO_ERROR) | |
4632 { | |
4633 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
|
4634 alGetString(error)); |
0 | 4635 } |
4636 | |
4637 /* Check the time, and also make sure that it is not | |
4638 * paused (if paused, we don't want to make the | |
4639 * evaluation because when resumed, we will adjust | |
4640 * the times to compensate for the pause). | |
4641 */ | |
4642 if( (current_time >= target_time) | |
4643 && (state != AL_PAUSED) ) | |
4644 { | |
4645 /* 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
|
4646 Internal_HaltChannel(i, AL_FALSE); |
0 | 4647 if((error = alGetError()) != AL_NO_ERROR) |
4648 { | |
4649 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
|
4650 alGetString(error)); |
0 | 4651 } |
4652 | |
4653 /* Everything should be done so go on to the next loop */ | |
4654 continue; | |
4655 } | |
4656 } /* End if time expired check */ | |
4657 | |
4658 /* Check to see if we need to adjust the volume for fading */ | |
4659 if( ALmixer_Channel_List[i].fade_enabled ) | |
4660 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4661 ALuint target_time = ALmixer_Channel_List[i].fade_expire_ticks |
0 | 4662 + ALmixer_Channel_List[i].fade_start_time; |
4663 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4664 AL_SOURCE_STATE, &state); | |
4665 if((error = alGetError()) != AL_NO_ERROR) | |
4666 { | |
4667 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
|
4668 alGetString(error)); |
0 | 4669 } |
4670 | |
4671 /* Check the time, and also make sure that it is not | |
4672 * paused (if paused, we don't want to make the | |
4673 * evaluation because when resumed, we will adjust | |
4674 * the times to compensate for the pause). | |
4675 */ | |
4676 if(state != AL_PAUSED) | |
4677 { | |
4678 ALfloat t; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4679 ALuint delta_time; |
0 | 4680 ALfloat current_volume; |
4681 if(current_time >= target_time) | |
4682 { | |
4683 /* Need to constrain value to the end time | |
4684 * (can't go pass the value for calculations) | |
4685 */ | |
4686 current_time = target_time; | |
4687 /* We can disable the fade flag now */ | |
4688 ALmixer_Channel_List[i].fade_enabled = 0; | |
4689 } | |
4690 /* Use the linear interpolation formula: | |
4691 * X = (1-t)x0 + tx1 | |
4692 * where x0 would be the start value | |
4693 * and x1 is the final value | |
4694 * and t is delta_time*inv_time (adjusts 0 <= time <= 1) | |
4695 * delta_time = current_time-start_time | |
4696 * inv_time = 1/ (end_time-start_time) | |
4697 * so t = current_time-start_time / (end_time-start_time) | |
4698 * | |
4699 */ | |
4700 delta_time = current_time - ALmixer_Channel_List[i].fade_start_time; | |
4701 t = (ALfloat) delta_time * ALmixer_Channel_List[i].fade_inv_time; | |
4702 current_volume = (1.0f-t) * ALmixer_Channel_List[i].fade_start_volume | |
4703 + t * ALmixer_Channel_List[i].fade_end_volume; | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
4704 fprintf(stderr, "start_vol=%f, end_vol:%f, current_volume: %f\n", ALmixer_Channel_List[i].fade_start_volume, ALmixer_Channel_List[i].fade_end_volume, current_volume); |
0 | 4705 |
4706 /* Set the volume */ | |
4707 alSourcef(ALmixer_Channel_List[i].alsource, | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
4708 AL_GAIN, current_volume); |
0 | 4709 if((error = alGetError()) != AL_NO_ERROR) |
4710 { | |
4711 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
|
4712 alGetString(error)); |
0 | 4713 } |
4714 | |
4715 /* | |
4716 fprintf(stderr, "Current time =%d\n", current_time); | |
4717 fprintf(stderr, "Current vol=%f on channel %d\n", current_volume, i); | |
4718 */ | |
4719 } /* End if not PAUSED */ | |
4720 } /* End if fade_enabled */ | |
4721 | |
4722 | |
4723 /* Okay, now that the time expired and fading stuff | |
4724 * is done, do the rest of the hard stuff | |
4725 */ | |
4726 | |
4727 | |
4728 /* For predecoded, check to see if done */ | |
4729 if( ALmixer_Channel_List[i].almixer_data->decoded_all ) | |
4730 { | |
4731 | |
4732 #if 0 | |
4733 /********* Remove this **********/ | |
4734 ALint buffers_processed; | |
4735 ALint buffers_still_queued; | |
4736 fprintf(stderr, "For Predecoded\n"); | |
4737 | |
4738 alGetSourcei( | |
4739 ALmixer_Channel_List[i].alsource, | |
4740 AL_SOURCE_STATE, &state | |
4741 ); | |
4742 switch(state) { | |
4743 case AL_PLAYING: | |
4744 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
4745 break; | |
4746 case AL_PAUSED: | |
4747 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
4748 break; | |
4749 case AL_STOPPED: | |
4750 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
4751 break; | |
4752 case AL_INITIAL: | |
4753 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
4754 break; | |
4755 default: | |
4756 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
4757 break; | |
4758 } | |
4759 | |
4760 alGetSourcei( | |
4761 ALmixer_Channel_List[i].alsource, | |
4762 AL_BUFFERS_PROCESSED, &buffers_processed | |
4763 ); | |
4764 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
4765 | |
4766 alGetSourcei( | |
4767 ALmixer_Channel_List[i].alsource, | |
4768 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4769 ); | |
4770 | |
4771 /******** END REMOVE *******/ | |
4772 #endif | |
4773 /* FIXME: Ugh! Somewhere an alError is being thrown ("Invalid Enum Value"), but I can't | |
4774 * find it. It only seems to be thrown for OS X. I placed error messages after every al* | |
4775 * command I could find in the above loops, but the error doesn't seem to show | |
4776 * up until around here. I mistook it for a get queued buffers | |
4777 * error in OS X. I don't think there's an error down there. | |
4778 * For now, I'm clearing the error here. | |
4779 */ | |
4780 | |
4781 if((error = alGetError()) != AL_NO_ERROR) | |
4782 { | |
4783 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
|
4784 alGetString(error)); |
0 | 4785 } |
4786 | |
4787 | |
4788 alGetSourcei( | |
4789 ALmixer_Channel_List[i].alsource, | |
4790 AL_SOURCE_STATE, &state | |
4791 ); | |
4792 if((error = alGetError()) != AL_NO_ERROR) | |
4793 { | |
4794 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
|
4795 alGetString(error)); |
0 | 4796 } |
4797 | |
4798 | |
4799 if(AL_STOPPED == state) | |
4800 { | |
4801 /* Playback has ended. | |
4802 * Loop if necessary, or launch callback | |
4803 * and clear channel (or clear channel and | |
4804 * then launch callback?) | |
4805 */ | |
4806 | |
4807 | |
4808 /* Need to check for loops */ | |
4809 if(ALmixer_Channel_List[i].loops != 0) | |
4810 { | |
4811 /* Corner Case: If the buffer has | |
4812 * been modified using Seek, | |
4813 * the loop will start at the seek | |
4814 * position. | |
4815 */ | |
4816 if(ALmixer_Channel_List[i].loops != -1) | |
4817 { | |
4818 ALmixer_Channel_List[i].loops--; | |
4819 } | |
4820 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
4821 if((error = alGetError()) != AL_NO_ERROR) | |
4822 { | |
4823 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
|
4824 alGetString(error)); |
0 | 4825 } |
4826 continue; | |
4827 } | |
4828 /* No loops. End play. */ | |
4829 else | |
4830 { | |
4831 /* Problem: It seems that when mixing | |
4832 * streamed and predecoded sources, | |
4833 * the previous instance lingers, | |
4834 * so we need to force remove | |
4835 * the data from the source. | |
4836 * The sharing problem | |
4837 * occurs when a previous predecoded buffer is played on | |
4838 * a source, and then a streamed source is played later | |
4839 * on that same source. OpenAL isn't consistently | |
4840 * removing the previous buffer so both get played. | |
4841 * (Different dists seem to have different quirks. | |
4842 * The problem might lead to crashes in the worst case.) | |
4843 */ | |
4844 /* Additional problem: There is another | |
4845 * inconsistency among OpenAL distributions. | |
4846 * Both Loki and Creative Windows seem to keep | |
4847 * the buffer queued which requires removing. | |
4848 * But the Creative Macintosh version does | |
4849 * not have any buffer queued after play | |
4850 * and it returns the error: Invalid Enum Value | |
4851 * if I try to unqueue it. | |
4852 * So I'm going to put in a check to see if I | |
4853 * can detect any buffers queued first | |
4854 * and then unqueue them if I can see them. | |
4855 * Additional note: The new CoreAudio based | |
4856 * implementation leaves it's buffer queued | |
4857 * like Loki and Creative Windows. But | |
4858 * considering all the problems I'm having | |
4859 * with the different distributions, this | |
4860 * check seems reasonable. | |
4861 */ | |
4862 ALint buffers_still_queued; | |
4863 if((error = alGetError()) != AL_NO_ERROR) | |
4864 { | |
4865 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
|
4866 alGetString(error)); |
0 | 4867 } |
4868 | |
4869 alGetSourcei( | |
4870 ALmixer_Channel_List[i].alsource, | |
4871 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4872 ); | |
4873 if((error = alGetError()) != AL_NO_ERROR) | |
4874 { | |
4875 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
|
4876 alGetString(error)); |
0 | 4877 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
|
4878 alGetString(error) ); |
0 | 4879 error_flag--; |
4880 } | |
4881 if(buffers_still_queued > 0) | |
4882 { | |
1 | 4883 |
4884 #if 0 /* This triggers an error in OS X Core Audio. */ | |
4885 alSourceUnqueueBuffers( | |
4886 ALmixer_Channel_List[i].alsource, | |
4887 1, | |
4888 ALmixer_Channel_List[i].almixer_data->buffer | |
4889 ); | |
4890 #else | |
4891 /* fprintf(stderr, "In the Bob Aron section...about to clear source\n"); | |
0 | 4892 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 4893 */ |
0 | 4894 /* Rather than force unqueuing the buffer, let's see if |
4895 * setting the buffer to none works (the OpenAL 1.0 | |
4896 * Reference Annotation suggests this should work). | |
4897 */ | |
4898 alSourcei(ALmixer_Channel_List[i].alsource, | |
4899 AL_BUFFER, AL_NONE); | |
4900 /* | |
4901 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
4902 */ | |
1 | 4903 #endif |
0 | 4904 if((error = alGetError()) != AL_NO_ERROR) |
4905 { | |
4906 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
|
4907 alGetString(error)); |
0 | 4908 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
|
4909 alGetString(error) ); |
0 | 4910 error_flag--; |
4911 } | |
4912 | |
4913 } | |
4914 | |
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
|
4915 /* 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
|
4916 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
|
4917 |
0 | 4918 Clean_Channel(i); |
4919 /* Subtract counter */ | |
4920 Is_Playing_global--; | |
4921 | |
4922 | |
4923 /* We're done for this loop. | |
4924 * Go to next channel | |
4925 */ | |
4926 continue; | |
4927 } | |
4928 continue; | |
4929 } | |
4930 } /* End if decoded_all */ | |
4931 /* For streamed */ | |
4932 else | |
4933 { | |
4934 ALint buffers_processed; | |
4935 ALint buffers_still_queued; | |
4936 ALint current_buffer_id; | |
4937 | |
4938 ALuint unqueued_buffer_id; | |
4939 #if 0 | |
4940 /********* Remove this **********/ | |
4941 fprintf(stderr, "For Streamed\n"); | |
4942 | |
4943 alGetSourcei( | |
4944 ALmixer_Channel_List[i].alsource, | |
4945 AL_SOURCE_STATE, &state | |
4946 ); | |
4947 switch(state) { | |
4948 case AL_PLAYING: | |
4949 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
4950 break; | |
4951 case AL_PAUSED: | |
4952 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
4953 break; | |
4954 case AL_STOPPED: | |
4955 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
4956 break; | |
4957 case AL_INITIAL: | |
4958 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
4959 break; | |
4960 default: | |
4961 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
4962 break; | |
4963 } | |
4964 /******** END REMOVE *******/ | |
4965 #endif | |
4966 /* Get the number of buffers still queued */ | |
4967 alGetSourcei( | |
4968 ALmixer_Channel_List[i].alsource, | |
4969 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4970 ); | |
4971 if((error = alGetError()) != AL_NO_ERROR) | |
4972 { | |
4973 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
|
4974 alGetString(error)); |
0 | 4975 } |
4976 /* Get the number of buffers processed | |
4977 * so we know if we need to refill | |
4978 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4979 /* 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
|
4980 * 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
|
4981 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4982 // fprintf(stderr, "calling AL_BUFFERS_PROCESSED on source:%d", ALmixer_Channel_List[i].alsource); |
0 | 4983 alGetSourcei( |
4984 ALmixer_Channel_List[i].alsource, | |
4985 AL_BUFFERS_PROCESSED, &buffers_processed | |
4986 ); | |
4987 if((error = alGetError()) != AL_NO_ERROR) | |
4988 { | |
4989 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
|
4990 alGetString(error)); |
0 | 4991 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4992 // fprintf(stderr, "finished AL_BUFFERS_PROCESSED, buffers_processed=%d", buffers_processed); |
0 | 4993 |
4994 /* WTF!!! The Nvidia distribution is failing on the alGetSourcei(source, AL_BUFFER, buf_id) call. | |
4995 * I need this call to figure out which buffer OpenAL is currently playing. | |
4996 * It keeps returning an "Invalid Enum" error. | |
4997 * This is totally inane! It's a basic query. | |
4998 * By the spec, this functionality is not explicitly defined so Nvidia refuses to | |
4999 * fix this behavior, even though all other distributions work fine with this. | |
5000 * The only workaround for this is for | |
5001 * a significant rewrite of my code which requires me to | |
5002 * duplicate the OpenAL queued buffers state with my own | |
5003 * code and try to derive what the current playing buffer is by indirect observation of | |
5004 * looking at buffers_processed. But of course this has a ton of downsides since my | |
5005 * queries do not give me perfect timing of what OpenAL is actually doing and | |
5006 * the fact that some of the distributions seem to have buffer queuing problems | |
5007 * with their query results (CoreAudio). This also means a ton of extra code | |
5008 * on my side. The lack of support of a 1 line call has required me to | |
5009 * implement yet another entire state machine. <sigh> | |
5010 */ | |
5011 #if 0 /* This code will not work until possibly OpenAL 1.1 because of Nvidia */ | |
5012 /* Get the id to the current buffer playing */ | |
5013 alGetSourcei( | |
5014 ALmixer_Channel_List[i].alsource, | |
5015 AL_BUFFER, ¤t_buffer_id | |
5016 ); | |
5017 if((error = alGetError()) != AL_NO_ERROR) | |
5018 { | |
5019 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
|
5020 alGetString(error)); |
0 | 5021 } |
5022 | |
5023 /* Before the hard stuff, check to see if the | |
5024 * current queued AL buffer has changed. | |
5025 * If it has, we should launch a data callback if | |
5026 * necessary | |
5027 */ | |
5028 if( ((ALuint)current_buffer_id) != | |
5029 ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5030 { | |
5031 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5032 = (ALuint)current_buffer_id; | |
5033 | |
5034 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5035 } | |
5036 #else | |
5037 /* Only do this if "access_data" was requested (i.e. the circular_buffer!=NULL) | |
5038 * And if one of the two are true: | |
5039 * Either buffers_processed > 0 (because the current_buffer might have changed) | |
5040 * or if the current_buffer==0 (because we are in an initial state or recovering from | |
5041 * a buffer underrun) | |
5042 */ | |
5043 if((ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5044 && ( | |
5045 (buffers_processed > 0) || (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5046 ) | |
5047 ) | |
5048 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5049 ALint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5050 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5051 ALubyte is_out_of_sync = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5052 ALuint my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
1 | 5053 /* Ugh, I have to deal with signed/unsigned mismatch here. */ |
5054 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
|
5055 ALuint unplayed_buffers; |
1 | 5056 if(buffers_unplayed_int < 0) |
5057 { | |
5058 unplayed_buffers = 0; | |
5059 } | |
5060 else | |
5061 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5062 unplayed_buffers = (ALuint)buffers_unplayed_int; |
1 | 5063 } |
0 | 5064 /* |
5065 fprintf(stderr, "Queue in processed check, before pop, buffers_processed=%d\n", buffers_processed); | |
5066 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5067 */ | |
5068 /* We can't make any determinations solely based on the number of buffers_processed | |
5069 * because currently, we only unqueue 1 buffer per loop. That means if 2 or more | |
5070 * buffers became processed in one loop, the following loop, we would have | |
5071 * at least that_many-1 buffers_processed (plus possible new processed). | |
5072 * If we tried to just remove 1 buffer from our queue, we would be incorrect | |
5073 * because we would not actually reflect the current playing buffer. | |
5074 * So the solution seems to be to make sure our queue is the same size | |
5075 * as the number of buffers_queued-buffers_processed, and return the head of our queue | |
5076 * as the current playing buffer. | |
5077 */ | |
5078 /* Also, we have a corner case. When we first start playing or if we have | |
5079 * a buffer underrun, we have not done a data callback. | |
5080 * In this case, we need to see if there is any new data in our queue | |
5081 * and if so, launch that data callback. | |
5082 */ | |
5083 /* Warning, this code risks the possibility of no data callback being fired if | |
5084 * the system is really late (or skipped buffers). | |
5085 */ | |
5086 | |
5087 /* First, let's syncronize our queue with the OpenAL queue */ | |
5088 #if 0 | |
5089 fprintf(stderr, "inside, Buffers processed=%d, Buffers queued=%d, my queue=%d\n", | |
5090 buffers_processed, buffers_still_queued, my_queue_size); | |
1 | 5091 #endif |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5092 is_out_of_sync = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5093 for(k=0; k<buffers_processed; k++) |
0 | 5094 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5095 queue_ret_flag = CircularQueueUnsignedInt_PopFront( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5096 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
|
5097 if(0 == queue_ret_flag) |
0 | 5098 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5099 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
|
5100 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5101 } |
0 | 5102 my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
5103 /* We have several possibilities we need to handle: | |
5104 * 1) We are in an initial state or underrun and need to do a data callback on the head. | |
5105 * 2) We were out of sync and need to do a new data callback on the new head. | |
5106 * 3) We were not out of sync but just had left over processed buffers which caused us to | |
5107 * fall in this block of code. (Don't do anything.) | |
5108 */ | |
5109 if( (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) || (1 == is_out_of_sync) ) | |
5110 { | |
5111 if(my_queue_size > 0) | |
5112 { | |
5113 current_buffer_id = CircularQueueUnsignedInt_Front( | |
5114 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5115 if(0 == current_buffer_id) | |
5116 { | |
5117 fprintf(stderr, "53a Internal Error, current_buffer_id=0 when it shouldn't be 0\n"); | |
5118 } | |
5119 /* | |
5120 else | |
5121 { | |
5122 fprintf(stderr, "Queue in processed check, after pop\n"); | |
5123 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5124 } | |
5125 */ | |
5126 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5127 = (ALuint)current_buffer_id; | |
5128 | |
5129 #if 0 | |
5130 /* Remove me...only for checking...doesn't work on Nvidia */ | |
5131 { | |
5132 ALuint real_id; | |
5133 alGetSourcei( | |
5134 ALmixer_Channel_List[i].alsource, | |
5135 AL_BUFFER, &real_id | |
5136 ); | |
5137 alGetError(); | |
5138 fprintf(stderr, "Callback fired on data buffer=%d, real_id shoud be=%d\n", current_buffer_id, real_id); | |
5139 } | |
5140 #endif | |
5141 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5142 } | |
5143 else | |
5144 { | |
1 | 5145 /* |
0 | 5146 fprintf(stderr, "53b, Notice/Warning:, OpenAL queue has been depleted.\n"); |
1 | 5147 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
5148 */ | |
0 | 5149 /* In this case, we might either be in an underrun or finished with playback */ |
5150 ALmixer_Channel_List[i].almixer_data->current_buffer = 0; | |
5151 } | |
5152 } | |
5153 } | |
5154 #endif | |
5155 | |
5156 | |
5157 | |
5158 /* Just a test - remove | |
5159 if( ALmixer_Channel_List[i].loops > 0) | |
5160 { | |
5161 fprintf(stderr, ">>>>>>>>>>>>>>>Loops = %d\n", | |
5162 ALmixer_Channel_List[i].loops); | |
5163 } | |
5164 */ | |
5165 #if 0 | |
5166 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
5167 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5168 #endif | |
5169 /* We've used up a buffer so we need to unqueue and replace */ | |
5170 /* Okay, it gets more complicated here: | |
5171 * We need to Queue more data | |
5172 * if buffers_processed > 0 or | |
5173 * if num_of_buffers_in_use < NUMBER_OF_QUEUE_BUFFERS | |
5174 * but we don't do this if at EOF, | |
5175 * except when there is looping | |
5176 */ | |
5177 /* For this to work, we must rely on EVERYTHING | |
5178 * else to unset the EOF if there is looping. | |
5179 * Remember, even Play() must do this | |
5180 */ | |
5181 | |
5182 /* If not EOF, then we are still playing. | |
5183 * Inside, we might find num_of_buffers < NUM...QUEUE_BUF.. | |
5184 * or buffers_process > 0 | |
5185 * in which case we queue up. | |
5186 * We also might find no buffers we need to fill, | |
5187 * in which case we just keep going | |
5188 */ | |
5189 if( ! ALmixer_Channel_List[i].almixer_data->eof) | |
5190 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5191 ALuint bytes_returned; |
0 | 5192 /* We have a priority. We first must assign |
5193 * unused buffers in reserve. If there is nothing | |
5194 * left, then we may unqueue buffers. We can't | |
5195 * do it the other way around because we will | |
5196 * lose the pointer to the unqueued buffer | |
5197 */ | |
5198 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5199 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5200 { | |
1 | 5201 #if 0 |
0 | 5202 fprintf(stderr, "Getting more data in NOT_EOF and num_buffers_in_use (%d) < max_queue (%d)\n", |
5203 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5204 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5205 #endif |
0 | 5206 /* Going to add an unused packet. |
5207 * Grab next packet */ | |
5208 bytes_returned = GetMoreData( | |
5209 ALmixer_Channel_List[i].almixer_data, | |
5210 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5211 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5212 ); | |
5213 } | |
5214 /* For processed > 0 */ | |
5215 else if(buffers_processed > 0) | |
5216 { | |
5217 /* Unqueue only 1 buffer for now. | |
5218 * If there are more than one, | |
5219 * let the next Update pass deal with it | |
5220 * so we don't stall the program for too long. | |
5221 */ | |
5222 #if 0 | |
5223 fprintf(stderr, "About to Unqueue, Buffers processed = %d\n", buffers_processed); | |
5224 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5225 fprintf(stderr, "Unqueuing a buffer\n"); | |
5226 #endif | |
5227 alSourceUnqueueBuffers( | |
5228 ALmixer_Channel_List[i].alsource, | |
5229 1, &unqueued_buffer_id | |
5230 ); | |
5231 if((error = alGetError()) != AL_NO_ERROR) | |
5232 { | |
5233 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
|
5234 alGetString(error)); |
0 | 5235 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
|
5236 alGetString(error) ); |
0 | 5237 error_flag--; |
5238 } | |
5239 /* | |
5240 fprintf(stderr, "Right after unqueue..."); | |
5241 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5242 fprintf(stderr, "Getting more data for NOT_EOF, max_buffers filled\n"); | |
5243 */ | |
5244 /* Grab unqueued packet */ | |
5245 bytes_returned = GetMoreData( | |
5246 ALmixer_Channel_List[i].almixer_data, | |
5247 unqueued_buffer_id); | |
5248 } | |
5249 /* We are still streaming, but currently | |
5250 * don't need to fill any buffers */ | |
5251 else | |
5252 { | |
5253 /* Might want to check state */ | |
5254 /* In case the playback stopped, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5255 * we need to resume |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5256 * a.k.a. buffer underrun |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5257 */ |
1 | 5258 #if 1 |
5259 /* Try not refetching the state here because I'm getting a duplicate | |
5260 buffer playback (hiccup) */ | |
0 | 5261 alGetSourcei( |
5262 ALmixer_Channel_List[i].alsource, | |
5263 AL_SOURCE_STATE, &state | |
5264 ); | |
1 | 5265 if((error = alGetError()) != AL_NO_ERROR) |
5266 { | |
5267 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
|
5268 alGetString(error)); |
1 | 5269 } |
5270 /* Get the number of buffers processed | |
5271 */ | |
5272 alGetSourcei( | |
5273 ALmixer_Channel_List[i].alsource, | |
5274 AL_BUFFERS_PROCESSED, | |
5275 &buffers_processed | |
5276 ); | |
5277 if((error = alGetError()) != AL_NO_ERROR) | |
5278 { | |
5279 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
|
5280 alGetString(error)); |
1 | 5281 } |
5282 #endif | |
0 | 5283 if(AL_STOPPED == state) |
5284 { | |
5285 /* Resuming in not eof, but nothing to buffer */ | |
1 | 5286 |
5287 /* Okay, here's another lately discovered problem: | |
5288 * I can't find it in the spec, but for at least some of the | |
5289 * implementations, if I call play on a stopped source that | |
5290 * has processed buffers, all those buffers get marked as unprocessed | |
5291 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5292 * processed, on resume, the earlier 24 buffers will get replayed, | |
5293 * causing a "hiccup" like sound in the playback. | |
5294 * To avoid this, I must unqueue all processed buffers before | |
5295 * calling play. But to complicate things, I need to worry about resyncing | |
5296 * the circular queue with this since I designed this thing | |
5297 * with some correlation between the two. However, I might | |
5298 * have already handled this, so I will try writing this code without | |
5299 * syncing for now. | |
5300 * There is currently an assumption that a buffer | |
5301 * was queued above so I actually have something | |
5302 * to play. | |
5303 */ | |
5304 ALint temp_count; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5305 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5306 fprintf(stderr, "STOPPED1, need to clear processed=%d, status is:\n", buffers_processed); |
1 | 5307 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
|
5308 #endif |
1 | 5309 for(temp_count=0; temp_count<buffers_processed; temp_count++) |
5310 { | |
5311 alSourceUnqueueBuffers( | |
5312 ALmixer_Channel_List[i].alsource, | |
5313 1, &unqueued_buffer_id | |
5314 ); | |
5315 if((error = alGetError()) != AL_NO_ERROR) | |
5316 { | |
5317 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
|
5318 alGetString(error)); |
1 | 5319 error_flag--; |
5320 } | |
5321 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5322 #if 0 |
1 | 5323 fprintf(stderr, "After unqueue clear...:\n"); |
5324 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
|
5325 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5326 /* 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
|
5327 * 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
|
5328 * 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
|
5329 * 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
|
5330 * no buffers in queue. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5331 * 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
|
5332 * Then we need to resume playing. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5333 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5334 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5335 int buffers_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5336 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5337 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5338 AL_BUFFERS_QUEUED, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5339 &buffers_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5340 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5341 |
1 | 5342 if((error = alGetError()) != AL_NO_ERROR) |
5343 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5344 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
|
5345 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5346 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5347 assert(buffers_queued == 0); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5348 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
|
5349 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5350 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5351 /* 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
|
5352 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
|
5353 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5354 /* 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
|
5355 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5356 ALmixer_Channel_List[i].almixer_data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5357 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
|
5358 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5359 /* 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
|
5360 * 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
|
5361 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5362 if(bytes_returned > 0) |
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 /* Queue up the new data */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5365 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5366 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5367 1, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5368 &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
|
5369 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5370 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5371 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5372 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
|
5373 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5374 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5375 /* 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
|
5376 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
|
5377 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5378 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5379 /* 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
|
5380 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
|
5381 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5382 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5383 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
|
5384 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5385 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
|
5386 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
|
5387 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5388 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5389 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5390 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
|
5391 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
|
5392 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5393 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5394 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5395 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5396 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5397 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5398 /* Resume playback from underrun */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5399 alSourcePlay(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5400 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5401 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5402 fprintf(stderr, "55Tbesting error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5403 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5404 } |
1 | 5405 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5406 |
0 | 5407 } |
5408 /* Let's escape to the next loop. | |
5409 * All code below this point is for queuing up | |
5410 */ | |
5411 /* | |
1 | 5412 fprintf(stderr, "Entry: Nothing to do...continue\n\n"); |
5413 */ | |
0 | 5414 continue; |
5415 } | |
5416 /* We now know we have to fill an available | |
5417 * buffer. | |
5418 */ | |
5419 | |
5420 /* In the previous branch, we just grabbed more data. | |
5421 * Let's check it to make sure it's okay, | |
5422 * and then queue it up | |
5423 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5424 /* This check doesn't work anymore because it is now ALuint */ |
0 | 5425 #if 0 |
5426 if(-1 == bytes_returned) | |
5427 { | |
5428 /* Problem occurred...not sure what to do */ | |
5429 /* Go to next loop? */ | |
5430 error_flag--; | |
5431 /* Set the eof flag to force a quit so | |
5432 * we don't get stuck in an infinite loop | |
5433 */ | |
5434 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5435 continue; | |
5436 } | |
5437 #endif | |
5438 /* This is a special case where we've run | |
5439 * out of data. We should check for loops | |
5440 * and get more data. If there is no loop, | |
5441 * then do nothing and wait for future | |
5442 * update passes to handle the EOF. | |
5443 * The advantage of handling the loop here | |
5444 * instead of waiting for play to stop is | |
5445 * that we should be able to keep the buffer | |
5446 * filled. | |
5447 */ | |
5448 #if 0 | |
5449 else if(0 == bytes_returned) | |
5450 #endif | |
5451 if(0 == bytes_returned) | |
5452 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5453 /* |
0 | 5454 fprintf(stderr, "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
|
5455 */ |
0 | 5456 /* Check for loops */ |
5457 if( ALmixer_Channel_List[i].loops != 0 ) | |
5458 { | |
5459 /* We have to loop, so rewind | |
5460 * and fetch more data | |
5461 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5462 /* |
0 | 5463 fprintf(stderr, "Rewinding data\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5464 */ |
0 | 5465 if(0 == Sound_Rewind( |
5466 ALmixer_Channel_List[i].almixer_data->sample)) | |
5467 { | |
5468 fprintf(stderr, "Rewinding failed\n"); | |
5469 ALmixer_SetError( Sound_GetError() ); | |
5470 ALmixer_Channel_List[i].loops = 0; | |
5471 error_flag--; | |
5472 /* We'll continue on because we do have some valid data */ | |
5473 continue; | |
5474 } | |
5475 /* Remember to reset the data->eof flag */ | |
5476 ALmixer_Channel_List[i].almixer_data->eof = 0; | |
5477 if(ALmixer_Channel_List[i].loops > 0) | |
5478 { | |
5479 ALmixer_Channel_List[i].loops--; | |
5480 } | |
5481 /* Try grabbing another packet now. | |
5482 * Since we may have already unqueued a | |
5483 * buffer, we don't want to lose it. | |
5484 */ | |
5485 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5486 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5487 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5488 /* |
0 | 5489 fprintf(stderr, "We 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
|
5490 */ |
0 | 5491 /* Grab next packet */ |
5492 bytes_returned = GetMoreData( | |
5493 ALmixer_Channel_List[i].almixer_data, | |
5494 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5495 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5496 ); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5497 /* |
0 | 5498 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
|
5499 */ |
0 | 5500 } |
5501 /* Refilling unqueued packet */ | |
5502 else | |
5503 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5504 /* |
0 | 5505 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
|
5506 */ |
0 | 5507 /* Grab next packet */ |
5508 bytes_returned = GetMoreData( | |
5509 ALmixer_Channel_List[i].almixer_data, | |
5510 unqueued_buffer_id); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5511 /* |
0 | 5512 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
|
5513 */ |
0 | 5514 } |
5515 /* Another error check */ | |
5516 /* | |
5517 if(bytes_returned <= 0) | |
5518 */ | |
5519 if(0 == bytes_returned) | |
5520 { | |
5521 fprintf(stderr, "??????????ERROR\n"); | |
5522 ALmixer_SetError("Could not loop because after rewind, no data could be retrieved"); | |
5523 /* Problem occurred...not sure what to do */ | |
5524 /* Go to next loop? */ | |
5525 error_flag--; | |
5526 /* Set the eof flag to force a quit so | |
5527 * we don't get stuck in an infinite loop | |
5528 */ | |
5529 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5530 continue; | |
5531 } | |
5532 /* We made it to the end. We still need | |
5533 * to BufferData, so let this branch | |
5534 * fall into the next piece of | |
5535 * code below which will handle that | |
5536 */ | |
5537 | |
5538 | |
5539 } /* END loop check */ | |
5540 else | |
5541 { | |
5542 /* No more loops to do. | |
5543 * EOF flag should be set. | |
5544 * Just go to next loop and | |
5545 * let things be handled correctly | |
5546 * in future update calls | |
5547 */ | |
1 | 5548 /* |
0 | 5549 fprintf(stderr, "SHOULD BE EOF\n"); |
5550 | |
5551 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
1 | 5552 */ |
0 | 5553 continue; |
5554 } | |
5555 } /* END if bytes_returned == 0 */ | |
5556 /********* Possible trouble point. I might be queueing empty buffers on the mac. | |
5557 * This check doesn't say if the buffer is valid. Only the EOF assumption is a clue at this point | |
5558 */ | |
5559 /* Fall here */ | |
5560 /* Everything is normal. We aren't | |
5561 * at an EOF, but need to simply | |
5562 * queue more data. The data is already checked for good, | |
5563 * so queue it up */ | |
5564 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5565 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5566 { | |
5567 /* Keep count of how many buffers we have | |
5568 * to queue so we can return the value | |
5569 */ | |
5570 retval++; | |
1 | 5571 /* |
0 | 5572 fprintf(stderr, "NOT_EOF???, about to Queue more data for num_buffers (%d) < max_queue (%d)\n", |
5573 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5574 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5575 */ |
0 | 5576 alSourceQueueBuffers( |
5577 ALmixer_Channel_List[i].alsource, | |
5578 1, | |
5579 &ALmixer_Channel_List[i].almixer_data->buffer[ | |
5580 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5581 ); | |
5582 if((error = alGetError()) != AL_NO_ERROR) | |
5583 { | |
5584 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
|
5585 alGetString(error)); |
0 | 5586 } |
5587 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5588 * which buffer to show during callbacks (for things like | |
5589 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5590 * data structure. This code will be called only if | |
5591 * "access_data" was set, indicated by whether the queue is NULL. | |
5592 */ | |
5593 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5594 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5595 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5596 // fprintf(stderr, "56d: CircularQueue_PushBack.\n"); |
0 | 5597 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5598 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5599 ALmixer_Channel_List[i].almixer_data->buffer[ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5600 ); | |
5601 if(0 == queue_ret_flag) | |
5602 { | |
5603 fprintf(stderr, "56aSerious internal error: CircularQueue could not push into queue.\n"); | |
5604 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5605 } | |
5606 /* | |
5607 else | |
5608 { | |
5609 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5610 } | |
5611 */ | |
5612 } | |
5613 } | |
5614 /* for processed > 0 */ | |
5615 else | |
5616 { | |
5617 /* Keep count of how many buffers we have | |
5618 * to queue so we can return the value | |
5619 */ | |
5620 retval++; | |
5621 /* | |
5622 fprintf(stderr, "NOT_EOF, about to Queue more data for filled max_queue (%d)\n", | |
5623 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
5624 */ | |
5625 alSourceQueueBuffers( | |
5626 ALmixer_Channel_List[i].alsource, | |
5627 1, &unqueued_buffer_id); | |
5628 if((error = alGetError()) != AL_NO_ERROR) | |
5629 { | |
5630 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
|
5631 alGetString(error) ); |
0 | 5632 error_flag--; |
5633 continue; | |
5634 } | |
5635 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5636 * which buffer to show during callbacks (for things like | |
5637 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5638 * data structure. This code will be called only if | |
5639 * "access_data" was set, indicated by whether the queue is NULL. | |
5640 */ | |
5641 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5642 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5643 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5644 // fprintf(stderr, "56e: CircularQueue_PushBack.\n"); |
0 | 5645 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5646 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5647 unqueued_buffer_id | |
5648 ); | |
5649 if(0 == queue_ret_flag) | |
5650 { | |
5651 fprintf(stderr, "56bSerious internal error: CircularQueue could not push into queue.\n"); | |
5652 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5653 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5654 #if 0 |
0 | 5655 else |
5656 { | |
5657 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5658 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5659 #endif |
0 | 5660 } |
5661 } | |
5662 /* If we used an available buffer queue, | |
5663 * then we need to update the number of them in use | |
5664 */ | |
5665 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5666 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5667 { | |
5668 /* Increment the number of buffers in use */ | |
5669 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use++; | |
5670 } | |
5671 /* Might want to check state */ | |
5672 /* In case the playback stopped, | |
5673 * we need to resume */ | |
1 | 5674 #if 1 |
5675 /* Try not refetching the state here because I'm getting a duplicate | |
5676 buffer playback (hiccup) */ | |
0 | 5677 alGetSourcei( |
5678 ALmixer_Channel_List[i].alsource, | |
5679 AL_SOURCE_STATE, &state | |
5680 ); | |
1 | 5681 if((error = alGetError()) != AL_NO_ERROR) |
5682 { | |
5683 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
|
5684 alGetString(error)); |
1 | 5685 } |
5686 /* Get the number of buffers processed | |
5687 */ | |
5688 alGetSourcei( | |
5689 ALmixer_Channel_List[i].alsource, | |
5690 AL_BUFFERS_PROCESSED, | |
5691 &buffers_processed | |
5692 ); | |
5693 if((error = alGetError()) != AL_NO_ERROR) | |
5694 { | |
5695 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
|
5696 alGetString(error)); |
1 | 5697 } |
5698 #endif | |
0 | 5699 if(AL_STOPPED == state) |
5700 { | |
1 | 5701 /* |
0 | 5702 fprintf(stderr, "Resuming in not eof\n"); |
1 | 5703 */ |
5704 /* Okay, here's another lately discovered problem: | |
5705 * I can't find it in the spec, but for at least some of the | |
5706 * implementations, if I call play on a stopped source that | |
5707 * has processed buffers, all those buffers get marked as unprocessed | |
5708 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5709 * processed, on resume, the earlier 24 buffers will get replayed, | |
5710 * causing a "hiccup" like sound in the playback. | |
5711 * To avoid this, I must unqueue all processed buffers before | |
5712 * calling play. But to complicate things, I need to worry about resyncing | |
5713 * the circular queue with this since I designed this thing | |
5714 * with some correlation between the two. However, I might | |
5715 * have already handled this, so I will try writing this code without | |
5716 * syncing for now. | |
5717 * There is currently an assumption that a buffer | |
5718 * was queued above so I actually have something | |
5719 * to play. | |
5720 */ | |
5721 ALint temp_count; | |
5722 /* | |
5723 fprintf(stderr, "STOPPED2, need to clear processed, status is:\n"); | |
5724 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5725 */ | |
5726 | |
5727 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5728 { | |
5729 alSourceUnqueueBuffers( | |
5730 ALmixer_Channel_List[i].alsource, | |
5731 1, &unqueued_buffer_id | |
5732 ); | |
5733 if((error = alGetError()) != AL_NO_ERROR) | |
5734 { | |
5735 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
|
5736 alGetString(error)); |
1 | 5737 error_flag--; |
5738 } | |
5739 } | |
5740 /* | |
5741 fprintf(stderr, "After unqueue clear...:\n"); | |
5742 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5743 */ | |
5744 | |
5745 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5746 if((error = alGetError()) != AL_NO_ERROR) | |
5747 { | |
5748 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
|
5749 alGetString(error)); |
1 | 5750 } |
0 | 5751 } |
5752 continue; | |
5753 } /* END if( ! eof) */ | |
5754 /* We have hit EOF in the SDL_Sound sample and there | |
5755 * are no more loops. However, there may still be | |
5756 * buffers in the OpenAL queue which still need to | |
5757 * be played out. The following body of code will | |
5758 * determine if play is still happening or | |
5759 * initiate the stop/cleanup sequenece. | |
5760 */ | |
5761 else | |
5762 { | |
5763 /* Let's continue to remove the used up | |
5764 * buffers as they come in. */ | |
5765 if(buffers_processed > 0) | |
5766 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5767 ALint temp_count; |
0 | 5768 /* Do as a for-loop because I don't want |
5769 * to have to create an array for the | |
5770 * unqueued_buffer_id's | |
5771 */ | |
5772 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5773 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5774 /* |
0 | 5775 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
|
5776 */ |
0 | 5777 alSourceUnqueueBuffers( |
5778 ALmixer_Channel_List[i].alsource, | |
5779 1, &unqueued_buffer_id | |
5780 ); | |
5781 if((error = alGetError()) != AL_NO_ERROR) | |
5782 { | |
5783 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
|
5784 alGetString(error)); |
0 | 5785 } |
5786 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5787 /* |
0 | 5788 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
|
5789 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5790 |
0 | 5791 /* Need to update counts since we removed everything. |
5792 * If we don't update the counts here, we end up in the | |
5793 * "Shouldn't be here section, but maybe it's okay due to race conditions" | |
5794 */ | |
5795 alGetSourcei( | |
5796 ALmixer_Channel_List[i].alsource, | |
5797 AL_BUFFERS_QUEUED, &buffers_still_queued | |
5798 ); | |
5799 if((error = alGetError()) != AL_NO_ERROR) | |
5800 { | |
5801 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
|
5802 alGetString(error)); |
0 | 5803 } |
5804 /* Get the number of buffers processed | |
5805 * so we know if we need to refill | |
5806 */ | |
5807 alGetSourcei( | |
5808 ALmixer_Channel_List[i].alsource, | |
5809 AL_BUFFERS_PROCESSED, &buffers_processed | |
5810 ); | |
5811 if((error = alGetError()) != AL_NO_ERROR) | |
5812 { | |
5813 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
|
5814 alGetString(error)); |
0 | 5815 } |
5816 } | |
5817 | |
5818 | |
5819 /* Else if buffers_processed == 0 | |
5820 * and buffers_still_queued == 0. | |
5821 * then we check to see if the source | |
5822 * is still playing. Quit if stopped | |
5823 * We shouldn't need to worry about | |
5824 * looping because that should have | |
5825 * been handled above. | |
5826 */ | |
5827 if(0 == buffers_still_queued) | |
5828 { | |
5829 /* Make sure playback has stopped before | |
5830 * we shutdown. | |
5831 */ | |
5832 alGetSourcei( | |
5833 ALmixer_Channel_List[i].alsource, | |
5834 AL_SOURCE_STATE, &state | |
5835 ); | |
5836 if((error = alGetError()) != AL_NO_ERROR) | |
5837 { | |
5838 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
|
5839 alGetString(error)); |
0 | 5840 } |
5841 if(AL_STOPPED == state) | |
5842 { | |
5843 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use = 0; | |
5844 /* Playback has ended. | |
5845 * Loop if necessary, or launch callback | |
5846 * and clear channel (or clear channel and | |
5847 * 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
|
5848 * Update: Need to do callback first because I reference the mixer_data and source |
0 | 5849 */ |
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
|
5850 |
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
|
5851 /* 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
|
5852 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
|
5853 |
0 | 5854 Clean_Channel(i); |
5855 /* Subtract counter */ | |
5856 Is_Playing_global--; | |
5857 | |
5858 | |
5859 /* We're done for this loop. | |
5860 * Go to next channel | |
5861 */ | |
5862 continue; | |
5863 } | |
5864 } /* End end-playback */ | |
5865 else | |
5866 { | |
5867 /* Need to run out buffer */ | |
5868 #if 1 | |
5869 /* Might want to check state */ | |
5870 /* In case the playback stopped, | |
5871 * we need to resume */ | |
5872 alGetSourcei( | |
5873 ALmixer_Channel_List[i].alsource, | |
5874 AL_SOURCE_STATE, &state | |
5875 ); | |
5876 if((error = alGetError()) != AL_NO_ERROR) | |
5877 { | |
5878 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
|
5879 alGetString(error)); |
0 | 5880 } |
5881 if(AL_STOPPED == state) | |
5882 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5883 /* |
0 | 5884 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
|
5885 */ |
1 | 5886 /* |
0 | 5887 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 5888 */ |
0 | 5889 /* Rather than force unqueuing the buffer, let's see if |
5890 * setting the buffer to none works (the OpenAL 1.0 | |
5891 * Reference Annotation suggests this should work). | |
5892 */ | |
5893 alSourcei(ALmixer_Channel_List[i].alsource, | |
5894 AL_BUFFER, AL_NONE); | |
5895 /* | |
5896 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5897 */ | |
5898 /* This doesn't work because in some cases, I think | |
5899 * it causes the sound to be replayed | |
5900 */ | |
5901 /* | |
5902 fprintf(stderr, "Resuming in eof (trying to run out buffers\n"); | |
5903 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5904 */ | |
5905 } | |
5906 #endif | |
5907 } /* End trap section */ | |
5908 } /* End POST-EOF use-up buffer section */ | |
5909 } /* END Streamed section */ | |
5910 } /* END channel in use */ | |
5911 } /* END for-loop for each channel */ | |
5912 | |
5913 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
5914 alcProcessContext(alcGetCurrentContext()); | |
5915 if((error = alGetError()) != AL_NO_ERROR) | |
5916 { | |
5917 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
|
5918 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5919 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5920 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5921 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5922 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5923 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5924 #endif |
0 | 5925 /* Return the number of errors */ |
5926 if(error_flag < 0) | |
5927 { | |
5928 return error_flag; | |
5929 } | |
5930 /* Return the number of buffers that were queued */ | |
5931 return retval; | |
5932 } | |
5933 | |
5934 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
5935 /* 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
|
5936 static void my_dummy_audio_callback(void* userdata, ALbyte* stream, int len) |
0 | 5937 { |
5938 } | |
5939 #endif | |
5940 | |
5941 | |
5942 | |
5943 | |
5944 #ifdef ENABLE_ALMIXER_THREADS | |
5945 /* We might need threads. We | |
5946 * must constantly poll OpenAL to find out | |
5947 * if sound is being streamed, if play has | |
5948 * ended, etc. Without threads, this must | |
5949 * be explicitly done by the user. | |
5950 * We could try to do it for them if we | |
5951 * finish the threads. | |
5952 */ | |
5953 | |
5954 static int Stream_Data_Thread_Callback(void* data) | |
5955 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5956 ALint retval; |
0 | 5957 |
5958 while(ALmixer_Initialized) | |
5959 { | |
5960 retval = Update_ALmixer(data); | |
5961 /* 0 means that nothing needed updating and | |
5962 * the function returned quickly | |
5963 */ | |
5964 if(0 == retval) | |
5965 { | |
5966 /* Let's be nice and make the thread sleep since | |
5967 * little work was done in update | |
5968 */ | |
5969 /* Make sure times are multiples of 10 | |
5970 * for optimal performance and accuracy in Linux | |
5971 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5972 ALmixer_Delay(10); |
0 | 5973 } |
5974 else | |
5975 { | |
5976 /* 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
|
5977 ALmixer_Delay(0); |
0 | 5978 } |
5979 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5980 /* |
0 | 5981 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
|
5982 */ |
0 | 5983 return 0; |
5984 } | |
5985 #endif /* End of ENABLE_ALMIXER_THREADS */ | |
5986 | |
5987 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5988 /* 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
|
5989 * 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
|
5990 * so SDL_mixer porting people beware. |
0 | 5991 * Warning: SDL_QuitSubSystem(SDL_INIT_AUDIO) is called which |
5992 * means the SDL audio system will be disabled. It will not | |
5993 * be restored (in case SDL is not actually being used) so | |
5994 * the user will need to restart it if they need it after | |
5995 * OpenAL shuts down. | |
5996 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5997 ALboolean ALmixer_Init(ALuint frequency, ALint num_sources, ALuint refresh) |
0 | 5998 { |
5999 ALCdevice* dev; | |
6000 ALCcontext* context; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6001 ALint i; |
0 | 6002 ALenum error; |
6003 ALuint* source; | |
6004 | |
6005 #ifdef USING_LOKI_AL_DIST | |
6006 /* The Loki dist requires that I set both the | |
6007 * device and context frequency values separately | |
6008 */ | |
6009 /* Hope this won't overflow */ | |
6010 char device_string[256]; | |
6011 #endif | |
6012 | |
6013 /* (Venting frustration) Damn it! Nobody bothered | |
6014 * documenting how you're supposed to use an attribute | |
6015 * list. In fact, the not even the Loki test program | |
6016 * writers seem to know because they use it inconsistently. | |
6017 * For example, how do you terminate that attribute list? | |
6018 * The Loki test code does it 3 different ways. They | |
6019 * set the last value to 0, or they set it to ALC_INVALID, | |
6020 * or they set two final values: ALC_INVALID, 0 | |
6021 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6022 * but with Creative Labs ALC_INVALID is -1. | |
6023 * So something's going to break. Loki's source | |
6024 * code says to terminate with ALC_INVALID. But I | |
6025 * don't know if that's really true, or it happens | |
6026 * to be a coinicidence because it's defined to 0. | |
6027 * Creative provides no source code, so I can't look at how | |
6028 * they terminate it. | |
6029 * So this is really, really ticking me off... | |
6030 * For now, I'm going to use ALC_INVALID. | |
6031 * (Update...after further review of the API spec, | |
6032 * it seems that a NULL terminated string is the correct | |
6033 * termination value to use, so 0 it is.) | |
6034 */ | |
6035 #if 0 | |
6036 ALint attrlist[] = { | |
6037 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6038 /* Don't know anything about these values. | |
6039 * Trust defaults? */ | |
6040 /* Supposed to be the refresh rate in Hz. | |
6041 * I think 15-120 are supposed to be good | |
6042 * values. Though I haven't gotten any effect except | |
6043 * for one strange instance on a Mac. But it was | |
6044 * unrepeatable. | |
6045 */ | |
6046 #if 0 | |
6047 ALC_REFRESH, 15, | |
6048 #endif | |
6049 /* Sync requires a alcProcessContext() call | |
6050 * for every cycle. By default, this is | |
6051 * not used and the value is AL_FALSE | |
6052 * because it will probably perform | |
6053 * pretty badly for me. | |
6054 */ | |
6055 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6056 ALC_SYNC, AL_TRUE, | |
6057 #else | |
6058 ALC_SYNC, AL_FALSE, | |
6059 #endif | |
6060 /* Looking at the API spec, it implies | |
6061 * that the list be a NULL terminated string | |
6062 * so it's probably not safe to use ALC_INVALID | |
6063 */ | |
6064 /* | |
6065 ALC_INVALID }; | |
6066 */ | |
6067 '\0'}; | |
6068 #endif | |
6069 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6070 * However, if no value is specified, I don't | |
6071 * want it in the list so I can get the OpenAL defaults | |
6072 */ | |
6073 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6074 ALsizei current_attrlist_index = 0; |
0 | 6075 |
6076 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6077 /* More problems: I'm getting bit by endian/signedness issues on | |
6078 * different platforms. I can find the endianess easily enough, | |
6079 * but I don't know how to determine what the correct signedness | |
6080 * is (if such a thing exists). I do know that if I try using | |
6081 * unsigned on OSX with an originally signed sample, I get | |
6082 * distortion. However, I don't have any native unsigned samples | |
6083 * to test. But I'm assuming that the platform must be in the | |
6084 * correct signedness no matter what. | |
6085 * I can either assume everybody is signed, or I can try to | |
6086 * determine the value. If I try to determine the values, | |
6087 * I think my only ability to figure it out will be to open | |
6088 * SDL_Audio, and read what the obtained settings were. | |
6089 * Then shutdown everything. However, I don't even know how | |
6090 * reliable this is. | |
6091 * Update: I think I resolved the issues...forgot to update | |
6092 * these comments when it happened. I should check the revision control | |
6093 * log... Anyway, I think the issue was partly related to me not | |
6094 * doing something correctly with the AudioInfo or some kind | |
6095 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6096 * revision control, I think I might have assumed that SDL_Sound would | |
6097 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6098 * and had to fill one out myself. | |
6099 */ | |
6100 SDL_AudioSpec desired; | |
6101 SDL_AudioSpec obtained; | |
6102 #endif | |
6103 | |
6104 | |
6105 /* Make sure ALmixer isn't already initialized */ | |
6106 if(ALmixer_Initialized) | |
6107 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6108 return AL_FALSE; |
0 | 6109 } |
6110 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6111 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6112 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6113 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6114 /* 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
|
6115 /* 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
|
6116 * 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
|
6117 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6118 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6119 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6120 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6121 s_ALmixerErrorPool = TError_CreateErrorPool(); |
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 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6124 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6125 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6126 } |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6127 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6128 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6129 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6130 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
|
6131 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
|
6132 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6133 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6134 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6135 |
0 | 6136 /* Set the defaults */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6137 /* |
0 | 6138 attrlist[0] = ALC_FREQUENCY; |
6139 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6140 attrlist[2] = ALC_SYNC; | |
6141 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6142 attrlist[3] = ALC_TRUE; | |
6143 #else | |
6144 attrlist[3] = ALC_FALSE; | |
6145 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6146 */ |
0 | 6147 /* Set frequency value if it is not 0 */ |
6148 if(0 != frequency) | |
6149 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6150 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6151 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6152 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6153 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6154 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6155 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6156 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6157 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6158 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6159 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6160 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6161 #endif |
0 | 6162 |
6163 /* If the user specifies a refresh value, | |
6164 * make room for it | |
6165 */ | |
6166 if(0 != refresh) | |
6167 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6168 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
|
6169 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6170 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6171 current_attrlist_index++; |
0 | 6172 } |
6173 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6174 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6175 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6176 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6177 |
0 | 6178 /* Initialize SDL_Sound */ |
6179 if(! Sound_Init() ) | |
6180 { | |
6181 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6182 return AL_FALSE; |
0 | 6183 } |
6184 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6185 /* Here is the paranoid check that opens | |
6186 * SDL audio in an attempt to find the correct | |
6187 * system values. | |
6188 */ | |
6189 /* Doesn't have to be the actual value I think | |
6190 * (as long as it doesn't influence format, in | |
6191 * which case I'm probably screwed anyway because OpenAL | |
6192 * may easily choose to do something else). | |
6193 */ | |
6194 desired.freq = 44100; | |
6195 desired.channels = 2; | |
6196 desired.format = AUDIO_S16SYS; | |
6197 desired.callback = my_dummy_audio_callback; | |
6198 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6199 { | |
6200 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6201 /* Now to get really paranoid, we should probably | |
6202 * also assume that the 8bit format is also the | |
6203 * same sign type and set that value | |
6204 */ | |
6205 if(AUDIO_S16SYS == obtained.format) | |
6206 { | |
6207 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6208 } | |
6209 /* Should be AUDIO_U16SYS */ | |
6210 else | |
6211 { | |
6212 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6213 } | |
6214 SDL_CloseAudio(); | |
6215 } | |
6216 else | |
6217 { | |
6218 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6219 */ | |
6220 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6221 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6222 } | |
6223 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6224 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6225 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6226 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
6227 * causes OpenAL and SMPEG to conflict. For some reason | |
6228 * if SDL_Init on audio is active, then all the SMPEG | |
6229 * decoded sound comes out silent. Unfortunately, | |
6230 * Sound_Init() invokes SDL_Init on audio. I'm | |
6231 * not sure why it actually needs it... | |
6232 * But we'll attempt to disable it here after the | |
6233 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
6234 */ | |
6235 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6236 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6237 |
0 | 6238 /* I'm told NULL will call the default string |
6239 * and hopefully do the right thing for each platform | |
6240 */ | |
6241 /* | |
6242 dev = alcOpenDevice( NULL ); | |
6243 */ | |
6244 /* Now I'm told I need to set both the device and context | |
6245 * to have the same sampling rate, so I must pass a string | |
6246 * to OpenDevice(). I don't know how portable these strings are. | |
6247 * I don't even know if the format for strings is | |
6248 * compatible | |
6249 * From the testattrib.c in the Loki test section | |
6250 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
6251 */ | |
6252 | |
6253 #ifdef USING_LOKI_AL_DIST | |
6254 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
6255 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
6256 #else | |
6257 dev = alcOpenDevice( NULL ); | |
6258 #endif | |
6259 if(NULL == dev) | |
6260 { | |
6261 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
|
6262 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6263 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6264 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6265 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6266 /* 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
|
6267 /* 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
|
6268 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6269 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6270 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6271 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6272 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
|
6273 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6274 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
|
6275 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6276 #endif |
0 | 6277 |
6278 context = alcCreateContext(dev, attrlist); | |
6279 if(NULL == context) | |
6280 { | |
6281 ALmixer_SetError("Cannot create a context OpenAL"); | |
6282 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6283 return AL_FALSE; |
0 | 6284 } |
6285 | |
6286 | |
6287 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6288 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6289 * According to Garin Hiebert, this is actually an inconsistency | |
6290 * in the Loki version. The function should return a boolean. | |
6291 * instead of ALC_NO_ERROR. Garin suggested I check via | |
6292 * alcGetError(). | |
6293 */ | |
6294 /* clear the error */ | |
6295 alcGetError(dev); | |
6296 alcMakeContextCurrent(context); | |
6297 | |
6298 error = alcGetError(dev); | |
6299 if( (ALC_NO_ERROR != error) ) | |
6300 { | |
6301 ALmixer_SetError("Could not MakeContextCurrent"); | |
6302 alcDestroyContext(context); | |
6303 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6304 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6305 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6306 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6307 /* 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
|
6308 * 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
|
6309 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6310 * 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
|
6311 * 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
|
6312 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6313 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6314 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6315 ALmixer_Frequency_global = frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6316 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6317 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6318 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
|
6319 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6320 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
|
6321 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6322 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6323 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6324 |
0 | 6325 #if 0 |
6326 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
6327 if(alcGetCurrentContext() != context) | |
6328 { | |
6329 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6330 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6331 * I think this is a bug in the OpenAL implementation. | |
6332 */ | |
6333 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
6334 | |
6335 fprintf(stderr, "Making context current\n"); | |
6336 #ifndef __APPLE__ | |
6337 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
6338 #else | |
6339 if(!alcMakeContextCurrent(context)) | |
6340 #endif | |
6341 { | |
6342 ALmixer_SetError("Could not MakeContextCurrent"); | |
6343 alcDestroyContext(context); | |
6344 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6345 return AL_FALSE; |
0 | 6346 } |
6347 } | |
6348 #endif | |
6349 | |
6350 | |
6351 /* #endif */ | |
6352 /* Saw this in the README with the OS X OpenAL distribution. | |
6353 * It looked interesting and simple, so I thought I might | |
6354 * try it out. | |
6355 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
6356 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
6357 * Audio format, the audio data passed to the | |
6358 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
6359 * usage by removing an audio data conversion | |
6360 * (per source) at render timem at the expense of a larger memory footprint. | |
6361 * | |
6362 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
6363 * setting will be applied to all subsequent | |
6364 * calls to alBufferData(). | |
6365 */ | |
6366 #ifdef __APPLE__ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6367 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6368 #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
|
6369 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6370 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6371 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6372 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6373 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
|
6374 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6375 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
|
6376 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6377 if(0 != convert_data_enum) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6378 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6379 alEnable(convert_data_enum); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6380 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6381 if( (AL_NO_ERROR != alGetError()) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6382 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6383 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
|
6384 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
|
6385 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6386 |
0 | 6387 #endif |
6388 | |
6389 | |
6390 | |
6391 | |
6392 ALmixer_Initialized = 1; | |
6393 | |
6394 if(num_sources <= 0) | |
6395 { | |
6396 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
6397 } | |
6398 else | |
6399 { | |
6400 Number_of_Channels_global = num_sources; | |
6401 } | |
6402 Number_of_Reserve_Channels_global = 0; | |
6403 Is_Playing_global = 0; | |
6404 /* Set to Null in case system quit and was reinitialized */ | |
6405 Channel_Done_Callback = NULL; | |
6406 Channel_Done_Callback_Userdata = NULL; | |
6407 Channel_Data_Callback = NULL; | |
1 | 6408 Channel_Data_Callback_Userdata = NULL; |
0 | 6409 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6410 /* Allocate memory for linked list of ALmixerData. */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6411 s_listOfALmixerData = LinkedList_Create(); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6412 if(NULL == s_listOfALmixerData) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6413 { |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6414 ALmixer_SetError("Couldn't create linked list"); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6415 alcDestroyContext(context); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6416 alcCloseDevice(dev); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6417 ALmixer_Initialized = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6418 Number_of_Channels_global = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6419 return AL_FALSE; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6420 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6421 |
0 | 6422 /* Allocate memory for the list of channels */ |
6423 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
6424 if(NULL == ALmixer_Channel_List) | |
6425 { | |
6426 ALmixer_SetError("Out of Memory for Channel List"); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6427 LinkedList_Free(s_listOfALmixerData); |
0 | 6428 alcDestroyContext(context); |
6429 alcCloseDevice(dev); | |
6430 ALmixer_Initialized = 0; | |
6431 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6432 return AL_FALSE; |
0 | 6433 } |
6434 | |
6435 /* Allocate memory for the list of sources that map to the channels */ | |
6436 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
6437 if(NULL == Source_Map_List) | |
6438 { | |
6439 ALmixer_SetError("Out of Memory for Source Map List"); | |
6440 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6441 LinkedList_Free(s_listOfALmixerData); |
0 | 6442 alcDestroyContext(context); |
6443 alcCloseDevice(dev); | |
6444 ALmixer_Initialized = 0; | |
6445 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6446 return AL_FALSE; |
0 | 6447 } |
6448 | |
6449 /* Create array that will hold the sources */ | |
6450 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
6451 if(NULL == source) | |
6452 { | |
6453 ALmixer_SetError("Out of Memory for sources"); | |
6454 free(Source_Map_List); | |
6455 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6456 LinkedList_Free(s_listOfALmixerData); |
0 | 6457 alcDestroyContext(context); |
6458 alcCloseDevice(dev); | |
6459 ALmixer_Initialized = 0; | |
6460 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6461 return AL_FALSE; |
0 | 6462 } |
6463 | |
6464 /* Clear the error state */ | |
6465 alGetError(); | |
6466 /* Generate the OpenAL sources */ | |
6467 alGenSources(Number_of_Channels_global, source); | |
6468 if( (error=alGetError()) != AL_NO_ERROR) | |
6469 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6470 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 6471 free(ALmixer_Channel_List); |
6472 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6473 LinkedList_Free(s_listOfALmixerData); |
0 | 6474 alcDestroyContext(context); |
6475 alcCloseDevice(dev); | |
6476 ALmixer_Initialized = 0; | |
6477 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6478 return AL_FALSE; |
0 | 6479 } |
6480 | |
6481 /* Initialize each channel and associate one source to one channel */ | |
6482 for(i=0; i<Number_of_Channels_global; i++) | |
6483 { | |
6484 if(0 == source[i]) | |
6485 { | |
6486 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"); | |
6487 } | |
6488 | |
6489 Init_Channel(i); | |
6490 /* Keeping the source allocation out of the Init function | |
6491 * in case I want to reuse the Init | |
6492 * function for resetting data | |
6493 */ | |
6494 ALmixer_Channel_List[i].alsource = source[i]; | |
6495 /* Now also keep a copy of the source to channel mapping | |
6496 * in case we need to look up a channel from the source | |
6497 * instead of a source from a channel | |
6498 */ | |
6499 Source_Map_List[i].source = source[i]; | |
6500 Source_Map_List[i].channel = i; | |
6501 /* Clean the channel because there are some things that need to | |
6502 * be done that can't happen until the source is set | |
6503 */ | |
6504 Clean_Channel(i); | |
6505 } | |
6506 | |
6507 /* The Source_Map_List must be sorted by source for binary searches | |
6508 */ | |
6509 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
6510 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6511 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6512 ALmixer_OutputDecoders(); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6513 */ |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6514 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6515 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6516 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6517 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6518 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6519 if(NULL == s_simpleLock) |
0 | 6520 { |
6521 /* SDL sets the error message already? */ | |
6522 free(source); | |
6523 free(ALmixer_Channel_List); | |
6524 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6525 LinkedList_Free(s_listOfALmixerData); |
0 | 6526 alcDestroyContext(context); |
6527 alcCloseDevice(dev); | |
6528 ALmixer_Initialized = 0; | |
6529 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6530 return AL_FALSE; |
0 | 6531 } |
6532 | |
6533 | |
6534 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
6535 if(NULL == Stream_Thread_global) | |
6536 { | |
6537 /* 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
|
6538 SDL_DestroyMutex(s_simpleLock); |
0 | 6539 free(source); |
6540 free(ALmixer_Channel_List); | |
6541 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6542 LinkedList_Free(s_listOfALmixerData); |
0 | 6543 alcDestroyContext(context); |
6544 alcCloseDevice(dev); | |
6545 ALmixer_Initialized = 0; | |
6546 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6547 return AL_FALSE; |
0 | 6548 } |
6549 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6550 /* |
0 | 6551 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6552 */ |
0 | 6553 #endif /* End of ENABLE_ALMIXER_THREADS */ |
6554 | |
6555 /* We don't need this array any more because all the sources | |
6556 * are connected to channels | |
6557 */ | |
6558 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6559 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6560 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6561 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6562 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6563 ALboolean ALmixer_InitContext(ALuint frequency, ALuint refresh) |
0 | 6564 { |
6565 ALCdevice* dev; | |
6566 ALCcontext* context; | |
6567 ALCenum error; | |
6568 | |
6569 #ifdef USING_LOKI_AL_DIST | |
6570 /* The Loki dist requires that I set both the | |
6571 * device and context frequency values separately | |
6572 */ | |
6573 /* Hope this won't overflow */ | |
6574 char device_string[256]; | |
6575 #endif | |
6576 | |
6577 /* (Venting frustration) Damn it! Nobody bothered | |
6578 * documenting how you're supposed to use an attribute | |
6579 * list. In fact, the not even the Loki test program | |
6580 * writers seem to know because they use it inconsistently. | |
6581 * For example, how do you terminate that attribute list? | |
6582 * The Loki test code does it 3 different ways. They | |
6583 * set the last value to 0, or they set it to ALC_INVALID, | |
6584 * or they set two final values: ALC_INVALID, 0 | |
6585 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6586 * but with Creative Labs ALC_INVALID is -1. | |
6587 * So something's going to break. Loki's source | |
6588 * code says to terminate with ALC_INVALID. But I | |
6589 * don't know if that's really true, or it happens | |
6590 * to be a coinicidence because it's defined to 0. | |
6591 * Creative provides no source code, so I can't look at how | |
6592 * they terminate it. | |
6593 * So this is really, really ticking me off... | |
6594 * For now, I'm going to use ALC_INVALID. | |
6595 * (Update...after further review of the API spec, | |
6596 * it seems that a NULL terminated string is the correct | |
6597 * termination value to use, so 0 it is.) | |
6598 */ | |
6599 #if 0 | |
6600 ALint attrlist[] = { | |
6601 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6602 /* Don't know anything about these values. | |
6603 * Trust defaults? */ | |
6604 /* Supposed to be the refresh rate in Hz. | |
6605 * I think 15-120 are supposed to be good | |
6606 * values. Though I haven't gotten any effect except | |
6607 * for one strange instance on a Mac. But it was | |
6608 * unrepeatable. | |
6609 */ | |
6610 #if 0 | |
6611 ALC_REFRESH, 15, | |
6612 #endif | |
6613 /* Sync requires a alcProcessContext() call | |
6614 * for every cycle. By default, this is | |
6615 * not used and the value is AL_FALSE | |
6616 * because it will probably perform | |
6617 * pretty badly for me. | |
6618 */ | |
6619 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6620 ALC_SYNC, AL_TRUE, | |
6621 #else | |
6622 ALC_SYNC, AL_FALSE, | |
6623 #endif | |
6624 /* Looking at the API spec, it implies | |
6625 * that the list be a NULL terminated string | |
6626 * so it's probably not safe to use ALC_INVALID | |
6627 */ | |
6628 /* | |
6629 ALC_INVALID }; | |
6630 */ | |
6631 '\0'}; | |
6632 #endif | |
6633 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6634 * However, if no value is specified, I don't | |
6635 * want it in the list so I can get the OpenAL defaults | |
6636 */ | |
6637 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6638 ALsizei current_attrlist_index = 0; |
0 | 6639 |
6640 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6641 /* More problems: I'm getting bit by endian/signedness issues on | |
6642 * different platforms. I can find the endianess easily enough, | |
6643 * but I don't know how to determine what the correct signedness | |
6644 * is (if such a thing exists). I do know that if I try using | |
6645 * unsigned on OSX with an originally signed sample, I get | |
6646 * distortion. However, I don't have any native unsigned samples | |
6647 * to test. But I'm assuming that the platform must be in the | |
6648 * correct signedness no matter what. | |
6649 * I can either assume everybody is signed, or I can try to | |
6650 * determine the value. If I try to determine the values, | |
6651 * I think my only ability to figure it out will be to open | |
6652 * SDL_Audio, and read what the obtained settings were. | |
6653 * Then shutdown everything. However, I don't even know how | |
6654 * reliable this is. | |
6655 * Update: I think I resolved the issues...forgot to update | |
6656 * these comments when it happened. I should check the revision control | |
6657 * log... Anyway, I think the issue was partly related to me not | |
6658 * doing something correctly with the AudioInfo or some kind | |
6659 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6660 * revision control, I think I might have assumed that SDL_Sound would | |
6661 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6662 * and had to fill one out myself. | |
6663 */ | |
6664 SDL_AudioSpec desired; | |
6665 SDL_AudioSpec obtained; | |
6666 #endif | |
6667 | |
6668 | |
6669 | |
6670 | |
6671 /* Make sure ALmixer isn't already initialized */ | |
6672 if(ALmixer_Initialized) | |
6673 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6674 return AL_FALSE; |
0 | 6675 } |
6676 | |
6677 /* Set the defaults */ | |
6678 attrlist[0] = ALC_FREQUENCY; | |
6679 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6680 attrlist[2] = ALC_SYNC; | |
6681 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6682 attrlist[3] = ALC_TRUE; | |
6683 #else | |
6684 attrlist[3] = ALC_FALSE; | |
6685 #endif | |
6686 /* Set frequency value if it is not 0 */ | |
6687 if(0 != frequency) | |
6688 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6689 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6690 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6691 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6692 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6693 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6694 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6695 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6696 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6697 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6698 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6699 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6700 #endif |
0 | 6701 |
6702 /* If the user specifies a refresh value, | |
6703 * make room for it | |
6704 */ | |
6705 if(0 != refresh) | |
6706 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6707 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
|
6708 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6709 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6710 current_attrlist_index++; |
0 | 6711 } |
6712 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6713 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6714 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6715 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6716 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6717 |
0 | 6718 /* Initialize SDL_Sound */ |
6719 if(! Sound_Init() ) | |
6720 { | |
6721 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6722 return AL_FALSE; |
0 | 6723 } |
6724 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6725 /* Here is the paranoid check that opens | |
6726 * SDL audio in an attempt to find the correct | |
6727 * system values. | |
6728 */ | |
6729 /* Doesn't have to be the actual value I think | |
6730 * (as long as it doesn't influence format, in | |
6731 * which case I'm probably screwed anyway because OpenAL | |
6732 * may easily choose to do something else). | |
6733 */ | |
6734 desired.freq = 44100; | |
6735 desired.channels = 2; | |
6736 desired.format = AUDIO_S16SYS; | |
6737 desired.callback = my_dummy_audio_callback; | |
6738 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6739 { | |
6740 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6741 /* Now to get really paranoid, we should probably | |
6742 * also assume that the 8bit format is also the | |
6743 * same sign type and set that value | |
6744 */ | |
6745 if(AUDIO_S16SYS == obtained.format) | |
6746 { | |
6747 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6748 } | |
6749 /* Should be AUDIO_U16SYS */ | |
6750 else | |
6751 { | |
6752 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6753 } | |
6754 SDL_CloseAudio(); | |
6755 } | |
6756 else | |
6757 { | |
6758 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6759 */ | |
6760 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6761 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6762 } | |
6763 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6764 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6765 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6766 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
6767 * causes OpenAL and SMPEG to conflict. For some reason | |
6768 * if SDL_Init on audio is active, then all the SMPEG | |
6769 * decoded sound comes out silent. Unfortunately, | |
6770 * Sound_Init() invokes SDL_Init on audio. I'm | |
6771 * not sure why it actually needs it... | |
6772 * But we'll attempt to disable it here after the | |
6773 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
6774 */ | |
6775 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6776 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6777 |
0 | 6778 /* I'm told NULL will call the default string |
6779 * and hopefully do the right thing for each platform | |
6780 */ | |
6781 /* | |
6782 dev = alcOpenDevice( NULL ); | |
6783 */ | |
6784 /* Now I'm told I need to set both the device and context | |
6785 * to have the same sampling rate, so I must pass a string | |
6786 * to OpenDevice(). I don't know how portable these strings are. | |
6787 * I don't even know if the format for strings is | |
6788 * compatible | |
6789 * From the testattrib.c in the Loki test section | |
6790 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
6791 */ | |
6792 | |
6793 #ifdef USING_LOKI_AL_DIST | |
6794 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
6795 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
6796 #else | |
6797 dev = alcOpenDevice( NULL ); | |
6798 #endif | |
6799 if(NULL == dev) | |
6800 { | |
6801 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
|
6802 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6803 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6804 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6805 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6806 /* 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
|
6807 /* 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
|
6808 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6809 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6810 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6811 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6812 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
|
6813 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6814 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
|
6815 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6816 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6817 |
0 | 6818 |
6819 context = alcCreateContext(dev, attrlist); | |
6820 if(NULL == context) | |
6821 { | |
6822 ALmixer_SetError("Cannot create a context OpenAL"); | |
6823 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6824 return AL_FALSE; |
0 | 6825 } |
6826 | |
6827 | |
6828 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6829 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6830 * According to Garin Hiebert, this is actually an inconsistency | |
6831 * in the Loki version. The function should return a boolean. | |
6832 * instead of ALC_NO_ERROR. Garin suggested I check via | |
6833 * alcGetError(). | |
6834 */ | |
6835 /* clear the error */ | |
6836 alcGetError(dev); | |
6837 alcMakeContextCurrent(context); | |
6838 | |
6839 error = alcGetError(dev); | |
6840 if( (ALC_NO_ERROR != error) ) | |
6841 { | |
6842 ALmixer_SetError("Could not MakeContextCurrent"); | |
6843 alcDestroyContext(context); | |
6844 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6845 return AL_FALSE; |
0 | 6846 } |
6847 | |
6848 | |
6849 #if 0 | |
6850 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
6851 if(alcGetCurrentContext() != context) | |
6852 { | |
6853 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6854 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6855 * I think this is a bug in the OpenAL implementation. | |
6856 */ | |
6857 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
6858 | |
6859 fprintf(stderr, "Making context current\n"); | |
6860 #ifndef __APPLE__ | |
6861 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
6862 #else | |
6863 if(!alcMakeContextCurrent(context)) | |
6864 #endif | |
6865 { | |
6866 ALmixer_SetError("Could not MakeContextCurrent"); | |
6867 alcDestroyContext(context); | |
6868 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6869 return AL_FALSE; |
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 |
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 #endif |
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 /* 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
|
6876 * 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
|
6877 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6878 * 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
|
6879 * 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
|
6880 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6881 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6882 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6883 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
|
6884 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6885 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
|
6886 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6887 #endif |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6888 |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6889 |
0 | 6890 |
6891 /* Saw this in the README with the OS X OpenAL distribution. | |
6892 * It looked interesting and simple, so I thought I might | |
6893 * try it out. | |
6894 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
6895 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
6896 * Audio format, the audio data passed to the | |
6897 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
6898 * usage by removing an audio data conversion | |
6899 * (per source) at render timem at the expense of a larger memory footprint. | |
6900 * | |
6901 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
6902 * setting will be applied to all subsequent | |
6903 * calls to alBufferData(). | |
6904 */ | |
6905 #ifdef __APPLE__ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6906 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6907 #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
|
6908 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6909 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6910 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6911 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6912 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
|
6913 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6914 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
|
6915 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6916 if(0 != convert_data_enum) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6917 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6918 alEnable(convert_data_enum); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6919 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6920 if( (AL_NO_ERROR != alGetError()) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6921 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6922 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
|
6923 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
|
6924 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6925 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6926 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6927 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6928 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6929 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6930 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6931 ALboolean ALmixer_InitMixer(ALint num_sources) |
0 | 6932 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6933 ALint i; |
0 | 6934 ALenum error; |
6935 ALuint* source; | |
6936 | |
6937 | |
6938 ALmixer_Initialized = 1; | |
6939 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6940 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6941 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6942 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6943 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6944 /* 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
|
6945 /* 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
|
6946 * 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
|
6947 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6948 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6949 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6950 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6951 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6952 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6953 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6954 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6955 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6956 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6957 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6958 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6959 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6960 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
|
6961 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
|
6962 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6963 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6964 |
0 | 6965 if(num_sources <= 0) |
6966 { | |
6967 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
6968 } | |
6969 else | |
6970 { | |
6971 Number_of_Channels_global = num_sources; | |
6972 } | |
6973 Number_of_Reserve_Channels_global = 0; | |
6974 Is_Playing_global = 0; | |
6975 /* Set to Null in case system quit and was reinitialized */ | |
6976 Channel_Done_Callback = NULL; | |
6977 Channel_Done_Callback_Userdata = NULL; | |
6978 Channel_Data_Callback = NULL; | |
1 | 6979 Channel_Data_Callback_Userdata = NULL; |
0 | 6980 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6981 /* Allocate memory for linked list of ALmixerData. */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6982 s_listOfALmixerData = LinkedList_Create(); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6983 if(NULL == s_listOfALmixerData) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6984 { |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6985 ALmixer_SetError("Couldn't create linked list"); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6986 ALmixer_Initialized = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6987 Number_of_Channels_global = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6988 return AL_FALSE; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6989 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6990 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6991 |
0 | 6992 /* Allocate memory for the list of channels */ |
6993 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
6994 if(NULL == ALmixer_Channel_List) | |
6995 { | |
6996 ALmixer_SetError("Out of Memory for Channel List"); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6997 LinkedList_Free(s_listOfALmixerData); |
0 | 6998 ALmixer_Initialized = 0; |
6999 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7000 return AL_FALSE; |
0 | 7001 } |
7002 | |
7003 /* Allocate memory for the list of sources that map to the channels */ | |
7004 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
7005 if(NULL == Source_Map_List) | |
7006 { | |
7007 ALmixer_SetError("Out of Memory for Source Map List"); | |
7008 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7009 LinkedList_Free(s_listOfALmixerData); |
0 | 7010 ALmixer_Initialized = 0; |
7011 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7012 return AL_FALSE; |
0 | 7013 } |
7014 | |
7015 /* Create array that will hold the sources */ | |
7016 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
7017 if(NULL == source) | |
7018 { | |
7019 ALmixer_SetError("Out of Memory for sources"); | |
7020 free(Source_Map_List); | |
7021 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7022 LinkedList_Free(s_listOfALmixerData); |
0 | 7023 ALmixer_Initialized = 0; |
7024 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7025 return AL_FALSE; |
0 | 7026 } |
7027 | |
7028 /* Clear the error state */ | |
7029 alGetError(); | |
7030 /* Generate the OpenAL sources */ | |
7031 alGenSources(Number_of_Channels_global, source); | |
7032 if( (error=alGetError()) != AL_NO_ERROR) | |
7033 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7034 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 7035 free(ALmixer_Channel_List); |
7036 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7037 LinkedList_Free(s_listOfALmixerData); |
0 | 7038 ALmixer_Initialized = 0; |
7039 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7040 return AL_FALSE; |
0 | 7041 } |
7042 | |
7043 /* Initialize each channel and associate one source to one channel */ | |
7044 for(i=0; i<Number_of_Channels_global; i++) | |
7045 { | |
7046 Init_Channel(i); | |
7047 /* Keeping the source allocation out of the Init function | |
7048 * in case I want to reuse the Init | |
7049 * function for resetting data | |
7050 */ | |
7051 ALmixer_Channel_List[i].alsource = source[i]; | |
7052 /* Now also keep a copy of the source to channel mapping | |
7053 * in case we need to look up a channel from the source | |
7054 * instead of a source from a channel | |
7055 */ | |
7056 Source_Map_List[i].source = source[i]; | |
7057 Source_Map_List[i].channel = i; | |
7058 /* Clean the channel because there are some things that need to | |
7059 * be done that can't happen until the source is set | |
7060 */ | |
7061 Clean_Channel(i); | |
7062 } | |
7063 | |
7064 /* The Source_Map_List must be sorted by source for binary searches | |
7065 */ | |
7066 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
7067 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7068 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7069 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7070 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7071 if(NULL == s_simpleLock) |
0 | 7072 { |
7073 /* SDL sets the error message already? */ | |
7074 free(source); | |
7075 free(ALmixer_Channel_List); | |
7076 free(Source_Map_List); | |
7077 ALmixer_Initialized = 0; | |
7078 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7079 return AL_FALSE; |
0 | 7080 } |
7081 | |
7082 | |
7083 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
7084 if(NULL == Stream_Thread_global) | |
7085 { | |
7086 /* 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
|
7087 SDL_DestroyMutex(s_simpleLock); |
0 | 7088 free(source); |
7089 free(ALmixer_Channel_List); | |
7090 free(Source_Map_List); | |
7091 ALmixer_Initialized = 0; | |
7092 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7093 return AL_FALSE; |
0 | 7094 } |
7095 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7096 /* |
0 | 7097 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7098 */ |
0 | 7099 #endif /* End of ENABLE_ALMIXER_THREADS */ |
7100 | |
7101 /* We don't need this array any more because all the sources | |
7102 * are connected to channels | |
7103 */ | |
7104 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7105 return AL_TRUE; |
0 | 7106 } |
7107 | |
7108 | |
7109 | |
7110 /* Keep the return value void to allow easy use with | |
7111 * atexit() | |
7112 */ | |
7113 void ALmixer_Quit() | |
7114 { | |
7115 ALCcontext* context; | |
7116 ALCdevice* dev; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7117 ALint i; |
0 | 7118 |
7119 if( ! ALmixer_Initialized) | |
7120 { | |
7121 return; | |
7122 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7123 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7124 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7125 #endif |
0 | 7126 /* Shutdown everything before closing context */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7127 Internal_HaltChannel(-1, AL_FALSE); |
0 | 7128 |
7129 /* This flag will cause the thread to terminate */ | |
7130 ALmixer_Initialized = 0; | |
7131 #ifdef ENABLE_ALMIXER_THREADS | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7132 SDL_UnlockMutex(s_simpleLock); |
0 | 7133 SDL_WaitThread(Stream_Thread_global, NULL); |
7134 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7135 SDL_DestroyMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7136 #endif |
0 | 7137 |
7138 /* Delete all the OpenAL sources */ | |
7139 for(i=0; i<Number_of_Channels_global; i++) | |
7140 { | |
7141 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
7142 } | |
7143 /* Delete all the channels */ | |
7144 free(ALmixer_Channel_List); | |
7145 free(Source_Map_List); | |
7146 | |
7147 /* Reset the Number_of_Channels just in case somebody | |
7148 * tries using a ALmixer function. | |
7149 * I probably should put "Initialized" checks everywhere, | |
7150 * but I'm too lazy at the moment. | |
7151 */ | |
7152 Number_of_Channels_global = 0; | |
7153 | |
7154 context = alcGetCurrentContext(); | |
7155 if(NULL == context) | |
7156 { | |
7157 return; | |
7158 } | |
7159 /* Need to get the device before I close the context */ | |
7160 dev = alcGetContextsDevice(context); | |
7161 alcDestroyContext(context); | |
7162 | |
7163 if(NULL == dev) | |
7164 { | |
7165 return; | |
7166 } | |
7167 alcCloseDevice(dev); | |
7168 | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7169 /* Delete the list of ALmixerData's before Sound_Quit deletes |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7170 * its own underlying information and I potentially have dangling pointers. |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7171 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7172 while(LinkedList_Size(s_listOfALmixerData) > 0) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7173 { |
16
038baa026db3
Fixed bug in LinkedList delete. Shouldn't have both popped list and then called FreeData which would check the list again for the data. Instead, I should just get the data and then call FreeData to let it manipulate the list.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
13
diff
changeset
|
7174 /* Note that ALmixer_FreeData will remove the data from the linked list for us so don't pop the list here. */ |
038baa026db3
Fixed bug in LinkedList delete. Shouldn't have both popped list and then called FreeData which would check the list again for the data. Instead, I should just get the data and then call FreeData to let it manipulate the list.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
13
diff
changeset
|
7175 ALmixer_Data* almixer_data = LinkedList_Back(s_listOfALmixerData); |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7176 ALmixer_FreeData(almixer_data); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7177 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7178 LinkedList_Free(s_listOfALmixerData); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7179 s_listOfALmixerData = NULL; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7180 |
0 | 7181 Sound_Quit(); |
7182 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7183 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7184 /* 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
|
7185 TError_FreeErrorPool(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7186 s_ALmixerErrorPool = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7187 #endif |
0 | 7188 return; |
7189 } | |
7190 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7191 ALboolean ALmixer_IsInitialized() |
0 | 7192 { |
7193 return ALmixer_Initialized; | |
7194 } | |
7195 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7196 ALuint ALmixer_GetFrequency() |
0 | 7197 { |
7198 return ALmixer_Frequency_global; | |
7199 } | |
7200 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7201 const ALmixer_version* ALmixer_GetLinkedVersion() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7202 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7203 static ALmixer_version linked_mixver; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7204 ALMIXER_GET_COMPILED_VERSION(&linked_mixver); |
0 | 7205 return(&linked_mixver); |
7206 } | |
7207 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7208 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7209 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7210 const char* ALmixer_GetError() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7211 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7212 const char* error_string = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7213 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7214 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7215 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
|
7216 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7217 error_string = TError_GetLastErrorStr(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7218 /* 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
|
7219 if(NULL == error_string) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7220 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7221 return ""; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7222 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7223 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7224 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7225 return error_string; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7226 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7227 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7228 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7229 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
|
7230 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7231 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7232 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7233 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
|
7234 return; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7235 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7236 va_list argp; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7237 va_start(argp, err_str); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7238 // 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
|
7239 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
|
7240 va_end(argp); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7241 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7242 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7243 #endif |
0 | 7244 |
7245 | |
7246 | |
7247 | |
7248 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7249 void ALmixer_OutputAttributes() |
0 | 7250 { |
7251 ALint num_flags = 0; | |
7252 ALint* flags = 0; | |
7253 int i; | |
7254 ALCdevice* dev = alcGetContextsDevice( alcGetCurrentContext() ); | |
7255 | |
7256 | |
7257 printf("custom context\n"); | |
7258 | |
7259 alcGetIntegerv(dev, ALC_ATTRIBUTES_SIZE, | |
7260 sizeof num_flags, &num_flags ); | |
7261 | |
7262 printf("Number of Flags: %d\n", num_flags); | |
7263 | |
7264 if(num_flags) | |
7265 { | |
7266 flags = malloc(sizeof(num_flags) * sizeof(ALint)); | |
7267 | |
7268 alcGetIntegerv(dev, ALC_ALL_ATTRIBUTES, | |
7269 sizeof num_flags * sizeof(ALint), | |
7270 flags ); | |
7271 } | |
7272 for(i = 0; i < num_flags-1; i += 2) | |
7273 { | |
7274 printf("key 0x%x : value %d\n", | |
7275 flags[i], flags[i+1]); | |
7276 } | |
7277 free(flags); | |
7278 } | |
7279 #endif | |
7280 | |
7281 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7282 void ALmixer_OutputDecoders() |
0 | 7283 { |
7284 Sound_Version sound_compile_version; | |
7285 Sound_Version sound_link_version; | |
7286 | |
7287 const Sound_DecoderInfo **rc = Sound_AvailableDecoders(); | |
7288 const Sound_DecoderInfo **i; | |
7289 const char **ext; | |
7290 FILE* stream = stdout; | |
7291 | |
7292 | |
7293 fprintf(stream, "SDL_sound Information:\n"); | |
7294 | |
7295 SOUND_VERSION(&sound_compile_version); | |
7296 fprintf(stream, "\tCompiled with SDL_sound version: %d.%d.%d\n", | |
7297 sound_compile_version.major, | |
7298 sound_compile_version.minor, | |
7299 sound_compile_version.patch); | |
7300 | |
7301 Sound_GetLinkedVersion(&sound_link_version); | |
7302 fprintf(stream, "\tRunning (linked) with SDL_sound version: %d.%d.%d\n", | |
7303 sound_link_version.major, | |
7304 sound_link_version.minor, | |
7305 sound_link_version.patch); | |
7306 | |
7307 fprintf(stream, "Supported sound formats:\n"); | |
7308 if (rc == NULL) | |
7309 fprintf(stream, " * Apparently, NONE!\n"); | |
7310 else | |
7311 { | |
7312 for (i = rc; *i != NULL; i++) | |
7313 { | |
7314 fprintf(stream, " * %s\n", (*i)->description); | |
7315 | |
7316 for (ext = (*i)->extensions; *ext != NULL; ext++) | |
7317 fprintf(stream, " File extension \"%s\"\n", *ext); | |
7318 | |
7319 fprintf(stream, " Written by %s.\n %s\n\n", | |
7320 (*i)->author, (*i)->url); | |
7321 } /* for */ | |
7322 } /* else */ | |
7323 | |
7324 fprintf(stream, "\n"); | |
7325 } | |
7326 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7327 void ALmixer_OutputOpenALInfo() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7328 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7329 ALmixer_version mixer_compile_version; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7330 const ALmixer_version * mixer_link_version=ALmixer_GetLinkedVersion(); |
0 | 7331 FILE* stream = stdout; |
7332 | |
7333 fprintf(stream, "OpenAL Information:\n"); | |
7334 fprintf(stream, "\tAL_VENDOR: %s\n", alGetString( AL_VENDOR ) ); | |
7335 fprintf(stream, "\tAL_VERSION: %s\n", alGetString( AL_VERSION ) ); | |
7336 fprintf(stream, "\tAL_RENDERER: %s\n", alGetString( AL_RENDERER ) ); | |
7337 fprintf(stream, "\tAL_EXTENSIONS: %s\n", alGetString( AL_EXTENSIONS ) ); | |
7338 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7339 ALMIXER_GET_COMPILED_VERSION(&mixer_compile_version); |
0 | 7340 fprintf(stream, "\nSDL_ALmixer Information:\n"); |
7341 fprintf(stream, "\tCompiled with SDL_ALmixer version: %d.%d.%d\n", | |
7342 mixer_compile_version.major, | |
7343 mixer_compile_version.minor, | |
7344 mixer_compile_version.patch); | |
7345 | |
7346 fprintf(stream, "\tRunning (linked) with SDL_ALmixer version: %d.%d.%d\n", | |
7347 mixer_link_version->major, | |
7348 mixer_link_version->minor, | |
7349 mixer_link_version->patch); | |
7350 | |
7351 fprintf(stream, "\tCompile flags: "); | |
7352 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
7353 fprintf(stream, "ENABLE_LOKI_QUEUE_FIX_HACK "); | |
7354 #endif | |
7355 #ifdef ENABLE_ALMIXER_THREADS | |
7356 fprintf(stream, "ENABLE_ALMIXER_THREADS "); | |
7357 #endif | |
7358 #ifdef ENABLE_ALC_SYNC | |
7359 fprintf(stream, "ENABLE_ALC_SYNC "); | |
7360 #endif | |
7361 fprintf(stream, "\n"); | |
7362 } | |
7363 | |
7364 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7365 ALint ALmixer_AllocateChannels(ALint numchans) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7366 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7367 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7368 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7369 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7370 #endif |
0 | 7371 retval = Internal_AllocateChannels(numchans); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7372 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7373 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7374 #endif |
0 | 7375 return retval; |
7376 } | |
7377 | |
7378 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7379 ALint ALmixer_ReserveChannels(ALint num) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7380 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7381 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7382 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7383 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7384 #endif |
0 | 7385 retval = Internal_ReserveChannels(num); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7386 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7387 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7388 #endif |
0 | 7389 return retval; |
7390 } | |
7391 | |
7392 | |
7393 | |
7394 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7395 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
|
7396 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7397 ALuint bytes_decoded; |
0 | 7398 ALmixer_Data* ret_data; |
7399 ALenum error; | |
7400 | |
7401 /* Allocate memory */ | |
7402 ret_data = (ALmixer_Data *)malloc(sizeof(ALmixer_Data)); | |
7403 if (NULL == ret_data) | |
7404 { | |
7405 ALmixer_SetError("Out of memory"); | |
7406 return(NULL); | |
7407 } | |
7408 | |
7409 /* Initialize the data fields */ | |
7410 | |
7411 /* Set the Sound_Sample pointer */ | |
7412 ret_data->sample = sample; | |
7413 | |
7414 /* Flag the data to note that it is not in use */ | |
7415 ret_data->in_use = 0; | |
7416 | |
7417 /* Initialize remaining flags */ | |
7418 ret_data->total_time = -1; | |
7419 ret_data->eof = 0; | |
7420 | |
7421 /* Just initialize */ | |
7422 ret_data->num_buffers_in_use = 0; | |
7423 | |
7424 /* Just initialize */ | |
7425 ret_data->total_bytes = 0; | |
7426 | |
7427 /* Just initialize */ | |
7428 ret_data->loaded_bytes = 0; | |
7429 | |
7430 /* Set the max queue buffers (minimum must be 2) */ | |
7431 if(max_queue_buffers < 2) | |
7432 { | |
7433 max_queue_buffers = ALMIXER_DEFAULT_QUEUE_BUFFERS; | |
7434 } | |
7435 ret_data->max_queue_buffers = max_queue_buffers; | |
7436 /* Set up the start up buffers */ | |
7437 if(0 == num_startup_buffers) | |
7438 { | |
7439 num_startup_buffers = ALMIXER_DEFAULT_STARTUP_BUFFERS; | |
7440 } | |
7441 /* Make sure start up buffers is less or equal to max_queue_buffers */ | |
7442 if(num_startup_buffers > max_queue_buffers) | |
7443 { | |
7444 num_startup_buffers = max_queue_buffers; | |
7445 } | |
7446 ret_data->num_startup_buffers = num_startup_buffers; | |
7447 | |
7448 ret_data->buffer_map_list = NULL; | |
7449 ret_data->current_buffer = 0; | |
7450 | |
7451 ret_data->circular_buffer_queue = NULL; | |
7452 | |
7453 /* Now decode and load the data into a data chunk */ | |
7454 /* Different cases for Streamed and Predecoded | |
7455 * Streamed might turn into a predecoded if buffersize | |
7456 * is large enough */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7457 if(AL_FALSE == decode_mode_is_predecoded) |
0 | 7458 { |
7459 bytes_decoded = Sound_Decode(sample); | |
7460 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7461 { | |
7462 ALmixer_SetError(Sound_GetError()); | |
7463 Sound_FreeSample(sample); | |
7464 free(ret_data); | |
7465 return NULL; | |
7466 } | |
7467 | |
7468 /* If no data, return an error */ | |
7469 if(0 == bytes_decoded) | |
7470 { | |
7471 ALmixer_SetError("File has no data"); | |
7472 Sound_FreeSample(sample); | |
7473 free(ret_data); | |
7474 return NULL; | |
7475 } | |
7476 | |
7477 /* Note, currently, my Ogg conservative modifications | |
7478 * prevent EOF from being detected in the first read | |
7479 * because of the weird packet behavior of ov_read(). | |
7480 * The EAGAIN will get set, but not the EOF. | |
7481 * I don't know the best way to handle this, | |
7482 * so for now, Ogg's can only be explicitly | |
7483 * predecoded. | |
7484 */ | |
7485 | |
7486 /* Correction: Since we no longer actually keep the | |
7487 * streamed data we read here (we rewind and throw | |
7488 * it away, and start over on Play), it is | |
7489 * safe to read another chunk to see if we've hit EOF | |
7490 */ | |
7491 if(sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
7492 { | |
7493 bytes_decoded = Sound_Decode(sample); | |
7494 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7495 { | |
7496 ALmixer_SetError(Sound_GetError()); | |
7497 Sound_FreeSample(sample); | |
7498 free(ret_data); | |
7499 return NULL; | |
7500 } | |
7501 } | |
7502 | |
7503 | |
7504 /* If we found an EOF, the entire file was | |
7505 * decoded, so we can treat it like one. | |
7506 */ | |
7507 | |
7508 if(sample->flags & SOUND_SAMPLEFLAG_EOF) | |
7509 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7510 /* |
0 | 7511 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
|
7512 */ |
0 | 7513 ret_data->decoded_all = 1; |
7514 /* Need to keep this information around for | |
7515 * seek and rewind abilities. | |
7516 */ | |
7517 ret_data->total_bytes = bytes_decoded; | |
7518 /* For now, the loaded bytes is the same as total bytes, but | |
7519 * this could change during a seek operation | |
7520 */ | |
7521 ret_data->loaded_bytes = bytes_decoded; | |
7522 | |
7523 /* Let's compute the total playing time | |
7524 * SDL_sound does not yet provide this (we're working on | |
7525 * that at the moment...) | |
7526 */ | |
7527 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
7528 | |
7529 /* Create one element in the buffer array for data for OpanAL */ | |
7530 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
7531 if(NULL == ret_data->buffer) | |
7532 { | |
7533 ALmixer_SetError("Out of Memory"); | |
7534 Sound_FreeSample(sample); | |
7535 free(ret_data); | |
7536 return NULL; | |
7537 } | |
7538 /* Clear the error code */ | |
7539 alGetError(); | |
7540 /* Now generate an OpenAL buffer using that first element */ | |
7541 alGenBuffers(1, ret_data->buffer); | |
7542 if( (error = alGetError()) != AL_NO_ERROR) | |
7543 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7544 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7545 Sound_FreeSample(sample); |
7546 free(ret_data->buffer); | |
7547 free(ret_data); | |
7548 return NULL; | |
7549 } | |
7550 | |
7551 | |
7552 /* Now copy the data to the OpenAL buffer */ | |
7553 /* We can't just set a pointer because the API needs | |
7554 * its own copy to assist hardware acceleration */ | |
7555 alBufferData(ret_data->buffer[0], | |
7556 TranslateFormat(&sample->desired), | |
7557 sample->buffer, | |
7558 bytes_decoded, | |
7559 sample->desired.rate | |
7560 ); | |
7561 if( (error = alGetError()) != AL_NO_ERROR) | |
7562 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7563 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 7564 Sound_FreeSample(sample); |
7565 alDeleteBuffers(1, ret_data->buffer); | |
7566 free(ret_data->buffer); | |
7567 free(ret_data); | |
7568 return NULL; | |
7569 } | |
7570 | |
7571 /* We should be done with the sample since it's all | |
7572 * predecoded. So we can free the memory */ | |
7573 | |
7574 /* Additional notes: | |
7575 * We need to keep data around in case Seek() is needed | |
7576 * or other Sound_AudioInfo is needed. | |
7577 * This can either be done by not deleting the sample, | |
7578 * or it can be done by dynamically recreating it | |
7579 * when we need it. | |
7580 */ | |
7581 /* Since OpenAL won't let us retrieve it | |
7582 * (aka dynamically), we have to keep the Sample | |
7583 * around because since the user requested | |
7584 * streamed and we offered predecoded, | |
7585 * we don't want to mess up the user who | |
7586 * was expecting seek support | |
7587 * So Don't Do anything | |
7588 */ | |
7589 /* | |
7590 if(0 == access_data) | |
7591 { | |
7592 Sound_FreeSample(sample); | |
7593 ret_data->sample = NULL; | |
7594 } | |
7595 */ | |
7596 /* Else, We keep a copy of the sample around. | |
7597 * so don't do anything. | |
7598 */ | |
7599 | |
7600 #if 0 | |
7601 #if defined(DISABLE_PREDECODED_SEEK) | |
7602 Sound_FreeSample(sample); | |
7603 ret_data->sample = NULL; | |
7604 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
7605 Sound_FreeSample(sample); | |
7606 ret_data->sample = NULL; | |
7607 #else | |
7608 /* We keep a copy of the sample around. | |
7609 * so don't do anything. | |
7610 */ | |
7611 #endif | |
7612 #endif | |
7613 /* okay we're done here */ | |
7614 | |
7615 } | |
7616 /* Else, we need to stream the data, so we'll | |
7617 * create multple buffers for queuing */ | |
7618 else | |
7619 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7620 /* |
0 | 7621 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
|
7622 */ |
0 | 7623 ret_data->decoded_all = 0; |
7624 | |
7625 /* This information is for predecoded. | |
7626 * Set to 0, since we don't know. | |
7627 */ | |
7628 ret_data->total_bytes = 0; | |
7629 | |
7630 /* Create buffers for data | |
7631 */ | |
7632 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) * max_queue_buffers); | |
7633 if(NULL == ret_data->buffer) | |
7634 { | |
7635 ALmixer_SetError("Out of Memory"); | |
7636 Sound_FreeSample(sample); | |
7637 free(ret_data); | |
7638 return NULL; | |
7639 } | |
7640 | |
7641 /* Clear the error code */ | |
7642 alGetError(); | |
7643 /* Now generate an OpenAL buffer using that first element */ | |
7644 alGenBuffers(max_queue_buffers, ret_data->buffer); | |
7645 if( (error = alGetError()) != AL_NO_ERROR) | |
7646 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7647 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7648 Sound_FreeSample(sample); |
7649 free(ret_data->buffer); | |
7650 free(ret_data); | |
7651 return NULL; | |
7652 } | |
7653 | |
7654 /* Redesign: Okay, because of the unqueuing problems and such, | |
7655 * I've decided to redesign where and how queuing is handled. | |
7656 * Before, everything was queued up here. However, this | |
7657 * placed a penalty on load and made performance inconsistent | |
7658 * when samples had to be rewound. It did make things easier | |
7659 * to queue because I could let OpenAL decide which buffer | |
7660 * needed to be queued next. | |
7661 * Now, I'm going to push off the queuing to the actual | |
7662 * Play() command. I'm going to add some book keeping, | |
7663 * and allow for additional buffers to be filled at later | |
7664 * times. | |
7665 */ | |
7666 | |
7667 | |
7668 /* So first of all, because of I already decoded the sample | |
7669 * for testing, I need to decide what to do with it. | |
7670 * The best thing would be be to alBufferData() it. | |
7671 * The problem is it may conflict with the rest of | |
7672 * the system because everything now assumes buffers | |
7673 * are entirely stripped (because of the unqueing | |
7674 * problem). | |
7675 * So it looks like I have to do the crappy thing | |
7676 * and throw away the data, and rewind. | |
7677 */ | |
7678 | |
7679 if(0 == Sound_Rewind(ret_data->sample)) | |
7680 { | |
7681 ALmixer_SetError("Cannot use sample for streamed data because it must be rewindable: %s", Sound_GetError() ); | |
7682 Sound_FreeSample(sample); | |
7683 free(ret_data->buffer); | |
7684 free(ret_data); | |
7685 return NULL; | |
7686 } | |
7687 | |
7688 | |
7689 /* If the user has selected access_data, we need to | |
7690 * keep copies of the queuing buffers around because | |
7691 * OpenAL won't let us access the data. | |
7692 * Allocate the memory for the buffers here | |
7693 * and initialize the albuffer-index map | |
7694 */ | |
7695 if(access_data) | |
7696 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7697 ALuint j; |
0 | 7698 /* Create buffers for data access |
7699 * Should be the same number as the number of queue buffers | |
7700 */ | |
1 | 7701 ret_data->buffer_map_list = (ALmixer_Buffer_Map*)malloc( sizeof(ALmixer_Buffer_Map) * max_queue_buffers); |
0 | 7702 if(NULL == ret_data->buffer_map_list) |
7703 { | |
7704 ALmixer_SetError("Out of Memory"); | |
7705 Sound_FreeSample(sample); | |
7706 free(ret_data->buffer); | |
7707 free(ret_data); | |
7708 return NULL; | |
7709 } | |
7710 | |
7711 ret_data->circular_buffer_queue = CircularQueueUnsignedInt_CreateQueue(max_queue_buffers); | |
7712 if(NULL == ret_data->circular_buffer_queue) | |
7713 { | |
7714 ALmixer_SetError("Out of Memory"); | |
7715 free(ret_data->buffer_map_list); | |
7716 Sound_FreeSample(sample); | |
7717 free(ret_data->buffer); | |
7718 free(ret_data); | |
7719 return NULL; | |
7720 } | |
7721 | |
7722 | |
7723 for(j=0; j<max_queue_buffers; j++) | |
7724 { | |
7725 ret_data->buffer_map_list[j].albuffer = ret_data->buffer[j]; | |
7726 ret_data->buffer_map_list[j].index = j; | |
7727 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
|
7728 ret_data->buffer_map_list[j].data = (ALbyte*)malloc( sizeof(ALbyte) * buffersize); |
0 | 7729 if(NULL == ret_data->buffer_map_list[j].data) |
7730 { | |
7731 ALmixer_SetError("Out of Memory"); | |
7732 break; | |
7733 } | |
7734 } | |
7735 /* If an error happened, we have to clean up the memory */ | |
7736 if(j < max_queue_buffers) | |
7737 { | |
7738 fprintf(stderr, "################## Buffer allocation failed\n"); | |
7739 for( ; j>=0; j--) | |
7740 { | |
7741 free(ret_data->buffer_map_list[j].data); | |
7742 } | |
7743 free(ret_data->buffer_map_list); | |
7744 CircularQueueUnsignedInt_FreeQueue(ret_data->circular_buffer_queue); | |
7745 Sound_FreeSample(sample); | |
7746 free(ret_data->buffer); | |
7747 free(ret_data); | |
7748 return NULL; | |
7749 } | |
7750 | |
7751 /* The Buffer_Map_List must be sorted by albuffer for binary searches | |
7752 */ | |
1 | 7753 qsort(ret_data->buffer_map_list, max_queue_buffers, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 7754 } /* End if access_data==true */ |
7755 | |
7756 | |
7757 } /* End of do stream */ | |
7758 } /* end of DECODE_STREAM */ | |
7759 /* 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
|
7760 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
|
7761 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7762 #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
|
7763 /* 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
|
7764 * 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
|
7765 * 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
|
7766 * so looping isn't needed. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7767 * 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
|
7768 * 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
|
7769 * 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
|
7770 * 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
|
7771 * 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
|
7772 * 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
|
7773 * to load a file. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7774 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7775 ALint sound_duration = Sound_GetDuration(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7776 if(sound_duration > 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7777 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7778 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
|
7779 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
|
7780 if(0 == buffer_resize_succeeded) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7781 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7782 ALmixer_SetError(Sound_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7783 Sound_FreeSample(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7784 free(ret_data); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7785 return NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7786 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7787 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7788 #endif /* ALMIXER_DISABLE_PREDECODED_PRECOMPUTE_BUFFER_SIZE_OPTIMIZATION */ |
0 | 7789 bytes_decoded = Sound_DecodeAll(sample); |
7790 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7791 { | |
7792 ALmixer_SetError(Sound_GetError()); | |
7793 Sound_FreeSample(sample); | |
7794 free(ret_data); | |
7795 return NULL; | |
7796 } | |
7797 | |
7798 /* If no data, return an error */ | |
7799 if(0 == bytes_decoded) | |
7800 { | |
7801 ALmixer_SetError("File has no data"); | |
7802 Sound_FreeSample(sample); | |
7803 free(ret_data); | |
7804 return NULL; | |
7805 } | |
7806 | |
7807 | |
7808 ret_data->decoded_all = 1; | |
7809 /* Need to keep this information around for | |
7810 * seek and rewind abilities. | |
7811 */ | |
7812 ret_data->total_bytes = bytes_decoded; | |
7813 /* For now, the loaded bytes is the same as total bytes, but | |
7814 * this could change during a seek operation | |
7815 */ | |
7816 ret_data->loaded_bytes = bytes_decoded; | |
7817 | |
7818 /* Let's compute the total playing time | |
7819 * SDL_sound does not yet provide this (we're working on | |
7820 * that at the moment...) | |
7821 */ | |
7822 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
7823 | |
7824 /* Create one element in the buffer array for data for OpanAL */ | |
7825 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
7826 if(NULL == ret_data->buffer) | |
7827 { | |
7828 ALmixer_SetError("Out of Memory"); | |
7829 Sound_FreeSample(sample); | |
7830 free(ret_data); | |
7831 return NULL; | |
7832 } | |
7833 /* Clear the error code */ | |
7834 alGetError(); | |
7835 /* Now generate an OpenAL buffer using that first element */ | |
7836 alGenBuffers(1, ret_data->buffer); | |
7837 if( (error = alGetError()) != AL_NO_ERROR) | |
7838 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7839 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7840 Sound_FreeSample(sample); |
7841 free(ret_data->buffer); | |
7842 free(ret_data); | |
7843 return NULL; | |
7844 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7845 /* |
0 | 7846 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
|
7847 */ |
0 | 7848 /* Now copy the data to the OpenAL buffer */ |
7849 /* We can't just set a pointer because the API needs | |
7850 * its own copy to assist hardware acceleration */ | |
7851 alBufferData(ret_data->buffer[0], | |
7852 TranslateFormat(&sample->desired), | |
7853 sample->buffer, | |
7854 bytes_decoded, | |
7855 sample->desired.rate | |
7856 ); | |
7857 if( (error = alGetError()) != AL_NO_ERROR) | |
7858 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7859 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 7860 Sound_FreeSample(sample); |
7861 alDeleteBuffers(1, ret_data->buffer); | |
7862 free(ret_data->buffer); | |
7863 free(ret_data); | |
7864 return NULL; | |
7865 } | |
7866 | |
7867 /* We should be done with the sample since it's all | |
7868 * predecoded. So we can free the memory */ | |
7869 /* Need to keep around because Seek() needs it */ | |
7870 | |
7871 /* Additional notes: | |
7872 * We need to keep data around in case Seek() is needed | |
7873 * or other Sound_AudioInfo is needed. | |
7874 * This can either be done by not deleting the sample, | |
7875 * or it can be done by dynamically recreating it | |
7876 * when we need it. | |
7877 * Update: I think now it's up to the user by passing the | |
7878 * access_data flag. If they set the flag, then they get | |
7879 * data callbacks and seek support. If not, then they can | |
7880 * get all that stuff at the expense of keeping extra memory | |
7881 * around. | |
7882 */ | |
7883 if(0 == access_data) | |
7884 { | |
7885 Sound_FreeSample(sample); | |
7886 ret_data->sample = NULL; | |
7887 } | |
7888 | |
7889 /* Else, We keep a copy of the sample around. | |
7890 * so don't do anything. | |
7891 */ | |
7892 #if 0 | |
7893 #if defined(DISABLE_PREDECODED_SEEK) | |
7894 Sound_FreeSample(sample); | |
7895 ret_data->sample = NULL; | |
7896 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
7897 Sound_FreeSample(sample); | |
7898 ret_data->sample = NULL; | |
7899 #else | |
7900 /* We keep a copy of the sample around. | |
7901 * so don't do anything. | |
7902 */ | |
7903 #endif | |
7904 #endif | |
7905 | |
7906 /* okay we're done here */ | |
7907 } | |
7908 else | |
7909 { | |
7910 /* Shouldn't get here */ | |
7911 ALmixer_SetError("Unknown decode mode"); | |
7912 Sound_FreeSample(sample); | |
7913 free(ret_data); | |
7914 return NULL; | |
7915 } | |
7916 | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7917 /* Add the ALmixerData to an internal linked list so we can delete it on |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7918 * quit and avoid messy dangling issues with Sound_Quit |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7919 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7920 LinkedList_PushBack(s_listOfALmixerData, ret_data); |
0 | 7921 return ret_data; |
7922 } | |
7923 | |
7924 | |
7925 /* This will load a sample for us. Most of the uglyness is | |
7926 * error checking and the fact that streamed/predecoded files | |
7927 * must be treated differently. | |
7928 * I don't like the AudioInfo parameter. I removed it once, | |
7929 * but the system will fail on RAW samples because the user | |
7930 * must specify it, so I had to bring it back. | |
7931 * Remember I must close the rwops if there is an error before NewSample() | |
7932 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7933 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 | 7934 { |
7935 Sound_Sample* sample = NULL; | |
7936 Sound_AudioInfo target; | |
7937 | |
7938 /* Initialize target values to defaults | |
7939 * 0 tells SDL_sound to use the "actual" values | |
7940 */ | |
7941 target.channels = 0; | |
7942 target.rate = 0; | |
7943 #if 0 | |
7944 /* This requires my new additions to SDL_sound. It will | |
7945 * convert the sample to the proper endian order. | |
7946 * If the actual is 8-bit, it will do unsigned, if | |
7947 * the actual is 16-bit, it will do signed. | |
7948 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
7949 * in this way. | |
7950 */ | |
7951 target.format = AUDIO_U8S16SYS; | |
7952 #else | |
7953 target.format = AUDIO_S16SYS; | |
7954 #endif | |
7955 | |
7956 /* Set a default buffersize if needed */ | |
7957 if(0 == buffersize) | |
7958 { | |
7959 buffersize = ALMIXER_DEFAULT_BUFFERSIZE; | |
7960 } | |
7961 | |
7962 sample = Sound_NewSample(rwops, fileext, &target, buffersize); | |
7963 if(NULL == sample) | |
7964 { | |
7965 ALmixer_SetError(Sound_GetError()); | |
7966 return NULL; | |
7967 } | |
7968 | |
1 | 7969 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 7970 } |
7971 | |
7972 | |
7973 | |
7974 /* This will load a sample for us from | |
7975 * a file (instead of RWops). Most of the uglyness is | |
7976 * error checking and the fact that streamed/predecoded files | |
7977 * must be treated differently. | |
7978 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7979 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 | 7980 { |
7981 Sound_Sample* sample = NULL; | |
7982 Sound_AudioInfo target; | |
7983 | |
7984 /* Initialize target values to defaults | |
7985 * 0 tells SDL_sound to use the "actual" values | |
7986 */ | |
7987 target.channels = 0; | |
7988 target.rate = 0; | |
7989 | |
7990 #if 0 | |
7991 /* This requires my new additions to SDL_sound. It will | |
7992 * convert the sample to the proper endian order. | |
7993 * If the actual is 8-bit, it will do unsigned, if | |
7994 * the actual is 16-bit, it will do signed. | |
7995 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
7996 * in this way. | |
7997 */ | |
7998 target.format = AUDIO_U8S16SYS; | |
7999 #else | |
8000 target.format = AUDIO_S16SYS; | |
8001 #endif | |
8002 | |
8003 #if 0 | |
8004 /* Okay, here's a messy hack. The problem is that we need | |
8005 * to convert the sample to have the correct bitdepth, | |
8006 * endian order, and signedness values. | |
8007 * The bit depth is 8 or 16. | |
8008 * The endian order is the native order of the system. | |
8009 * The signedness depends on what the original value | |
8010 * of the sample. Unfortunately, we can't specify these | |
8011 * values until we after we already know what the original | |
8012 * values were for bitdepth and signedness. | |
8013 * So we must open the file once to get the values, | |
8014 * then close it, and then reopen it with the | |
8015 * correct desired target values. | |
8016 * I tried changing the sample->desired field after | |
8017 * the NewSample call, but it had no effect, so | |
8018 * it looks like it must be set on open. | |
8019 */ | |
8020 /* Pick a small buffersize for the first open to not | |
8021 * waste much time allocating memory */ | |
8022 sample = Sound_NewSampleFromFile(filename, NULL, 512); | |
8023 if(NULL == sample) | |
8024 { | |
8025 ALmixer_SetError(Sound_GetError()); | |
8026 return NULL; | |
8027 } | |
8028 | |
8029 bit_depth = GetBitDepth(sample->actual.format); | |
8030 signedness_value = GetSignednessValue(sample->actual.format); | |
8031 if(8 == bit_depth) | |
8032 { | |
8033 /* If 8 bit, then we don't have to worry about | |
8034 * endian issues. We can just use the actual format | |
8035 * value and it should do the right thing | |
8036 */ | |
8037 target.format = sample->actual.format; | |
8038 } | |
8039 else | |
8040 { | |
8041 /* We'll assume it's 16-bit, and if it's not | |
8042 * hopefully SDL_sound will return an error, | |
8043 * or let us convert to 16-bit | |
8044 */ | |
8045 /* Now we need to get the correct signedness */ | |
8046 if(ALMIXER_UNSIGNED_VALUE == signedness_value) | |
8047 { | |
8048 /* Set to Unsigned 16-bit, system endian order */ | |
8049 target.format = AUDIO_U16SYS; | |
8050 } | |
8051 else | |
8052 { | |
8053 /* Again, we'll assume it's Signed 16-bit system order | |
8054 * or force the conversion and hope it works out | |
8055 */ | |
8056 target.format = AUDIO_S16SYS; | |
8057 } | |
8058 } | |
8059 | |
8060 /* Now we have the correct info. We need to close and reopen */ | |
8061 Sound_FreeSample(sample); | |
8062 #endif | |
8063 | |
8064 sample = Sound_NewSampleFromFile(filename, &target, buffersize); | |
8065 if(NULL == sample) | |
8066 { | |
8067 ALmixer_SetError(Sound_GetError()); | |
8068 return NULL; | |
8069 } | |
8070 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8071 /* |
0 | 8072 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
|
8073 */ |
1 | 8074 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8075 } |
8076 | |
8077 | |
8078 /* This is a back door for RAW samples or if you need the | |
8079 * AudioInfo field. Use at your own risk. | |
8080 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8081 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 | 8082 { |
8083 Sound_Sample* sample = NULL; | |
1 | 8084 Sound_AudioInfo sound_desired; |
8085 /* Rather than copying the data from struct to struct, I could just | |
8086 * cast the thing since the structs are meant to be identical. | |
8087 * But if SDL_sound changes it's implementation, bad things | |
8088 * will probably happen. (Or if I change my implementation and | |
8089 * forget about the cast, same bad scenario.) Since this is a load | |
8090 * function, performance of this is negligible. | |
8091 */ | |
8092 if(NULL == desired) | |
8093 { | |
8094 sample = Sound_NewSample(rwops, fileext, NULL, buffersize); | |
8095 } | |
8096 else | |
8097 { | |
8098 sound_desired.format = desired->format; | |
8099 sound_desired.channels = desired->channels; | |
8100 sound_desired.rate = desired->rate; | |
8101 sample = Sound_NewSample(rwops, fileext, &sound_desired, buffersize); | |
8102 } | |
0 | 8103 if(NULL == sample) |
8104 { | |
8105 ALmixer_SetError(Sound_GetError()); | |
8106 return NULL; | |
8107 } | |
1 | 8108 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8109 } |
8110 | |
8111 | |
8112 | |
8113 | |
8114 /* This is a back door for RAW samples or if you need the | |
8115 * AudioInfo field. Use at your own risk. | |
8116 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8117 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 | 8118 { |
8119 Sound_Sample* sample = NULL; | |
1 | 8120 Sound_AudioInfo sound_desired; |
8121 /* Rather than copying the data from struct to struct, I could just | |
8122 * cast the thing since the structs are meant to be identical. | |
8123 * But if SDL_sound changes it's implementation, bad things | |
8124 * will probably happen. (Or if I change my implementation and | |
8125 * forget about the cast, same bad scenario.) Since this is a load | |
8126 * function, performance of this is negligible. | |
8127 */ | |
8128 if(NULL == desired) | |
8129 { | |
8130 sample = Sound_NewSampleFromFile(filename, NULL, buffersize); | |
8131 } | |
8132 else | |
8133 { | |
8134 sound_desired.format = desired->format; | |
8135 sound_desired.channels = desired->channels; | |
8136 sound_desired.rate = desired->rate; | |
8137 sample = Sound_NewSampleFromFile(filename, &sound_desired, buffersize); | |
8138 } | |
8139 | |
0 | 8140 if(NULL == sample) |
8141 { | |
8142 ALmixer_SetError(Sound_GetError()); | |
8143 return NULL; | |
8144 } | |
1 | 8145 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8146 } |
8147 | |
8148 | |
8149 | |
8150 | |
8151 void ALmixer_FreeData(ALmixer_Data* data) | |
8152 { | |
8153 ALenum error; | |
8154 if(NULL == data) | |
8155 { | |
8156 return; | |
8157 } | |
8158 | |
8159 if(data->decoded_all) | |
8160 { | |
8161 /* If access_data was enabled, then the Sound_Sample* | |
8162 * still exists. We need to free it | |
8163 */ | |
8164 if(data->sample != NULL) | |
8165 { | |
8166 Sound_FreeSample(data->sample); | |
8167 } | |
8168 alDeleteBuffers(1, data->buffer); | |
8169 if((error = alGetError()) != AL_NO_ERROR) | |
8170 { | |
8171 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
|
8172 alGetString(error)); |
0 | 8173 } |
8174 | |
8175 } | |
8176 else | |
8177 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8178 ALuint i; |
0 | 8179 |
8180 /* Delete buffer copies if access_data was enabled */ | |
8181 if(data->buffer_map_list != NULL) | |
8182 { | |
8183 for(i=0; i<data->max_queue_buffers; i++) | |
8184 { | |
8185 free(data->buffer_map_list[i].data); | |
8186 } | |
8187 free(data->buffer_map_list); | |
8188 } | |
8189 if(data->circular_buffer_queue != NULL) | |
8190 { | |
8191 CircularQueueUnsignedInt_FreeQueue(data->circular_buffer_queue); | |
8192 } | |
8193 | |
8194 Sound_FreeSample(data->sample); | |
8195 alDeleteBuffers(data->max_queue_buffers, data->buffer); | |
8196 if((error = alGetError()) != AL_NO_ERROR) | |
8197 { | |
8198 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
|
8199 alGetString(error)); |
0 | 8200 } |
8201 } | |
8202 free(data->buffer); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8203 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8204 LinkedList_Remove(s_listOfALmixerData, |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8205 LinkedList_Find(s_listOfALmixerData, data, NULL) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8206 ); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8207 |
0 | 8208 free(data); |
8209 } | |
8210 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8211 ALint ALmixer_GetTotalTime(ALmixer_Data* data) |
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 if(NULL == data) |
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 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8216 } |
0 | 8217 return data->total_time; |
8218 } | |
8219 | |
8220 /* This function will look up the source for the corresponding channel */ | |
8221 /* 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
|
8222 ALuint ALmixer_GetSource(ALint channel) |
0 | 8223 { |
8224 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8225 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8226 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8227 #endif |
0 | 8228 retval = Internal_GetSource(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8229 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8230 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8231 #endif |
0 | 8232 return retval; |
8233 } | |
8234 | |
8235 /* 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
|
8236 ALint ALmixer_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8237 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8238 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8239 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8240 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8241 #endif |
0 | 8242 retval = Internal_GetChannel(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8243 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8244 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8245 #endif |
0 | 8246 return retval; |
8247 } | |
8248 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8249 ALint ALmixer_FindFreeChannel(ALint start_channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8250 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8251 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8252 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8253 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8254 #endif |
0 | 8255 retval = Internal_FindFreeChannel(start_channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8256 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8257 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8258 #endif |
0 | 8259 return retval; |
8260 } | |
8261 | |
8262 | |
8263 | |
8264 /* API update function. | |
8265 * It should return the number of buffers that were | |
8266 * queued during the call. The value might be | |
8267 * used to guage how long you might wait to | |
8268 * call the next update loop in case you are worried | |
8269 * about preserving CPU cycles. The idea is that | |
8270 * when a buffer is queued, there was probably some | |
8271 * CPU intensive looping which took awhile. | |
8272 * 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
|
8273 * Timing the call with ALmixer_GetTicks() would produce |
0 | 8274 * more accurate information. |
8275 * Returns a negative value if there was an error, | |
8276 * the value being the number of errors. | |
8277 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8278 ALint ALmixer_Update() |
0 | 8279 { |
8280 #ifdef ENABLE_ALMIXER_THREADS | |
8281 /* The thread will handle all updates by itself. | |
8282 * Don't allow the user to explicitly call update. | |
8283 */ | |
8284 return 0; | |
8285 #else | |
8286 return( Update_ALmixer(NULL) ); | |
8287 #endif | |
8288 } | |
8289 | |
8290 | |
8291 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8292 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
|
8293 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8294 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8295 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8296 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8297 Channel_Done_Callback = playback_finished_callback; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8298 Channel_Done_Callback_Userdata = user_data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8299 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8300 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8301 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8302 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8303 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8304 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8305 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
|
8306 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8307 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8308 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8309 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8310 Channel_Data_Callback = playback_data_callback; |
1 | 8311 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
|
8312 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8313 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8314 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8315 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8316 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8317 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8318 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8319 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8320 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8321 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
|
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_PlayChannelTimed(channel, data, loops, ticks); |
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 | |
8334 | |
8335 /* In case the user wants to specify a source instead of a channel, | |
8336 * they may use this function. This function will look up the | |
8337 * source-to-channel map, and convert the call into a | |
8338 * PlayChannelTimed() function call. | |
8339 * Returns the channel it's being played on. | |
8340 * Note: If you are prefer this method, then you need to be careful | |
8341 * about using PlayChannel, particularly if you request the | |
8342 * first available channels because source and channels have | |
8343 * a one-to-one mapping in this API. It is quite easy for | |
8344 * a channel/source to already be in use because of this. | |
8345 * In this event, an error message will be returned to you. | |
8346 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8347 ALuint ALmixer_PlaySourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALint ticks) |
0 | 8348 { |
8349 ALuint retval; | |
2
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_PlaySourceTimed(source, data, loops, ticks); |
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 | |
8360 | |
8361 /* Will return the number of channels halted | |
8362 * or 0 for error | |
8363 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8364 ALint ALmixer_HaltChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8365 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8366 ALint retval; |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8369 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8370 retval = Internal_HaltChannel(channel, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8371 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8372 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8373 #endif |
0 | 8374 return retval; |
8375 } | |
8376 | |
8377 /* Will return the number of channels halted | |
8378 * or 0 for error | |
8379 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8380 ALint ALmixer_HaltSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8381 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8382 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8383 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8384 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8385 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8386 retval = Internal_HaltSource(source, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8387 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8388 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8389 #endif |
0 | 8390 return retval; |
8391 } | |
8392 | |
8393 | |
8394 /* This will rewind the SDL_Sound sample for streamed | |
8395 * samples and start buffering up the data for the next | |
8396 * playback. This may require samples to be halted | |
8397 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8398 ALboolean ALmixer_RewindData(ALmixer_Data* data) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8399 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8400 ALboolean retval; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8401 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8402 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8403 #endif |
0 | 8404 retval = Internal_RewindData(data); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8407 #endif |
0 | 8408 return retval; |
8409 } | |
8410 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8411 ALint ALmixer_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8412 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8413 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8414 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8415 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8416 #endif |
0 | 8417 retval = Internal_RewindChannel(channel); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8420 #endif |
0 | 8421 return retval; |
8422 } | |
8423 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8424 ALint ALmixer_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8425 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8426 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8427 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8428 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8429 #endif |
0 | 8430 retval = Internal_RewindSource(source); |
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8433 #endif |
0 | 8434 return retval; |
8435 } | |
8436 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8437 ALint ALmixer_PauseChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8438 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8439 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8440 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8441 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8442 #endif |
0 | 8443 retval = Internal_PauseChannel(channel); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8446 #endif |
0 | 8447 return retval; |
8448 } | |
8449 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8450 ALint ALmixer_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8451 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8452 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8453 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8454 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8455 #endif |
0 | 8456 retval = Internal_PauseSource(source); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8459 #endif |
0 | 8460 return retval; |
8461 } | |
8462 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8463 ALint ALmixer_ResumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8464 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8465 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8466 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8467 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8468 #endif |
0 | 8469 retval = Internal_ResumeChannel(channel); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8472 #endif |
0 | 8473 return retval; |
8474 } | |
8475 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8476 ALint ALmixer_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8477 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8478 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8479 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8480 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8481 #endif |
0 | 8482 retval = Internal_ResumeSource(source); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8485 #endif |
0 | 8486 return retval; |
8487 } | |
8488 | |
8489 /* Might consider setting eof to 0 as a "feature" | |
8490 * This will allow seek to end to stay there because | |
8491 * Play automatically rewinds if at the end */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8492 ALboolean ALmixer_SeekData(ALmixer_Data* data, ALuint msec) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8493 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8494 ALboolean retval; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8495 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8496 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8497 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8498 retval = Internal_SeekData(data, msec); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8499 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8500 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8501 #endif |
0 | 8502 return retval; |
8503 } | |
8504 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8505 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
|
8506 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8507 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8508 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8509 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8510 #endif |
0 | 8511 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
|
8512 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8513 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8514 #endif |
0 | 8515 return retval; |
8516 } | |
8517 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8518 ALuint ALmixer_FadeInSourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 8519 { |
8520 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8521 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8522 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8523 #endif |
0 | 8524 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
|
8525 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8526 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8527 #endif |
0 | 8528 return retval; |
8529 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8530 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8531 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
|
8532 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8533 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8534 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8535 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8536 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8537 retval = Internal_FadeOutChannel(channel, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8538 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8539 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8540 #endif |
0 | 8541 return retval; |
8542 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8543 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8544 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
|
8545 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8546 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8547 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8548 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8549 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8550 retval = Internal_FadeOutSource(source, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8551 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8552 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8553 #endif |
0 | 8554 return retval; |
8555 } | |
8556 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8557 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
|
8558 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8559 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8560 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8561 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8562 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8563 retval = Internal_FadeChannel(channel, ticks, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8564 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8565 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8566 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8567 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8568 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8569 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8570 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
|
8571 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8572 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8573 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8574 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8575 #endif |
0 | 8576 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
|
8577 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8578 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8579 #endif |
0 | 8580 return retval; |
8581 } | |
8582 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8583 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8584 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
|
8585 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8586 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8587 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8588 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8589 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8590 retval = Internal_SetVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8591 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8592 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8593 #endif |
0 | 8594 return retval; |
8595 } | |
8596 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8597 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
|
8598 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8599 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8600 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8601 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8602 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8603 retval = Internal_SetVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8604 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8605 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8606 #endif |
0 | 8607 return retval; |
8608 } | |
8609 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8610 ALfloat ALmixer_GetVolumeChannel(ALint channel) |
0 | 8611 { |
8612 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8613 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8614 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8615 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8616 retval = Internal_GetVolumeChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8617 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8618 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8619 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8620 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8621 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8622 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8623 ALfloat ALmixer_GetVolumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8624 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8625 ALfloat retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8626 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8627 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8628 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8629 retval = Internal_GetVolumeSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8630 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8631 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8632 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8633 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8634 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8635 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8636 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
|
8637 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8638 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8639 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8640 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8641 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8642 retval = Internal_SetMaxVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8643 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8644 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8645 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8646 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8647 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8648 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8649 ALboolean ALmixer_SetMaxVolumeSource(ALuint source, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8650 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8651 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8652 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8653 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8654 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8655 retval = Internal_SetMaxVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8656 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8657 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8658 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8659 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8660 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8661 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8662 ALfloat ALmixer_GetMaxVolumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8663 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8664 ALfloat retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8665 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8666 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8667 #endif |
0 | 8668 retval = Internal_GetMaxVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8669 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8670 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8671 #endif |
0 | 8672 return retval; |
8673 } | |
8674 | |
8675 ALfloat ALmixer_GetMaxVolumeSource(ALuint source) | |
8676 { | |
8677 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8678 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8679 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8680 #endif |
0 | 8681 retval = Internal_GetMaxVolumeSource(source); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8684 #endif |
0 | 8685 return retval; |
8686 } | |
8687 | |
8688 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8689 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
|
8690 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8691 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8692 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8693 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8694 #endif |
0 | 8695 retval = Internal_SetMinVolumeChannel(channel, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8696 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8697 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8698 #endif |
0 | 8699 return retval; |
8700 } | |
8701 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8702 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
|
8703 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8704 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8705 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8706 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8707 #endif |
0 | 8708 retval = Internal_SetMinVolumeSource(source, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8709 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8710 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8711 #endif |
0 | 8712 return retval; |
8713 } | |
8714 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8715 ALfloat ALmixer_GetMinVolumeChannel(ALint channel) |
0 | 8716 { |
8717 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8718 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8719 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8720 #endif |
0 | 8721 retval = Internal_GetMinVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8722 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8723 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8724 #endif |
0 | 8725 return retval; |
8726 } | |
8727 | |
8728 ALfloat ALmixer_GetMinVolumeSource(ALuint source) | |
8729 { | |
8730 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8731 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8732 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8733 #endif |
0 | 8734 retval = Internal_GetMinVolumeSource(source); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8737 #endif |
0 | 8738 return retval; |
8739 } | |
8740 | |
8741 | |
8742 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8743 ALboolean ALmixer_SetMasterVolume(ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8744 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8745 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8746 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8747 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8748 #endif |
0 | 8749 retval = Internal_SetMasterVolume(volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8750 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8751 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8752 #endif |
0 | 8753 return retval; |
8754 } | |
8755 | |
8756 ALfloat ALmixer_GetMasterVolume() | |
8757 { | |
8758 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8759 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8760 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8761 #endif |
0 | 8762 retval = Internal_GetMasterVolume(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8763 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8764 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8765 #endif |
0 | 8766 return retval; |
8767 } | |
8768 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8769 ALint ALmixer_ExpireChannel(ALint channel, ALint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8770 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8771 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8772 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8773 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8774 #endif |
0 | 8775 retval = Internal_ExpireChannel(channel, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8776 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8777 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8778 #endif |
0 | 8779 return retval; |
8780 } | |
8781 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8782 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
|
8783 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8784 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8785 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8786 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8787 #endif |
0 | 8788 retval = Internal_ExpireSource(source, ticks); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8791 #endif |
0 | 8792 return retval; |
8793 } | |
8794 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8795 ALint ALmixer_IsActiveChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8796 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8797 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8798 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8799 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8800 #endif |
0 | 8801 retval = Internal_QueryChannel(channel); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8804 #endif |
0 | 8805 return retval; |
8806 } | |
8807 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8808 ALint ALmixer_IsActiveSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8809 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8810 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8811 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8812 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8813 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8814 retval = Internal_QuerySource(source); |
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8817 #endif |
0 | 8818 return retval; |
8819 } | |
8820 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8821 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8822 ALint ALmixer_IsPlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8823 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8824 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8825 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8826 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8827 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8828 retval = Internal_PlayingChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8829 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8830 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8831 #endif |
0 | 8832 return retval; |
8833 } | |
8834 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8835 ALint ALmixer_IsPlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8836 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8837 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8838 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8839 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8840 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8841 retval = Internal_PlayingSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8842 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8843 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8844 #endif |
0 | 8845 return retval; |
8846 } | |
8847 | |
2
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 ALint ALmixer_IsPausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8850 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8851 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8852 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8853 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8854 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8855 retval = Internal_PausedChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8856 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8857 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8858 #endif |
0 | 8859 return retval; |
8860 } | |
8861 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8862 ALint ALmixer_IsPausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8863 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8864 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8865 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8866 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8867 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8868 retval = Internal_PausedSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8869 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8870 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8871 #endif |
0 | 8872 return retval; |
8873 } | |
8874 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8875 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8876 ALuint ALmixer_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8877 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8878 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8879 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8880 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8881 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8882 retval = Internal_CountAllFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8883 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8884 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8885 #endif |
0 | 8886 return retval; |
8887 } | |
8888 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8889 ALuint ALmixer_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8890 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8891 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8892 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8893 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8894 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8895 retval = Internal_CountUnreservedFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8896 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8897 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8898 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8899 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8900 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8901 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8902 ALuint ALmixer_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8903 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8904 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8905 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8906 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8907 #endif |
0 | 8908 retval = Internal_CountAllUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8909 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8910 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8911 #endif |
0 | 8912 return retval; |
8913 } | |
8914 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8915 ALuint ALmixer_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8916 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8917 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8918 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8919 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8920 #endif |
0 | 8921 retval = Internal_CountUnreservedUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8922 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8923 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8924 #endif |
0 | 8925 return retval; |
8926 } | |
8927 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8928 ALboolean ALmixer_IsPredecoded(ALmixer_Data* data) |
1 | 8929 { |
8930 if(NULL == data) | |
8931 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8932 return AL_FALSE; |
1 | 8933 } |
8934 return data->decoded_all; | |
8935 } | |
8936 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8937 ALboolean ALmixer_CompiledWithThreadBackend() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8938 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8939 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8940 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8941 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8942 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8943 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8944 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8945 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8946 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8947 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8948 |