Mercurial > almixer_isolated
annotate ALmixer.c @ 24:e085cbc573cf
iOS optimization/bug/workaround.
It seems that usleep(10) is paradoxically causing the background thread to hog a bunch of CPU on iOS. (I don't see this on Mac.) Increasing the time to about 60 seems to start helping. More so at 100, but I began to worry about sleeping to long.
So instead I have an evil hack to change the thread priority for just iOS. (In theory, this approach can be applied to other platforms, but it is risky to muck with this.) Since SDL_thread doesn't have a priortiy API, I do some evil pointer math to get the pthread so I can call pthread_setschedparam. If SDL changes the implementation of SDL_thread including the structure layout, this will completely break.
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Fri, 24 Dec 2010 03:32:02 -0800 |
parents | 58f03008ea05 |
children | 46e82b415520 |
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 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
11 #include "ALmixer_RWops.h" |
2
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 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
17 #include "al.h" /* OpenAL */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
18 #include "alc.h" /* For creating OpenAL contexts */ |
0 | 19 |
1 | 20 #ifdef __APPLE__ |
21 /* For performance things like ALC_CONVERT_DATA_UPON_LOADING */ | |
22 /* Note: ALC_CONVERT_DATA_UPON_LOADING used to be in the alc.h header. | |
23 * But in the Tiger OpenAL 1.1 release (10.4.7 and Xcode 2.4), the | |
24 * define was moved to a new header file and renamed to | |
25 * ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING. | |
26 */ | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
27 #include <TargetConditionals.h> |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
28 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
29 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
30 #include <AudioToolbox/AudioToolbox.h> |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
31 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
32 #include <OpenAL/MacOSX_OALExtensions.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
33 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
34 */ |
1 | 35 #endif |
36 | |
0 | 37 /* For malloc, bsearch, qsort */ |
38 #include <stdlib.h> | |
39 | |
40 /* For memcpy */ | |
41 #include <string.h> | |
42 | |
43 #if 0 | |
44 /* for toupper */ | |
45 #include <ctype.h> | |
46 /* for strrchr */ | |
47 #include <string.h> | |
48 #endif | |
49 | |
50 /* Currently used in the output debug functions */ | |
51 #include <stdio.h> | |
52 | |
53 /* My own CircularQueue implementation needed | |
54 * to work around the Nvidia problem of the | |
55 * lack of a buffer query. | |
56 */ | |
57 #include "CircularQueue.h" | |
58 | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
59 /* 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
|
60 * 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
|
61 * 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
|
62 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
63 #include "LinkedList.h" |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
64 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
65 #ifdef ENABLE_ALMIXER_THREADS |
0 | 66 /* Needed for the Mutex locks (and threads if enabled) */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
67 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
68 #include "SimpleMutex.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
69 #include "SimpleThread.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
70 typedef struct SimpleMutex SDL_mutex; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
71 typedef struct SimpleThread SDL_Thread; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
72 #define SDL_CreateMutex SimpleMutex_CreateMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
73 #define SDL_DestroyMutex SimpleMutex_DestroyMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
74 #define SDL_LockMutex SimpleMutex_LockMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
75 #define SDL_UnlockMutex SimpleMutex_UnlockMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
76 #define SDL_CreateThread SimpleThread_CreateThread |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
77 #define SDL_WaitThread SimpleThread_WaitThread |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
78 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
79 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
80 #include "SDL_thread.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
81 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
82 #endif |
0 | 83 |
84 /* Because of the API differences between the Loki | |
85 * and Creative distributions, we need to know which | |
86 * version to use. The LOKI distribution currently | |
87 * has AL_BYTE_LOKI defined in altypes.h which | |
88 * I will use as a flag to identify the distributions. | |
89 * If this is ever removed, I might revert back to the | |
90 * if defined(_WIN32) or defined(__APPLE__) test to | |
91 * identify the Creative dist. | |
92 * I'm not sure if or how the Nvidia distribution differs | |
93 * from the Creative distribution. So for | |
94 * now, the Nvidia distribution gets lumped with the | |
95 * Creative dist and I hope nothing will break. | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
96 * My alGetString may be the most vulnerable. |
0 | 97 */ |
98 #ifdef AL_BYTE_LOKI | |
99 #define USING_LOKI_AL_DIST | |
100 /* This is a short term fix to get around the | |
101 * queuing problem with non-power of two buffer sizes. | |
102 * Hopefully the maintainers will fix this before | |
103 * we're ready to ship. | |
104 */ | |
105 #define ENABLE_LOKI_QUEUE_FIX_HACK | |
106 | |
107 /* The AL_GAIN in the Loki dist doesn't seem to do | |
108 * what I want/expect it to do. I want to use it for | |
109 * Fading, but it seems to work like an off/on switch. | |
110 * 0 = off, >0 = on. | |
111 * The AL_GAIN_LINEAR_LOKI switch seems to do what | |
112 * I want, so I'll redefine it here so the code is consistent | |
113 */ | |
114 /* Update: I've changed the source volume implementations | |
115 * to use AL_MAX_GAIN, so I don't think I need this block | |
116 * of code anymore. The listener uses AL_GAIN, but I | |
117 * hope they got this one right since there isn't a AL_MAX_GAIN | |
118 * for the listener. | |
119 */ | |
120 /* | |
121 #undef AL_GAIN | |
122 #include "alexttypes.h" | |
123 #define AL_GAIN AL_GAIN_LINEAR_LOKI | |
124 */ | |
125 #else | |
126 /* Might need to run other tests to figure out the DIST */ | |
127 /* I've been told that Nvidia doesn't define constants | |
128 * in the headers like Creative. Instead of | |
129 * #define AL_REFERENCE_DISTANCE 0x1020, | |
130 * Nvidia prefers you query OpenAL for a value. | |
131 * int AL_REFERENCE_DISTANCE = alGetEnumValue(ALubyte*)"AL_REFERNECE_DISTANCE"); | |
132 * So I'm assuming this means the Nvidia lacks this value. | |
133 * If this is the case, | |
134 * I guess we can use it to identify the Nvidia dist | |
135 */ | |
136 #ifdef AL_REFERENCE_DISTANCE | |
137 #define USING_CREATIVE_AL_DIST | |
138 #else | |
139 #define USING_NVIDIA_AL_DIST | |
140 #endif | |
141 #endif | |
142 | |
143 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
144 /* Need memset to zero out data */ | |
145 #include <string.h> | |
146 #endif | |
147 | |
148 | |
149 /* Seek issues for predecoded samples: | |
150 * The problem is that OpenAL makes us copy an | |
151 * entire buffer if we want to use it. This | |
152 * means we potentially have two copies of the | |
153 * same data. For predecoded data, this can be a | |
154 * large amount of memory. However, for seek | |
155 * support, I need to be able to get access to | |
156 * the original data so I can set byte positions. | |
157 * The following flags let you disable seek support | |
158 * if you don't want the memory hit, keep everything, | |
159 * or let you try to minimize the memory wasted by | |
160 * fetching it from the OpenAL buffer if needed | |
161 * and making a copy of it. | |
162 * Update: I don't think I need this flag anymore. I've made the | |
163 * effects of this user customizable by the access_data flag on load. | |
164 * If set to true, then seek and data callbacks work, with the | |
165 * cost of more memory and possibly CPU for copying the data through | |
166 * the callbacks. If false, then the extra memory is freed, but | |
167 * you don't get the features. | |
168 */ | |
169 /* | |
170 #define DISABLE_PREDECODED_SEEK | |
171 */ | |
172 /* Problem: Even though alGetBufferi(., AL_DATA, .) | |
173 * is in the Creative Programmer's reference, | |
174 * it actually isn't in the dist. (Invalid enum | |
175 * in Creative, can't compile in Loki.) | |
176 * So we have to keep it disabled | |
177 */ | |
178 #define DISABLE_SEEK_MEMORY_OPTIMIZATION | |
179 | |
180 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION | |
181 /* Needed for memcpy */ | |
182 #include <string.h> | |
183 #endif | |
184 | |
185 /* Old way of doing things: | |
186 #if defined(_WIN32) || defined(__APPLE__) | |
187 #define USING_CREATIVE_AL_DIST | |
188 #else | |
189 #define USING_LOKI_AL_DIST | |
190 #endif | |
191 */ | |
192 | |
193 /************ REMOVE ME (Don't need anymore) ********/ | |
194 #if 0 | |
195 /* Let's get fancy and see if triple buffering | |
196 * does anything good for us | |
197 * Must be 2 or more or things will probably break | |
198 */ | |
199 #define NUMBER_OF_QUEUE_BUFFERS 5 | |
200 /* This is the number of buffers that are queued up | |
201 * when play first starts up. This should be at least 1 | |
202 * and no more than NUMBER_OF_QUEUE_BUFFERS | |
203 */ | |
204 #define NUMBER_OF_START_UP_BUFFERS 2 | |
205 #endif | |
206 /************ END REMOVE ME (Don't need anymore) ********/ | |
207 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
208 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
209 #include "tErrorLib.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
210 static TErrorPool* s_ALmixerErrorPool = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
211 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
212 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
213 static ALboolean ALmixer_Initialized = 0; |
0 | 214 /* This should be set correctly by Init */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
215 static ALuint ALmixer_Frequency_global = ALMIXER_DEFAULT_FREQUENCY; |
0 | 216 |
217 /* Will be initialized in Init */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
218 static ALint Number_of_Channels_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
219 static ALint Number_of_Reserve_Channels_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
220 static ALuint Is_Playing_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
221 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
222 #ifdef ENABLE_ALMIXER_THREADS |
0 | 223 /* This is for a simple lock system. It is not meant to be good, |
224 * but just sufficient to minimize/avoid threading issues | |
225 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
226 static SDL_mutex* s_simpleLock; |
0 | 227 static SDL_Thread* Stream_Thread_global = NULL; |
228 #endif | |
229 | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
230 static LinkedList* s_listOfALmixerData = NULL; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
231 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
232 /* Special stuff for iOS interruption handling */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
233 static ALCcontext* s_interruptionContext = NULL; |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
234 |
0 | 235 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
236 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
237 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
|
238 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
239 static void (*alcMacOSXMixerOutputRateProcPtr)(const ALdouble) = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
240 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
241 if(NULL == alcMacOSXMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
242 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
243 alcMacOSXMixerOutputRateProcPtr = alGetProcAddress((const ALCchar*) "alcMacOSXMixerOutputRate"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
244 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
245 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
246 if(NULL != alcMacOSXMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
247 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
248 alcMacOSXMixerOutputRateProcPtr(sample_rate); |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
251 return; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
252 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
253 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
254 ALdouble Internal_alcMacOSXGetMixerOutputRate() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
255 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
256 static ALdouble (*alcMacOSXGetMixerOutputRateProcPtr)(void) = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
257 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
258 if(NULL == alcMacOSXGetMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
259 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
260 alcMacOSXGetMixerOutputRateProcPtr = alGetProcAddress((const ALCchar*) "alcMacOSXGetMixerOutputRate"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
261 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
262 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
263 if(NULL != alcMacOSXGetMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
264 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
265 return alcMacOSXGetMixerOutputRateProcPtr(); |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
268 return 0.0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
269 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
270 #endif |
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 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
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 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
275 #include <QuartzCore/QuartzCore.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
276 #include <unistd.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
277 static CFTimeInterval s_ticksBaseTime = 0.0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
278 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
279 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
280 #define WIN32_LEAN_AND_MEAN |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
281 #include <windows.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
282 #include <winbase.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
283 LARGE_INTEGER s_hiResTicksPerSecond; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
284 double s_hiResSecondsPerTick; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
285 LARGE_INTEGER s_ticksBaseTime; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
286 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
287 #include <unistd.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
288 #include <time.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
289 static struct timespec s_ticksBaseTime; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
290 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
291 static void ALmixer_InitTime() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
292 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
293 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
294 s_ticksBaseTime = CACurrentMediaTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
295 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
296 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
297 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
|
298 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
|
299 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
300 QueryPerformanceCounter(&s_ticksBaseTime); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
301 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
|
302 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
303 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
304 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
305 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
|
306 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
|
307 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
308 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
309 /* clock_gettime is POSIX.1-2001 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
310 clock_gettime(CLOCK_MONOTONIC, &s_ticksBaseTime); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
311 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
312 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
313 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
314 static ALuint ALmixer_GetTicks() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
315 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
316 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
317 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
|
318 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
319 LARGE_INTEGER current_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
320 QueryPerformanceCounter(¤t_time); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
321 return (ALuint)((current_time.QuadPart - s_ticksBaseTime.QuadPart) * 1000 * s_hiResSecondsPerTick); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
322 #else /* assuming POSIX */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
323 /* clock_gettime is POSIX.1-2001 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
324 struct timespec current_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
325 clock_gettime(CLOCK_MONOTONIC, ¤t_time); |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
326 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
|
327 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
328 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
329 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
|
330 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
331 #if defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
332 Sleep(milliseconds_delay); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
333 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
334 usleep(milliseconds_delay); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
335 #endif |
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 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
338 #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
|
339 #define ALmixer_GetTicks SDL_GetTicks |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
340 #define ALmixer_Delay SDL_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 |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
343 /* On iOS, usleep() of small numbers (say less than 100, very pronounced from 0-50) |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
344 * seems to be sucking up quite a bit of CPU time and causing performance problems. |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
345 * Instead of increasing the sleep time, I started changing the thread priority. |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
346 * This seemed to help the problem. |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
347 * Experimentally, the default priority seems to be 31. According to the docs, |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
348 * valid ranges are from 0 to 31. 6 was still giving me some hiccups so setting to |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
349 * 0 (PTHREAD_MIN_PRIORITY) seems to be the best value so far. |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
350 * Mac also reports 31 as the default. However, I have not noticed the same |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
351 * performance problems and cannot get audio to show up as a significant percentage |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
352 * of the CPU time in Shark/Instruments. |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
353 */ |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
354 #if defined(__APPLE__) && !defined(ALMIXER_COMPILE_WITHOUT_SDL) && ( (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) ) |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
355 #include <pthread.h> |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
356 #endif |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
357 static void Internal_LowerThreadPriority(SDL_Thread* simple_thread) |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
358 { |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
359 /* Might open to other platforms as needed */ |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
360 #if defined(__APPLE__) && ( (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) ) |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
361 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
362 SimpleThread_SetThreadPriority(Stream_Thread_global, 0); |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
363 #else |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
364 struct sched_param schedule_param; |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
365 int sched_policy; |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
366 int ret_val; |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
367 schedule_param.sched_priority = 0; /* PTHREAD_MIN_PRIORITY, max=31 */ |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
368 /* EVIL! This will break if the SDL_Thread structure layout changes. */ |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
369 pthread_t* native_thread_ptr_hack = (pthread_t*)(((char*)(Stream_Thread_global))+sizeof(unsigned long)); |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
370 ret_val = pthread_setschedparam(*native_thread_ptr_hack, SCHED_OTHER, &schedule_param); |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
371 #endif |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
372 #else |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
373 /* No-Op */ |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
374 #endif |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
375 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
376 |
0 | 377 /* If ENABLE_PARANOID_SIGNEDNESS_CHECK is used, |
378 * these values will be reset on Init() | |
379 * Consider these values Read-Only. | |
380 */ | |
381 | |
382 #define ALMIXER_SIGNED_VALUE 127 | |
383 #define ALMIXER_UNSIGNED_VALUE 255 | |
384 | |
385 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
386 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
|
387 static ALushort SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; |
0 | 388 #else |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
389 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
|
390 static const ALushort SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; |
0 | 391 #endif |
392 | |
1 | 393 |
394 /* This can be private instead of being in the header now that I moved | |
395 * ALmixer_Data inside here. | |
396 */ | |
397 typedef struct ALmixer_Buffer_Map ALmixer_Buffer_Map; | |
398 | |
399 | |
400 struct ALmixer_Data | |
401 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
402 ALboolean decoded_all; /* dictates different behaviors */ |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
403 ALint total_time; /* total playing time of sample (msec), obsolete now that we pushed our changes to SDL_sound */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
404 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
405 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
|
406 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
|
407 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
408 ALuint total_bytes; /* For predecoded */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
409 ALuint loaded_bytes; /* For predecoded (for seek) */ |
1 | 410 |
411 Sound_Sample* sample; /* SDL_Sound provides the data */ | |
412 ALuint* buffer; /* array of OpenAL buffers (at least 1 for predecoded) */ | |
413 | |
414 /* Needed for streamed buffers */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
415 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
|
416 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
|
417 ALuint num_buffers_in_use; /* number of buffers in use */ |
1 | 418 |
419 /* This stuff is for streamed buffers that require data access */ | |
420 ALmixer_Buffer_Map* buffer_map_list; /* translate ALbuffer to index | |
421 and holds pointer to copy of data for | |
422 data access */ | |
423 ALuint current_buffer; /* The current playing buffer */ | |
424 | |
425 /* Nvidia distribution refuses to recognize a simple buffer query command | |
426 * unlike all other distributions. It's forcing me to redo the code | |
427 * to accomodate this Nvidia flaw by making me maintain a "best guess" | |
428 * copy of what I think the buffer queue state looks like. | |
429 * A circular queue would a helpful data structure for this task, | |
430 * but I wanted to avoid making an additional header requirement, | |
431 * so I'm making it a void* | |
432 */ | |
433 void* circular_buffer_queue; | |
434 | |
435 | |
436 }; | |
437 | |
0 | 438 static struct ALmixer_Channel |
439 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
440 ALboolean channel_in_use; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
441 ALboolean callback_update; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
442 ALboolean needs_stream; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
443 ALboolean halted; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
444 ALboolean paused; |
0 | 445 ALuint alsource; |
446 ALmixer_Data* almixer_data; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
447 ALint loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
448 ALint expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
449 ALuint start_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
450 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
451 ALboolean fade_enabled; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
452 ALuint fade_expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
453 ALuint fade_start_time; |
0 | 454 ALfloat fade_inv_time; |
455 ALfloat fade_start_volume; | |
456 ALfloat fade_end_volume; | |
457 ALfloat max_volume; | |
458 ALfloat min_volume; | |
459 | |
460 /* Do we need other flags? | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
461 ALbyte *samples; |
0 | 462 int volume; |
463 int looping; | |
464 int tag; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
465 ALuint expire; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
466 ALuint start_time; |
0 | 467 Mix_Fading fading; |
468 int fade_volume; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
469 ALuint fade_length; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
470 ALuint ticks_fade; |
0 | 471 effect_info *effects; |
472 */ | |
473 } *ALmixer_Channel_List = NULL; | |
474 | |
1 | 475 struct ALmixer_Buffer_Map |
476 { | |
477 ALuint albuffer; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
478 ALint index; /* might not need */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
479 ALbyte* data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
480 ALuint num_bytes; |
1 | 481 }; |
482 | |
0 | 483 /* This will be used to find a channel if the user supplies a source */ |
484 typedef struct Source_Map | |
485 { | |
486 ALuint source; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
487 ALint channel; |
0 | 488 } Source_Map; |
489 /* Keep an array of all sources with their associated channel */ | |
490 static Source_Map* Source_Map_List; | |
491 | |
492 static int Compare_Source_Map(const void* a, const void* b) | |
493 { | |
494 return ( ((Source_Map*)a)->source - ((Source_Map*)b)->source ); | |
495 } | |
496 | |
497 /* Sort by channel instead of source */ | |
498 static int Compare_Source_Map_by_channel(const void* a, const void* b) | |
499 { | |
500 return ( ((Source_Map*)a)->channel - ((Source_Map*)b)->channel ); | |
501 } | |
502 | |
503 /* Compare by albuffer */ | |
504 static int Compare_Buffer_Map(const void* a, const void* b) | |
505 { | |
1 | 506 return ( ((ALmixer_Buffer_Map*)a)->albuffer - ((ALmixer_Buffer_Map*)b)->albuffer ); |
0 | 507 } |
508 | |
509 /* This is for the user defined callback via | |
510 * ALmixer_ChannelFinished() | |
511 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
512 static void (*Channel_Done_Callback)(ALint which_channel, ALuint al_source, ALmixer_Data* almixer_data, ALboolean finished_naturally, void* user_data) = NULL; |
0 | 513 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
|
514 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 | 515 static void* Channel_Data_Callback_Userdata = NULL; |
0 | 516 |
517 | |
518 static void PrintQueueStatus(ALuint source) | |
519 { | |
520 ALint buffers_queued = 0; | |
521 ALint buffers_processed = 0; | |
522 ALenum error; | |
523 | |
524 /* Get the number of buffers still queued */ | |
525 alGetSourcei( | |
526 source, | |
527 AL_BUFFERS_QUEUED, | |
528 &buffers_queued | |
529 ); | |
530 | |
531 if((error = alGetError()) != AL_NO_ERROR) | |
532 { | |
533 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
|
534 alGetString(error)); |
0 | 535 } |
536 /* Get the number of buffers processed | |
537 * so we know if we need to refill | |
538 */ | |
539 alGetSourcei( | |
540 source, | |
541 AL_BUFFERS_PROCESSED, | |
542 &buffers_processed | |
543 ); | |
544 if((error = alGetError()) != AL_NO_ERROR) | |
545 { | |
546 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
|
547 alGetString(error)); |
0 | 548 } |
549 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
550 /* |
0 | 551 fprintf(stderr, "For source: %d, buffers_queued=%d, buffers_processed=%d\n", |
552 source, | |
553 buffers_queued, | |
554 buffers_processed); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
555 */ |
0 | 556 } |
557 | |
558 | |
559 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
560 static void Init_Channel(ALint channel) |
0 | 561 { |
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 ALmixer_Channel_List[channel].expire_ticks = 0; | |
570 ALmixer_Channel_List[channel].start_time = 0; | |
571 | |
572 ALmixer_Channel_List[channel].fade_enabled = 0; | |
573 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
574 ALmixer_Channel_List[channel].fade_start_time = 0; | |
575 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
576 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
577 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
578 ALmixer_Channel_List[channel].max_volume = 1.0f; | |
579 ALmixer_Channel_List[channel].min_volume = 0.0f; | |
580 | |
581 ALmixer_Channel_List[channel].almixer_data = NULL; | |
582 } | |
583 /* Quick helper function to clean up a channel | |
584 * after it's done playing */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
585 static void Clean_Channel(ALint channel) |
0 | 586 { |
587 ALenum error; | |
588 ALmixer_Channel_List[channel].channel_in_use = 0; | |
589 ALmixer_Channel_List[channel].callback_update = 0; | |
590 ALmixer_Channel_List[channel].needs_stream = 0; | |
591 ALmixer_Channel_List[channel].paused = 0; | |
592 ALmixer_Channel_List[channel].halted = 0; | |
593 ALmixer_Channel_List[channel].loops = 0; | |
594 | |
595 | |
596 ALmixer_Channel_List[channel].expire_ticks = 0; | |
597 ALmixer_Channel_List[channel].start_time = 0; | |
598 | |
599 ALmixer_Channel_List[channel].fade_enabled = 0; | |
600 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
601 ALmixer_Channel_List[channel].fade_start_time = 0; | |
602 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
603 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
604 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
605 | |
606 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MAX_GAIN, | |
607 ALmixer_Channel_List[channel].max_volume); | |
608 | |
609 if((error = alGetError()) != AL_NO_ERROR) | |
610 { | |
611 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
|
612 alGetString(error)); |
0 | 613 } |
614 | |
615 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MIN_GAIN, | |
616 ALmixer_Channel_List[channel].min_volume); | |
617 if((error = alGetError()) != AL_NO_ERROR) | |
618 { | |
619 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
|
620 alGetString(error)); |
0 | 621 } |
622 | |
623 if(ALmixer_Channel_List[channel].almixer_data != NULL) | |
624 { | |
625 if(ALmixer_Channel_List[channel].almixer_data->in_use > 0) | |
626 { | |
627 ALmixer_Channel_List[channel].almixer_data->in_use--; | |
628 } | |
629 } | |
630 /* Needed to determine if rewind is needed, can't reset */ | |
631 /* | |
632 ALmixer_Channel_List[channel].almixer_data->eof = 0; | |
633 */ | |
634 | |
635 ALmixer_Channel_List[channel].almixer_data = NULL; | |
636 } | |
637 | |
638 /* What shoud this return? | |
639 * 127 for signed, 255 for unsigned | |
640 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
641 static ALubyte GetSignednessValue(ALushort format) |
0 | 642 { |
643 switch(format) | |
644 { | |
645 case AUDIO_U8: | |
646 case AUDIO_U16LSB: | |
647 case AUDIO_U16MSB: | |
648 return ALMIXER_UNSIGNED_VALUE; | |
649 break; | |
650 case AUDIO_S8: | |
651 case AUDIO_S16LSB: | |
652 case AUDIO_S16MSB: | |
653 return ALMIXER_SIGNED_VALUE; | |
654 break; | |
655 default: | |
656 return 0; | |
657 } | |
658 return 0; | |
659 } | |
660 | |
661 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
662 static ALubyte GetBitDepth(ALushort format) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
663 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
664 ALubyte bit_depth = 16; |
0 | 665 |
666 switch(format) | |
667 { | |
668 case AUDIO_U8: | |
669 case AUDIO_S8: | |
670 bit_depth = 8; | |
671 break; | |
672 | |
673 case AUDIO_U16LSB: | |
674 /* | |
675 case AUDIO_U16: | |
676 */ | |
677 case AUDIO_S16LSB: | |
678 /* | |
679 case AUDIO_S16: | |
680 */ | |
681 case AUDIO_U16MSB: | |
682 case AUDIO_S16MSB: | |
683 /* | |
684 case AUDIO_U16SYS: | |
685 case AUDIO_S16SYS: | |
686 */ | |
687 bit_depth = 16; | |
688 break; | |
689 default: | |
690 bit_depth = 0; | |
691 } | |
692 return bit_depth; | |
693 } | |
694 | |
695 /* Need to translate between SDL/SDL_Sound audiospec | |
696 * and OpenAL conventions */ | |
697 static ALenum TranslateFormat(Sound_AudioInfo* info) | |
698 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
699 ALubyte bit_depth; |
0 | 700 |
701 bit_depth = GetBitDepth(info->format); | |
702 if(0 == bit_depth) | |
703 { | |
704 fprintf(stderr, "Warning: Unknown bit depth. Setting to 16\n"); | |
705 bit_depth = 16; | |
706 } | |
707 | |
708 if(2 == info->channels) | |
709 { | |
710 if(16 == bit_depth) | |
711 { | |
712 return AL_FORMAT_STEREO16; | |
713 } | |
714 else | |
715 { | |
716 return AL_FORMAT_STEREO8; | |
717 } | |
718 } | |
719 else | |
720 { | |
721 if(16 == bit_depth) | |
722 { | |
723 return AL_FORMAT_MONO16; | |
724 } | |
725 else | |
726 { | |
727 return AL_FORMAT_MONO8; | |
728 } | |
729 } | |
730 /* Make compiler happy. Shouldn't get here */ | |
731 return AL_FORMAT_STEREO16; | |
732 } | |
733 | |
1 | 734 |
735 /* This will compute the total playing time | |
736 * based upon the number of bytes and audio info. | |
737 * (In prinicple, it should compute the time for any given length) | |
738 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
739 static ALuint Compute_Total_Time_Decomposed(ALuint bytes_per_sample, ALuint frequency, ALubyte channels, size_t total_bytes) |
1 | 740 { |
741 double total_sec; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
742 ALuint total_msec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
743 ALuint bytes_per_sec; |
1 | 744 |
745 if(0 == total_bytes) | |
746 { | |
747 return 0; | |
748 } | |
749 /* To compute Bytes per second, do | |
750 * samples_per_sec * bytes_per_sample * number_of_channels | |
751 */ | |
752 bytes_per_sec = frequency * bytes_per_sample * channels; | |
753 | |
754 /* Now to get total time (sec), do | |
755 * total_bytes / bytes_per_sec | |
756 */ | |
757 total_sec = total_bytes / (double)bytes_per_sec; | |
758 | |
759 /* Now convert seconds to milliseconds | |
760 * Add .5 to the float to do rounding before the final cast | |
761 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
762 total_msec = (ALuint) ( (total_sec * 1000) + 0.5 ); |
1 | 763 /* |
764 fprintf(stderr, "freq=%d, bytes_per_sample=%d, channels=%d, total_msec=%d\n", frequency, bytes_per_sample, channels, total_msec); | |
765 */ | |
766 return total_msec; | |
767 } | |
768 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
769 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
|
770 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
771 ALuint bytes_per_sample; |
1 | 772 |
773 if(0 == total_bytes) | |
774 { | |
775 return 0; | |
776 } | |
777 /* 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
|
778 * 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
|
779 * 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
|
780 * 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
|
781 * 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
|
782 * 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
|
783 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
784 bytes_per_sample = (ALuint) ((info->format & 0xFF) / 8); |
1 | 785 |
786 return Compute_Total_Time_Decomposed(bytes_per_sample, info->rate, info->channels, total_bytes); | |
787 } /* End Compute_Total_Time */ | |
788 | |
789 | |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
790 #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
|
791 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
|
792 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
793 double total_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
794 ALuint bytes_per_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
795 size_t total_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
796 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
797 if(0 >= total_msec) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
798 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
799 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
800 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
801 /* To compute Bytes per second, do |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
802 * 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
|
803 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
804 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
|
805 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
806 /* convert milliseconds to seconds */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
807 total_sec = total_msec / 1000.0; |
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 /* Now to get total bytes */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
810 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
|
811 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
812 /* 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
|
813 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
814 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
815 return total_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
816 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
817 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
818 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
|
819 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
820 ALuint bytes_per_sample; |
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 if(0 >= total_msec) |
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 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
825 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
826 /* 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
|
827 * 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
|
828 * 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
|
829 * 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
|
830 * 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
|
831 * 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
|
832 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
833 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
|
834 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
835 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
|
836 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
837 |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
838 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
839 /* The back-end decoders seem to need to decode in quantized frame sizes. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
840 * So if I can pad the bytes to the next quanta, things might go more smoothly. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
841 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
842 static size_t Compute_Total_Bytes_With_Frame_Padding(Sound_AudioInfo *info, ALuint total_msec) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
843 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
844 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
845 ALuint bytes_per_frame; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
846 size_t evenly_divisible_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
847 size_t remainder_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
848 size_t return_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
849 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
850 size_t total_bytes = Compute_Total_Bytes(info, total_msec); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
851 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
852 bytes_per_sample = (ALuint) ((info->format & 0xFF) / 8); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
853 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
854 bytes_per_frame = bytes_per_sample * info->channels; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
855 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
856 evenly_divisible_frames = total_bytes / bytes_per_frame; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
857 remainder_frames = total_bytes % bytes_per_frame; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
858 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
859 return_bytes = (evenly_divisible_frames * bytes_per_frame) + (remainder_frames * bytes_per_frame); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
860 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
861 /* Experimentally, some times I see to come up short in |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
862 * actual bytes decoded and I see a second pass is needed. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
863 * I'm worried this may have additional performance implications. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
864 * Sometimes in the second pass (depending on file), |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
865 * I have seen between 0 and 18 bytes. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
866 * I'm tempted to pad the bytes by some arbitrary amount. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
867 * However, I think currently the way SDL_sound is implemented, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
868 * there is a big waste of memory up front instead of per-pass, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
869 * so maybe I shouldn't worry about this. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
870 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
871 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
872 return_bytes += 64; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
873 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
874 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
875 fprintf(stderr, "remainder_frames=%d, padded_total_bytes=%d\n", remainder_frames, return_bytes); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
876 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
877 return return_bytes; |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
878 } |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
879 #endif /* 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
|
880 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
881 |
1 | 882 |
0 | 883 /**************** REMOVED ****************************/ |
884 /* This was removed because I originally thought | |
885 * OpenAL could return a pointer to the buffer data, | |
886 * but I was wrong. If something like that is ever | |
887 * implemented, then this might become useful. | |
888 */ | |
889 #if 0 | |
890 /* Reconstruct_Sound_Sample and Set_AudioInfo only | |
891 * are needed if the Seek memory optimization is | |
892 * used. Also, the Loki dist doesn't seem to support | |
893 * AL_DATA which I need for it. | |
894 */ | |
895 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION | |
896 | |
897 static void Set_AudioInfo(Sound_AudioInfo* info, ALint frequency, ALint bits, ALint channels) | |
898 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
899 info->rate = (ALuint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
900 info->channels = (ALubyte)channels; |
0 | 901 |
902 /* Not sure if it should be signed or unsigned. Hopefully | |
903 * that detail won't be needed. | |
904 */ | |
905 if(8 == bits) | |
906 { | |
907 info->format = AUDIO_U8; | |
908 } | |
909 else | |
910 { | |
911 info->format = AUDIO_U16SYS; | |
912 } | |
913 fprintf(stderr, "Audio info: freq=%d, chan=%d, format=%d\n", | |
914 info->rate, info->channels, info->format); | |
915 | |
916 } | |
917 | |
918 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
919 static ALint Reconstruct_Sound_Sample(ALmixer_Data* data) |
0 | 920 { |
921 ALenum error; | |
922 ALint* data_from_albuffer; | |
923 ALint freq; | |
924 ALint bits; | |
925 ALint channels; | |
926 ALint size; | |
927 | |
928 /* Create memory all initiallized to 0. */ | |
929 data->sample = (Sound_Sample*)calloc(1, sizeof(Sound_Sample)); | |
930 if(NULL == data->sample) | |
931 { | |
932 ALmixer_SetError("Out of memory for Sound_Sample"); | |
933 return -1; | |
934 } | |
935 | |
936 /* Clear errors */ | |
937 alGetError(); | |
938 | |
939 alGetBufferi(data->buffer[0], AL_FREQUENCY, &freq); | |
940 if((error = alGetError()) != AL_NO_ERROR) | |
941 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
942 ALmixer_SetError("alGetBufferi(AL_FREQUENCY): %s", alGetString(error) ); |
0 | 943 free(data->sample); |
944 data->sample = NULL; | |
945 return -1; | |
946 } | |
947 | |
948 alGetBufferi(data->buffer[0], AL_BITS, &bits); | |
949 if((error = alGetError()) != AL_NO_ERROR) | |
950 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
951 ALmixer_SetError("alGetBufferi(AL_BITS): %s", alGetString(error) ); |
0 | 952 free(data->sample); |
953 data->sample = NULL; | |
954 return -1; | |
955 } | |
956 | |
957 alGetBufferi(data->buffer[0], AL_CHANNELS, &channels); | |
958 if((error = alGetError()) != AL_NO_ERROR) | |
959 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
960 ALmixer_SetError("alGetBufferi(AL_CHANNELS): %s", alGetString(error) ); |
0 | 961 free(data->sample); |
962 data->sample = NULL; | |
963 return -1; | |
964 } | |
965 | |
966 alGetBufferi(data->buffer[0], AL_SIZE, &size); | |
967 if((error = alGetError()) != AL_NO_ERROR) | |
968 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
969 ALmixer_SetError("alGetBufferi(AL_SIZE): %s", alGetString(error) ); |
0 | 970 free(data->sample); |
971 data->sample = NULL; | |
972 return -1; | |
973 } | |
974 | |
975 alGetBufferi(data->buffer[0], AL_DATA, data_from_albuffer); | |
976 if((error = alGetError()) != AL_NO_ERROR) | |
977 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
978 ALmixer_SetError("alGetBufferi(AL_DATA): %s", alGetString(error) ); |
0 | 979 free(data->sample); |
980 data->sample = NULL; | |
981 return -1; | |
982 } | |
983 | |
984 if(size <= 0) | |
985 { | |
986 ALmixer_SetError("No data in al buffer"); | |
987 free(data->sample); | |
988 data->sample = NULL; | |
989 return -1; | |
990 } | |
991 | |
992 /* Now that we have all the attributes, we need to | |
993 * allocate memory for the buffer and reconstruct | |
994 * the AudioInfo attributes. | |
995 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
996 data->sample->buffer = malloc(size*sizeof(ALbyte)); |
0 | 997 if(NULL == data->sample->buffer) |
998 { | |
999 ALmixer_SetError("Out of memory for sample->buffer"); | |
1000 free(data->sample); | |
1001 data->sample = NULL; | |
1002 return -1; | |
1003 } | |
1004 | |
1005 memcpy(data->sample->buffer, data_from_albuffer, size); | |
1006 data->sample->buffer_size = size; | |
1007 | |
1008 /* Fill up the Sound_AudioInfo structures */ | |
1009 Set_AudioInfo(&data->sample->desired, freq, bits, channels); | |
1010 Set_AudioInfo(&data->sample->actual, freq, bits, channels); | |
1011 | |
1012 return 0; | |
1013 } | |
1014 | |
1015 #endif /* End DISABLE_SEEK_MEMORY_OPTIMIZATION */ | |
1016 #endif | |
1017 /*************** END REMOVED *************************/ | |
1018 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1019 static void Invoke_Channel_Done_Callback(ALint which_channel, ALboolean did_finish_naturally) |
0 | 1020 { |
1021 if(NULL == Channel_Done_Callback) | |
1022 { | |
1023 return; | |
1024 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1025 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
|
1026 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1027 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1028 static ALint LookUpBuffer(ALuint buffer, ALmixer_Buffer_Map* buffer_map_list, ALuint num_items_in_list) |
0 | 1029 { |
1030 /* Only the first value is used for the key */ | |
1 | 1031 ALmixer_Buffer_Map key = { 0, 0, NULL, 0 }; |
1032 ALmixer_Buffer_Map* found_item = NULL; | |
0 | 1033 key.albuffer = buffer; |
1034 | |
1035 /* Use the ANSI C binary search feature (yea!) */ | |
1 | 1036 found_item = (ALmixer_Buffer_Map*)bsearch(&key, buffer_map_list, num_items_in_list, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 1037 if(NULL == found_item) |
1038 { | |
1039 ALmixer_SetError("Can't find buffer"); | |
1040 return -1; | |
1041 } | |
1042 return found_item->index; | |
1043 } | |
1044 | |
1045 | |
1046 /* FIXME: Need to pass back additional info to be useful. | |
1047 * Bit rate, stereo/mono (num chans), time in msec? | |
1048 * Precoded/streamed flag so user can plan for future data? | |
1049 */ | |
1 | 1050 /* |
1051 * channels: 1 for mono, 2 for stereo | |
1052 * | |
1053 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1054 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
|
1055 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1056 ALboolean is_unsigned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1057 ALubyte bits_per_sample = GetBitDepth(format); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1058 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1059 ALuint length_in_msec; |
1 | 1060 |
1061 if(GetSignednessValue(format) == ALMIXER_UNSIGNED_VALUE) | |
1062 { | |
1063 is_unsigned = 1; | |
1064 } | |
1065 else | |
1066 { | |
1067 is_unsigned = 0; | |
1068 } | |
1069 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1070 bytes_per_sample = (ALuint) (bits_per_sample / 8); |
1 | 1071 |
1072 length_in_msec = Compute_Total_Time_Decomposed(bytes_per_sample, frequency, channels, num_bytes); | |
1073 | |
0 | 1074 /* |
1075 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); | |
1076 */ | |
1077 if(NULL == Channel_Data_Callback) | |
1078 { | |
1079 return; | |
1080 } | |
1 | 1081 /* |
1082 * Channel_Data_Callback(which_channel, data, num_bytes, frequency, channels, GetBitDepth(format), format, decode_mode_is_predecoded); | |
1083 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1084 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
|
1085 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1086 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1087 static void Invoke_Predecoded_Channel_Data_Callback(ALint channel, ALmixer_Data* data) |
0 | 1088 { |
1089 if(NULL == data->sample) | |
1090 { | |
1091 return; | |
1092 } | |
1093 /* The buffer position is complicated because if the current data was seeked, | |
1094 * we must adjust the buffer to the seek position | |
1095 */ | |
1096 Invoke_Channel_Data_Callback(channel, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1097 (((ALbyte*) data->sample->buffer) + (data->total_bytes - data->loaded_bytes) ), |
0 | 1098 data->loaded_bytes, |
1099 data->sample->desired.rate, | |
1100 data->sample->desired.channels, | |
1101 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1102 AL_TRUE |
0 | 1103 ); |
1104 } | |
1105 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1106 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
|
1107 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1108 ALint index; |
0 | 1109 if(NULL == data->buffer_map_list) |
1110 { | |
1111 return; | |
1112 } | |
1113 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1114 /* This should catch the case where all buffers are unqueued | |
1115 * and the "current" buffer is id: 0 | |
1116 */ | |
1117 if(-1 == index) | |
1118 { | |
1119 return; | |
1120 } | |
1121 Invoke_Channel_Data_Callback(channel, | |
1122 data->buffer_map_list[index].data, | |
1123 data->buffer_map_list[index].num_bytes, | |
1124 data->sample->desired.rate, | |
1125 data->sample->desired.channels, | |
1126 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1127 AL_FALSE |
0 | 1128 ); |
1129 } | |
1130 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1131 /* Converts milliseconds to byte positions. |
0 | 1132 * This is needed for seeking on predecoded samples |
1133 */ | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1134 static ALuint Convert_Msec_To_Byte_Pos(Sound_AudioInfo* audio_info, ALuint number_of_milliseconds) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1135 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1136 ALuint bytes_per_sample; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1137 ALuint bytes_per_frame; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1138 float bytes_per_millisecond; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1139 float byte_position; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1140 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1141 if(audio_info == NULL) |
0 | 1142 { |
1143 fprintf(stderr, "Error, info is NULL\n"); | |
1144 } | |
1145 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1146 /* SDL has a mask trick I was not aware of. Mask the upper bits |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1147 * of the format, and you get 8 or 16 which is the bits per sample. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1148 * Divide by 8bits_per_bytes and you get bytes_per_sample |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1149 * I tested this under 32-bit and 64-bit and big and little endian |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1150 * to make sure this still works since I have since moved from |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1151 * Uint32 to unspecified size types like ALuint. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1152 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1153 bytes_per_sample = (ALuint) ((audio_info->format & 0xFF) / 8); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1154 bytes_per_frame = bytes_per_sample * audio_info->channels; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1155 bytes_per_millisecond = (float)bytes_per_frame * (audio_info->rate / 1000.0f); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1156 byte_position = ((float)(number_of_milliseconds)) * bytes_per_millisecond; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1157 return (ALuint)(byte_position + 0.5); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1158 } |
0 | 1159 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1160 static ALint Set_Predecoded_Seek_Position(ALmixer_Data* data, ALuint byte_position) |
0 | 1161 { |
1162 ALenum error; | |
1163 /* clear error */ | |
1164 alGetError(); | |
1165 | |
1166 /* Is it greater than, or greater-than or equal to ?? */ | |
1167 if(byte_position > data->total_bytes) | |
1168 { | |
1169 /* 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
|
1170 /* |
0 | 1171 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
|
1172 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1173 |
0 | 1174 /* In case the below thing doesn't work, |
1175 * just rewind the whole thing. | |
1176 * | |
1177 alBufferData(data->buffer[0], | |
1178 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1179 (ALbyte*) data->sample->buffer, |
0 | 1180 data->total_bytes, |
1181 data->sample->desired.rate | |
1182 ); | |
1183 */ | |
1184 | |
1185 /* I was trying to set to the end, (1 byte remaining), | |
1186 * but I was getting freezes. I'm thinking it might be | |
1187 * another Power of 2 bug in the Loki dist. I tried 2, | |
1188 * and it still hung. 4 didn't hang, but I got a clip | |
1189 * artifact. 8 seemed to work okay. | |
1190 */ | |
1191 alBufferData(data->buffer[0], | |
1192 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1193 (((ALbyte*) data->sample->buffer) + (data->total_bytes - 8) ), |
0 | 1194 8, |
1195 data->sample->desired.rate | |
1196 ); | |
1197 if( (error = alGetError()) != AL_NO_ERROR) | |
1198 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1199 ALmixer_SetError("Can't seek past end and alBufferData failed: %s\n", alGetString(error)); |
0 | 1200 return -1; |
1201 } | |
1202 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1203 * query command to work because I don't know if it will mutilate the | |
1204 * size for its own purposes or return the original size | |
1205 */ | |
1206 data->loaded_bytes = 8; | |
1207 | |
1208 /* Not sure if this should be an error or not */ | |
1209 /* | |
1210 ALmixer_SetError("Can't Seek past end"); | |
1211 return -1; | |
1212 */ | |
1213 return 0; | |
1214 } | |
1215 | |
1216 alBufferData(data->buffer[0], | |
1217 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1218 &(((ALbyte*)data->sample->buffer)[byte_position]), |
0 | 1219 data->total_bytes - byte_position, |
1220 data->sample->desired.rate | |
1221 ); | |
1222 if( (error = alGetError()) != AL_NO_ERROR) | |
1223 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1224 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1225 return -1; |
1226 } | |
1227 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1228 * query command to work because I don't know if it will mutilate the | |
1229 * size for its own purposes or return the original size | |
1230 */ | |
1231 data->loaded_bytes = data->total_bytes - byte_position; | |
1232 | |
1233 return 0; | |
1234 } | |
1235 | |
1236 /* Because we have multiple queue buffers and OpenAL won't let | |
1237 * us access them, we need to keep copies of each buffer around | |
1238 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1239 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
|
1240 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1241 ALint index; |
0 | 1242 /* We only want to copy if access_data is true. |
1243 * This is determined by whether memory has been | |
1244 * allocated in the buffer_map_list or not | |
1245 */ | |
1246 if(NULL == data->buffer_map_list) | |
1247 { | |
1248 return -1; | |
1249 } | |
1250 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1251 if(-1 == index) | |
1252 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1253 /* |
0 | 1254 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
|
1255 */ |
0 | 1256 return -1; |
1257 } | |
1258 /* Copy the data to the access buffer */ | |
1259 memcpy(data->buffer_map_list[index].data, data->sample->buffer, num_bytes); | |
1260 data->buffer_map_list[index].num_bytes = data->sample->buffer_size; | |
1261 | |
1262 return 0; | |
1263 } | |
1264 | |
1265 | |
1266 /* For streamed data, gets more data | |
1267 * and prepares it in the active Mix_chunk | |
1268 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1269 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
|
1270 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1271 ALuint bytes_decoded; |
0 | 1272 ALenum error; |
1273 if(NULL == data) | |
1274 { | |
1275 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1276 return 0; | |
1277 } | |
1278 | |
1279 bytes_decoded = Sound_Decode(data->sample); | |
1280 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1281 { | |
1282 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1283 ALmixer_SetError(Sound_GetError()); | |
1284 /* Force cleanup through FreeData | |
1285 Sound_FreeSample(data->sample); | |
1286 */ | |
1287 return 0; | |
1288 } | |
1289 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1290 /* 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
|
1291 |
0 | 1292 /* Don't forget to add check for EOF */ |
1293 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1294 if(0 == bytes_decoded) | |
1295 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1296 data->eof = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1297 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1298 #if 0 |
0 | 1299 fprintf(stderr, "Hit eof while trying to buffer\n"); |
1300 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1301 { | |
1302 fprintf(stderr, "\tEOF flag\n"); | |
1303 } | |
1304 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1305 { | |
1306 fprintf(stderr, "\tCanSeek flag\n"); | |
1307 } | |
1308 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1309 { | |
1310 fprintf(stderr, "\tEAGAIN flag\n"); | |
1311 } | |
1312 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1313 { | |
1314 fprintf(stderr, "\tNONE flag\n"); | |
1315 } | |
1316 #endif | |
1317 return 0; | |
1318 } | |
1319 | |
1320 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
1321 /******* REMOVE ME ********************************/ | |
1322 /***************** ANOTHER EXPERIEMENT *******************/ | |
1323 /* The PROBLEM: It seems that the Loki distribution has problems | |
1324 * with Queuing when the buffer size is not a power of two | |
1325 * and additional buffers must come after it. | |
1326 * The behavior is inconsistent, but one of several things | |
1327 * usually happens: | |
1328 * Playback is normal | |
1329 * Playback immediately stops after the non-pow2 buffer | |
1330 * Playback gets distorted on the non-pow2 buffer | |
1331 * The entire program segfaults. | |
1332 * The workaround is to always specify a power of two buffer size | |
1333 * and hope that SDL_sound always fill it. (By lucky coincidence, | |
1334 * I already submitted the Ogg fix.) However, this won't catch | |
1335 * cases where a loop happens because the read at the end of the | |
1336 * file is typically less than the buffer size. | |
1337 * | |
1338 * This fix addresses this issue, however it may break in | |
1339 * other conditions. Always decode in buffer sizes of powers of 2. | |
1340 * | |
1341 * The HACK: | |
1342 * If the buffer is short, try filling it up with 0's | |
1343 * to meet the user requested buffer_size which | |
1344 * is probably a nice number OpenAL likes, in | |
1345 * hopes to avoid a possible Loki bug with | |
1346 * short buffers. If looping (which is the main | |
1347 * reason for this), the negative side effect is | |
1348 * that it may take longer for the loop to start | |
1349 * because it must play dead silence. Or if the decoder | |
1350 * doesn't guarantee to return the requested bytes | |
1351 * (like Ogg), then you will get breakup in between | |
1352 * packets. | |
1353 */ | |
1354 if( (bytes_decoded) < data->sample->buffer_size) | |
1355 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1356 ALubyte bit_depth; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1357 ALubyte signedness_value; |
0 | 1358 int silence_value; |
1359 /* Crap, memset value needs to be the "silent" value, | |
1360 * but it will differ for signed/unsigned and bit depth | |
1361 */ | |
1362 bit_depth = GetBitDepth(data->sample->desired.format); | |
1363 signedness_value = GetSignednessValue(data->sample->desired.format); | |
1364 if(ALMIXER_SIGNED_VALUE == signedness_value) | |
1365 { | |
1366 /* I'm guessing that if it's signed, then 0 is the | |
1367 * "silent" value */ | |
1368 silence_value = 0; | |
1369 } | |
1370 else | |
1371 { | |
1372 if(8 == bit_depth) | |
1373 { | |
1374 /* If 8 bit, I'm guessing it's (2^7)-1 = 127 */ | |
1375 silence_value = 127; | |
1376 } | |
1377 else | |
1378 { | |
1379 /* For 16 bit, I'm guessing it's (2^15)-1 = 32767 */ | |
1380 silence_value = 32767; | |
1381 } | |
1382 } | |
1383 /* Now fill up the rest of the data buffer with the | |
1384 * silence_value. | |
1385 * I don't think I have to worry about endian issues for | |
1386 * this part since the data is for internal use only | |
1387 * at this point. | |
1388 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1389 memset( &( ((ALbyte*)(data->sample->buffer))[bytes_decoded] ), silence_value, data->sample->buffer_size - bytes_decoded); |
0 | 1390 /* Now reset the bytes_decoded to reflect the entire |
1391 * buffer to tell alBufferData what our full size is. | |
1392 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1393 /* |
0 | 1394 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
|
1395 */ |
0 | 1396 bytes_decoded = data->sample->buffer_size; |
1397 } | |
1398 /*********** END EXPERIMENT ******************************/ | |
1399 /******* END REMOVE ME ********************************/ | |
1400 #endif | |
1401 | |
1402 /* Now copy the data to the OpenAL buffer */ | |
1403 /* We can't just set a pointer because the API needs | |
1404 * its own copy to assist hardware acceleration */ | |
1405 alBufferData(buffer, | |
1406 TranslateFormat(&data->sample->desired), | |
1407 data->sample->buffer, | |
1408 bytes_decoded, | |
1409 data->sample->desired.rate | |
1410 ); | |
1411 if( (error = alGetError()) != AL_NO_ERROR) | |
1412 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1413 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1414 return 0; |
1415 } | |
1416 | |
1417 /* If we need to, copy the data also to the access area | |
1418 * (the function will do the check for us) | |
1419 */ | |
1420 CopyDataToAccessBuffer(data, bytes_decoded, buffer); | |
1421 return bytes_decoded; | |
1422 } | |
1423 | |
1424 | |
1425 | |
1426 | |
1427 /******************** EXPERIEMENT **************************** | |
1428 * Test function to force maximum buffer filling during loops | |
1429 * REMOVE LATER | |
1430 *********************************************/ | |
1431 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1432 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
|
1433 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1434 ALint bytes_decoded; |
0 | 1435 ALenum error; |
1436 if(NULL == data) | |
1437 { | |
1438 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1439 return -1; | |
1440 } | |
1441 | |
1442 if(AL_FALSE == alIsBuffer(buffer)) | |
1443 { | |
1444 fprintf(stderr, "NOT A BUFFER>>>>>>>>>>>>>>>\n"); | |
1445 return -1; | |
1446 } | |
1447 fprintf(stderr, "Entered GetMoreData222222: buffer id is %d\n", buffer); | |
1448 | |
1449 /* | |
1450 fprintf(stderr, "Decode in GetMoreData\n"); | |
1451 */ | |
1452 | |
1453 #if 0 | |
1454 if(buffer%2 == 1) | |
1455 { | |
1456 fprintf(stderr, "Setting buffer size to 16384\n"); | |
1457 Sound_SetBufferSize(data->sample, 16384); | |
1458 } | |
1459 else | |
1460 { | |
1461 fprintf(stderr, "Setting buffer size to 8192\n"); | |
1462 Sound_SetBufferSize(data->sample, 8192); | |
1463 } | |
1464 #endif | |
1465 | |
1466 bytes_decoded = Sound_Decode(data->sample); | |
1467 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1468 { | |
1469 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1470 ALmixer_SetError(Sound_GetError()); | |
1471 /* | |
1472 Sound_FreeSample(data->sample); | |
1473 */ | |
1474 return -1; | |
1475 } | |
1476 /* Don't forget to add check for EOF */ | |
1477 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1478 if(0 == bytes_decoded) | |
1479 { | |
1480 #if 1 | |
1481 fprintf(stderr, "Hit eof while trying to buffer\n"); | |
1482 data->eof = 1; | |
1483 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1484 { | |
1485 fprintf(stderr, "\tEOF flag\n"); | |
1486 } | |
1487 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1488 { | |
1489 fprintf(stderr, "\tCanSeek flag\n"); | |
1490 } | |
1491 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1492 { | |
1493 fprintf(stderr, "\tEAGAIN flag\n"); | |
1494 } | |
1495 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1496 { | |
1497 fprintf(stderr, "\tNONE flag\n"); | |
1498 } | |
1499 #endif | |
1500 return 0; | |
1501 } | |
1502 | |
1503 if(bytes_decoded < 16384) | |
1504 { | |
1505 char* tempbuffer1 = (char*)malloc(16384); | |
1506 char* tempbuffer2 = (char*)malloc(16384); | |
1507 int retval; | |
1508 memcpy(tempbuffer1, data->sample->buffer, bytes_decoded); | |
1509 retval = Sound_SetBufferSize(data->sample, 16384-bytes_decoded); | |
1510 if(retval == 1) | |
1511 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1512 ALuint new_bytes; |
0 | 1513 Sound_Rewind(data->sample); |
1514 new_bytes = Sound_Decode(data->sample); | |
1515 fprintf(stderr, "Orig bytes: %d, Make up bytes_decoded=%d, total=%d\n", bytes_decoded, new_bytes, new_bytes+bytes_decoded); | |
1516 | |
1517 memcpy(tempbuffer2, data->sample->buffer, new_bytes); | |
1518 | |
1519 retval = Sound_SetBufferSize(data->sample, 16384); | |
1520 fprintf(stderr, "Finished reset...now danger copy\n"); | |
1521 memcpy(data->sample->buffer, tempbuffer1,bytes_decoded); | |
1522 | |
1523 fprintf(stderr, "Finished reset...now danger copy2\n"); | |
1524 memcpy( &( ((char*)(data->sample->buffer))[bytes_decoded] ), tempbuffer2, new_bytes); | |
1525 | |
1526 fprintf(stderr, "Finished \n"); | |
1527 | |
1528 free(tempbuffer1); | |
1529 free(tempbuffer2); | |
1530 bytes_decoded += new_bytes; | |
1531 fprintf(stderr, "ASSERT bytes should equal 16384: %d\n", bytes_decoded); | |
1532 } | |
1533 else | |
1534 { | |
1535 fprintf(stderr, "Experiment failed: %s\n", Sound_GetError()); | |
1536 } | |
1537 } | |
1538 | |
1539 /* Now copy the data to the OpenAL buffer */ | |
1540 /* We can't just set a pointer because the API needs | |
1541 * its own copy to assist hardware acceleration */ | |
1542 alBufferData(buffer, | |
1543 TranslateFormat(&data->sample->desired), | |
1544 data->sample->buffer, | |
1545 bytes_decoded, | |
1546 data->sample->desired.rate | |
1547 ); | |
1548 if( (error = alGetError()) != AL_NO_ERROR) | |
1549 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1550 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1551 return -1; |
1552 } | |
1553 | |
1554 fprintf(stderr, "GetMoreData2222 returning %d bytes decoded\n", bytes_decoded); | |
1555 return bytes_decoded; | |
1556 } | |
1557 #endif | |
1558 | |
1559 /************ END EXPERIEMENT - REMOVE ME *************************/ | |
1560 | |
1561 | |
1562 | |
1563 | |
1564 | |
1565 | |
1566 | |
1567 | |
1568 | |
1569 /* This function will look up the source for the corresponding channel */ | |
1570 /* 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
|
1571 static ALuint Internal_GetSource(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1572 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1573 ALint i; |
0 | 1574 /* Make sure channel is in bounds */ |
1575 if(channel >= Number_of_Channels_global) | |
1576 { | |
1577 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); | |
1578 return 0; | |
1579 } | |
1580 /* If the user specified -1, then return the an available source */ | |
1581 if(channel < 0) | |
1582 { | |
1583 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1584 { | |
1585 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1586 { | |
1587 return ALmixer_Channel_List[i].alsource; | |
1588 } | |
1589 } | |
1590 /* If we get here, all sources are in use */ | |
1591 /* Error message seems too harsh | |
1592 ALmixer_SetError("All sources are in use"); | |
1593 */ | |
1594 return 0; | |
1595 } | |
1596 /* Last case: Return the source for the channel */ | |
1597 return ALmixer_Channel_List[channel].alsource; | |
1598 } | |
1599 | |
1600 /* 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
|
1601 static ALint Internal_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1602 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1603 ALint i; |
0 | 1604 /* Only the first value is used for the key */ |
1605 Source_Map key = { 0, 0 }; | |
1606 Source_Map* found_item = NULL; | |
1607 key.source = source; | |
1608 | |
1609 /* If the source is 0, look up the first available channel */ | |
1610 if(0 == source) | |
1611 { | |
1612 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1613 { | |
1614 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1615 { | |
1616 return i; | |
1617 } | |
1618 } | |
1619 /* If we get here, all sources are in use */ | |
1620 /* Error message seems too harsh | |
1621 ALmixer_SetError("All channels are in use"); | |
1622 */ | |
1623 return -1; | |
1624 } | |
1625 | |
1626 | |
1627 /* Else, look up the source and return the channel */ | |
1628 if(AL_FALSE == alIsSource(source)) | |
1629 { | |
1630 ALmixer_SetError("Is not a source"); | |
1631 return -1; | |
1632 } | |
1633 | |
1634 /* Use the ANSI C binary search feature (yea!) */ | |
1635 found_item = (Source_Map*)bsearch(&key, Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
1636 if(NULL == found_item) | |
1637 { | |
1638 ALmixer_SetError("Source is valid but not registered with ALmixer (to a channel)"); | |
1639 return -1; | |
1640 } | |
1641 return found_item->channel; | |
1642 } | |
1643 | |
1644 | |
1645 | |
1646 /* This function will find the first available channel (not in use) | |
1647 * from the specified start channel. Reserved channels to not qualify | |
1648 * as available. | |
1649 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1650 static ALint Internal_FindFreeChannel(ALint start_channel) |
0 | 1651 { |
1652 /* Start at the number of reserved so we skip over | |
1653 * all the reserved channels. | |
1654 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1655 ALint i = Number_of_Reserve_Channels_global; |
0 | 1656 /* Quick check to see if we're out of bounds */ |
1657 if(start_channel >= Number_of_Channels_global) | |
1658 { | |
1659 return -1; | |
1660 } | |
1661 | |
1662 /* If the start channel is even higher than the reserved, | |
1663 * then start at the higher value. | |
1664 */ | |
1665 if(start_channel > Number_of_Reserve_Channels_global) | |
1666 { | |
1667 i = start_channel; | |
1668 } | |
1669 | |
1670 /* i has already been set */ | |
1671 for( ; i<Number_of_Channels_global; i++) | |
1672 { | |
1673 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1674 { | |
1675 return i; | |
1676 } | |
1677 } | |
1678 /* If we get here, all sources are in use */ | |
1679 return -1; | |
1680 } | |
1681 | |
1682 | |
1683 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1684 /* 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
|
1685 * or 0 for error |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1686 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1687 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
|
1688 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1689 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1690 ALint counter = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1691 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1692 ALint buffers_still_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1693 ALint buffers_processed; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1694 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1695 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1696 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1697 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
|
1698 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1699 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1700 /* 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
|
1701 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1702 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1703 /* 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
|
1704 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
|
1705 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1706 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1707 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1708 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1709 fprintf(stderr, "14Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1710 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1711 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1712 /* 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
|
1713 * 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
|
1714 * 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
|
1715 * 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
|
1716 * 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
|
1717 * 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
|
1718 * 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
|
1719 * 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
|
1720 * 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
|
1721 * 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
|
1722 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1723 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1724 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1725 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1726 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1727 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1728 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1729 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1730 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
|
1731 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1732 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
|
1733 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1734 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1735 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1736 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1737 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1738 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1739 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1740 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1741 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1742 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
|
1743 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1744 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
|
1745 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1746 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1747 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1748 /* 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
|
1749 * to clear the source |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1750 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1751 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
|
1752 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1753 alSourcei(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1754 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1755 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1756 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1757 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1758 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
|
1759 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1760 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
|
1761 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1762 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1763 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1764 } |
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 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
|
1767 |
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
|
1768 /* 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
|
1769 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
|
1770 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1771 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1772 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1773 counter++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1774 } |
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 /* 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
|
1777 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1778 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1779 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1780 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
|
1781 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1782 /* 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
|
1783 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
|
1784 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1785 alSourceStop(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1786 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1787 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1788 fprintf(stderr, "19Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1789 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1790 } |
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 /* 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
|
1793 * 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
|
1794 * 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
|
1795 * 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
|
1796 * 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
|
1797 * 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
|
1798 * 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
|
1799 * 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
|
1800 * 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
|
1801 * 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
|
1802 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1803 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1804 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1805 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1806 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1807 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1808 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1809 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1810 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
|
1811 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1812 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
|
1813 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1814 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1815 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1816 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1817 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1818 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1819 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1820 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1821 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1822 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
|
1823 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1824 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
|
1825 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1826 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1827 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1828 /* 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
|
1829 * to clear the source |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1830 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1831 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
|
1832 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1833 alSourcei(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1834 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1835 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1836 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1837 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1838 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
|
1839 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1840 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
|
1841 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1842 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1843 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1844 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1845 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1846 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
|
1847 |
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
|
1848 /* 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
|
1849 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
|
1850 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1851 Clean_Channel(i); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1852 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1853 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1854 /* Increment the counter */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1855 counter++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1856 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1857 /* 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
|
1858 * are bugs. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1859 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1860 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1861 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1862 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1863 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1864 / * 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
|
1865 * data will get messed up * / |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1866 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1867 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1868 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1869 /* Just in case */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1870 Is_Playing_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1871 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1872 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1873 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1874 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1875 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1876 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1877 return counter; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1878 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1879 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1880 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1881 /* Will return the 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
|
1882 * 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
|
1883 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1884 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
|
1885 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1886 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1887 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1888 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1889 /* 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
|
1890 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
|
1891 } |
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 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1894 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1895 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1896 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
|
1897 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1898 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1899 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
|
1900 } |
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 |
0 | 1903 |
1904 /* Note: Behaves, almost like SDL_mixer, but keep in mind | |
1905 * that there is no "music" channel anymore, so 0 | |
1906 * will remove everything. (Note, I no longer allow 0 | |
1907 * so it gets set to the default number.) | |
1908 * Also, callbacks for deleted channels will not be called. | |
1909 * I really need to do error checking, for realloc and | |
1910 * GenSources, but reversing the damage is too painful | |
1911 * for me to think about at the moment, so it's not in here. | |
1912 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1913 static ALint Internal_AllocateChannels(ALint numchans) |
0 | 1914 { |
1915 ALenum error; | |
1916 int i; | |
1917 /* Return info */ | |
1918 if(numchans < 0) | |
1919 { | |
1920 return Number_of_Channels_global; | |
1921 } | |
1922 if(0 == numchans) | |
1923 { | |
1924 numchans = ALMIXER_DEFAULT_NUM_CHANNELS; | |
1925 } | |
1926 /* No change */ | |
1927 if(numchans == Number_of_Channels_global) | |
1928 { | |
1929 return Number_of_Channels_global; | |
1930 } | |
1931 /* We need to increase the number of channels */ | |
1932 if(numchans > Number_of_Channels_global) | |
1933 { | |
1934 /* Not sure how safe this is, but SDL_mixer does it | |
1935 * the same way */ | |
1936 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1937 | |
1938 /* Allocate memory for the list of sources that map to the channels */ | |
1939 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
1940 | |
1941 for(i=Number_of_Channels_global; i<numchans; i++) | |
1942 { | |
1943 Init_Channel(i); | |
1944 /* Generate a new source and associate it with the channel */ | |
1945 alGenSources(1, &ALmixer_Channel_List[i].alsource); | |
1946 if((error = alGetError()) != AL_NO_ERROR) | |
1947 { | |
1948 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
|
1949 alGetString(error)); |
0 | 1950 } |
1951 /* Copy the source so the SourceMap has it too */ | |
1952 Source_Map_List[i].source = ALmixer_Channel_List[i].alsource; | |
1953 Source_Map_List[i].channel = i; | |
1954 /* Clean the channel because there are some things that need to | |
1955 * be done that can't happen until the source is set | |
1956 */ | |
1957 Clean_Channel(i); | |
1958 } | |
1959 | |
1960 /* The Source_Map_List must be sorted by source for binary searches | |
1961 */ | |
1962 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
1963 | |
1964 Number_of_Channels_global = numchans; | |
1965 return numchans; | |
1966 } | |
1967 /* Need to remove channels. This might be dangerous */ | |
1968 if(numchans < Number_of_Channels_global) | |
1969 { | |
1970 for(i=numchans; i<Number_of_Channels_global; i++) | |
1971 { | |
1972 /* Halt the channel */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1973 Internal_HaltChannel(i, AL_FALSE); |
0 | 1974 |
1975 /* Delete source associated with the channel */ | |
1976 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
1977 if((error = alGetError()) != AL_NO_ERROR) | |
1978 { | |
1979 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
|
1980 alGetString(error)); |
0 | 1981 } |
1982 } | |
1983 | |
1984 | |
1985 /* Not sure how safe this is, but SDL_mixer does it | |
1986 * the same way */ | |
1987 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1988 | |
1989 /* The tricky part is that we must remove the entries | |
1990 * in the source map that correspond to the deleted channels. | |
1991 * We'll resort the map by channels so we can pick them off | |
1992 * in order. | |
1993 */ | |
1994 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map_by_channel); | |
1995 | |
1996 /* Deallocate memory for the list of sources that map to the channels */ | |
1997 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
1998 | |
1999 /* Now resort the map by source and the correct num of chans */ | |
2000 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
2001 | |
2002 /* Reset the number of channels */ | |
2003 Number_of_Channels_global = numchans; | |
2004 return numchans; | |
2005 } | |
2006 /* Shouldn't ever reach here */ | |
2007 return -1; | |
2008 | |
2009 } | |
2010 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2011 static ALint Internal_ReserveChannels(ALint num) |
0 | 2012 { |
2013 /* Can't reserve more than the max num of channels */ | |
2014 /* Actually, I'll allow it for people who just want to | |
2015 * set the value really high to effectively disable | |
2016 * auto-assignment | |
2017 */ | |
2018 | |
2019 /* Return the current number of reserved channels */ | |
2020 if(num < 0) | |
2021 { | |
2022 return Number_of_Reserve_Channels_global; | |
2023 } | |
2024 Number_of_Reserve_Channels_global = num; | |
2025 return Number_of_Reserve_Channels_global; | |
2026 } | |
2027 | |
2028 | |
2029 /* This will rewind the SDL_Sound sample for streamed | |
2030 * samples and start buffering up the data for the next | |
2031 * playback. This may require samples to be halted | |
2032 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2033 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
|
2034 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2035 ALint retval = 0; |
0 | 2036 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2037 ALint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2038 ALint i; |
0 | 2039 */ |
2040 if(NULL == data) | |
2041 { | |
2042 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
|
2043 return AL_FALSE; |
0 | 2044 } |
2045 | |
2046 | |
2047 /* Might have to require Halt */ | |
2048 /* Okay, we assume Halt or natural stop has already | |
2049 * cleared the data buffers | |
2050 */ | |
2051 if(data->in_use) | |
2052 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2053 /* |
0 | 2054 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
|
2055 */ |
0 | 2056 /* |
2057 ALmixer_SetError("Data is in use. Cannot rewind unless all sources using the data are halted\n"); | |
2058 return -1; | |
2059 */ | |
2060 } | |
2061 | |
2062 | |
2063 /* Because Seek can alter things even in predecoded data, | |
2064 * decoded data must also be rewound | |
2065 */ | |
2066 if(data->decoded_all) | |
2067 { | |
2068 data->eof = 0; | |
2069 | |
2070 #if 0 | |
2071 #if defined(DISABLE_PREDECODED_SEEK) | |
2072 /* 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
|
2073 return AL_TRUE; |
0 | 2074 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) |
2075 /* This case is if the Sound_Sample has been deleted. | |
2076 * It assumes the data is already at the beginning. | |
2077 */ | |
2078 if(NULL == data->sample) | |
2079 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2080 return AL_TRUE; |
0 | 2081 } |
2082 /* Else, the sample has already been reallocated, | |
2083 * and we can fall to normal behavior | |
2084 */ | |
2085 #endif | |
2086 #endif | |
2087 /* If access_data, was enabled, the sound sample | |
2088 * still exists and we can do stuff. | |
2089 * If it's NULL, we can't do anything, but | |
2090 * it should already be "rewound". | |
2091 */ | |
2092 if(NULL == data->sample) | |
2093 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2094 return AL_TRUE; |
0 | 2095 } |
2096 /* Else, the sample has already been reallocated, | |
2097 * and we can fall to normal behavior | |
2098 */ | |
2099 | |
2100 Set_Predecoded_Seek_Position(data, 0); | |
2101 /* | |
2102 return data->total_bytes; | |
2103 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2104 return AL_TRUE; |
0 | 2105 } |
2106 | |
2107 /* Remaining stuff for streamed data */ | |
2108 | |
2109 data->eof = 0; | |
2110 retval = Sound_Rewind(data->sample); | |
2111 if(0 == retval) | |
2112 { | |
2113 ALmixer_SetError( Sound_GetError() ); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2114 return AL_FALSE; |
0 | 2115 } |
2116 #if 0 | |
2117 /* Clear error */ | |
2118 alGetError(); | |
2119 for(i=0; i<data->num_buffers; i++) | |
2120 { | |
2121 bytes_returned = GetMoreData(data, data->buffer[i]); | |
2122 if(-1 == bytes_returned) | |
2123 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2124 return AL_FALSE; |
0 | 2125 } |
2126 else if(0 == bytes_returned) | |
2127 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2128 return AL_FALSE; |
0 | 2129 } |
2130 retval += bytes_returned; | |
2131 | |
2132 } | |
2133 #endif | |
2134 | |
2135 | |
2136 | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2137 return AL_TRUE; |
0 | 2138 } |
2139 | |
2140 | |
2141 | |
2142 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2143 static ALint Internal_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2144 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2145 ALint retval = 0; |
0 | 2146 ALenum error; |
2147 ALint state; | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2148 ALint running_count = 0; |
0 | 2149 |
2150 if(channel >= Number_of_Channels_global) | |
2151 { | |
2152 ALmixer_SetError("Cannot rewind channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2153 return -1; | |
2154 } | |
2155 | |
2156 if((error = alGetError()) != AL_NO_ERROR) | |
2157 { | |
2158 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
|
2159 alGetString(error)); |
0 | 2160 } |
2161 /* Clear error */ | |
2162 alGetError(); | |
2163 | |
2164 /* If the user specified a specific channel */ | |
2165 if(channel >= 0) | |
2166 { | |
2167 /* only need to process channel if in use */ | |
2168 if(ALmixer_Channel_List[channel].channel_in_use) | |
2169 { | |
2170 | |
2171 /* What should I do? Do I just rewind the channel | |
2172 * or also rewind the data? Since the data is | |
2173 * shared, let's make it the user's responsibility | |
2174 * to rewind the data. | |
2175 */ | |
2176 if(ALmixer_Channel_List[channel].almixer_data->decoded_all) | |
2177 { | |
2178 alGetSourcei( | |
2179 ALmixer_Channel_List[channel].alsource, | |
2180 AL_SOURCE_STATE, &state | |
2181 ); | |
2182 if((error = alGetError()) != AL_NO_ERROR) | |
2183 { | |
2184 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
|
2185 alGetString(error)); |
0 | 2186 } |
2187 alSourceRewind(ALmixer_Channel_List[channel].alsource); | |
2188 if((error = alGetError()) != AL_NO_ERROR) | |
2189 { | |
2190 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2191 alGetString(error) ); |
0 | 2192 retval = -1; |
2193 } | |
2194 /* Need to resume playback if it was originally playing */ | |
2195 if(AL_PLAYING == state) | |
2196 { | |
2197 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2198 if((error = alGetError()) != AL_NO_ERROR) | |
2199 { | |
2200 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2201 alGetString(error) ); |
0 | 2202 retval = -1; |
2203 } | |
2204 } | |
2205 else if(AL_PAUSED == state) | |
2206 { | |
2207 /* HACK: The problem is that when paused, after | |
2208 * the Rewind, I can't get it off the INITIAL | |
2209 * state without restarting | |
2210 */ | |
2211 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2212 if((error = alGetError()) != AL_NO_ERROR) | |
2213 { | |
2214 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
|
2215 alGetString(error)); |
0 | 2216 } |
2217 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2218 if((error = alGetError()) != AL_NO_ERROR) | |
2219 { | |
2220 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2221 alGetString(error) ); |
0 | 2222 retval = -1; |
2223 } | |
2224 } | |
2225 } | |
2226 else | |
2227 { | |
2228 /* Streamed data is different. Rewinding the channel | |
2229 * does no good. Rewinding the data will have an | |
2230 * effect, but it will be lagged based on how | |
2231 * much data is queued. Recommend users call Halt | |
2232 * before rewind if they want immediate results. | |
2233 */ | |
2234 retval = Internal_RewindData(ALmixer_Channel_List[channel].almixer_data); | |
2235 } | |
2236 } | |
2237 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2238 /* The user wants to rewind all channels */ |
0 | 2239 else |
2240 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2241 ALint i; |
0 | 2242 for(i=0; i<Number_of_Channels_global; i++) |
2243 { | |
2244 /* only need to process channel if in use */ | |
2245 if(ALmixer_Channel_List[i].channel_in_use) | |
2246 { | |
2247 /* What should I do? Do I just rewind the channel | |
2248 * or also rewind the data? Since the data is | |
2249 * shared, let's make it the user's responsibility | |
2250 * to rewind the data. | |
2251 */ | |
2252 if(ALmixer_Channel_List[i].almixer_data->decoded_all) | |
2253 { | |
2254 alGetSourcei( | |
2255 ALmixer_Channel_List[i].alsource, | |
2256 AL_SOURCE_STATE, &state | |
2257 ); | |
2258 if((error = alGetError()) != AL_NO_ERROR) | |
2259 { | |
2260 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
|
2261 alGetString(error)); |
0 | 2262 } |
2263 alSourceRewind(ALmixer_Channel_List[i].alsource); | |
2264 if((error = alGetError()) != AL_NO_ERROR) | |
2265 { | |
2266 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2267 alGetString(error) ); |
0 | 2268 retval = -1; |
2269 } | |
2270 /* Need to resume playback if it was originally playing */ | |
2271 if(AL_PLAYING == state) | |
2272 { | |
2273 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2274 if((error = alGetError()) != AL_NO_ERROR) | |
2275 { | |
2276 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2277 alGetString(error) ); |
0 | 2278 retval = -1; |
2279 } | |
2280 } | |
2281 else if(AL_PAUSED == state) | |
2282 { | |
2283 /* HACK: The problem is that when paused, after | |
2284 * the Rewind, I can't get it off the INITIAL | |
2285 * state without restarting | |
2286 */ | |
2287 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2288 if((error = alGetError()) != AL_NO_ERROR) | |
2289 { | |
2290 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
|
2291 alGetString(error)); |
0 | 2292 } |
2293 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2294 if((error = alGetError()) != AL_NO_ERROR) | |
2295 { | |
2296 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2297 alGetString(error) ); |
0 | 2298 retval = -1; |
2299 } | |
2300 } | |
2301 } | |
2302 else | |
2303 { | |
2304 /* Streamed data is different. Rewinding the channel | |
2305 * does no good. Rewinding the data will have an | |
2306 * effect, but it will be lagged based on how | |
2307 * much data is queued. Recommend users call Halt | |
2308 * before rewind if they want immediate results. | |
2309 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2310 running_count += Internal_RewindData(ALmixer_Channel_List[i].almixer_data); |
0 | 2311 } |
2312 } | |
2313 } | |
2314 } | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2315 if(-1 == retval) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2316 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2317 return -1; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2318 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2319 else |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2320 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2321 return running_count; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2322 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2323 |
0 | 2324 } |
2325 | |
2326 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2327 static ALint Internal_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2328 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2329 ALint channel; |
0 | 2330 if(0 == source) |
2331 { | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
2332 return Internal_RewindChannel(-1); |
0 | 2333 } |
2334 | |
2335 channel = Internal_GetChannel(source); | |
2336 if(-1 == channel) | |
2337 { | |
2338 ALmixer_SetError("Cannot rewind source: %s", ALmixer_GetError()); | |
2339 return 0; | |
2340 } | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
2341 return Internal_RewindChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2342 } |
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 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
|
2349 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2350 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2351 int ret_flag = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2352 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2353 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2354 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
|
2355 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2356 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2357 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2358 /* 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
|
2359 * 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
|
2360 * 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
|
2361 * 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
|
2362 * 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
|
2363 * to prevent sharing |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2364 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2365 if(0 == data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2366 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2367 if(data->in_use) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2368 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2369 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
|
2370 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2371 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2372 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2373 /* 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
|
2374 * This mainly affects streamed files, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2375 * so the check is placed here |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2376 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2377 if(data->eof) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2378 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2379 if( -1 == Internal_RewindData(data) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2380 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2381 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
|
2382 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2383 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2384 } |
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 /* 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
|
2387 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2388 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2389 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2390 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
|
2391 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2392 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
|
2393 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2394 channel = i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2395 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2396 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2397 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2398 /* 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
|
2399 if(i == Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2400 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2401 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
|
2402 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2403 } |
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 /* 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
|
2406 * out of bounds or in use */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2407 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2408 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2409 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2410 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2411 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
|
2412 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2413 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2414 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
|
2415 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2416 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
|
2417 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2418 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2419 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2420 /* 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
|
2421 if(loops < -1) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2422 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2423 loops = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2424 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2425 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2426 /* 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
|
2427 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2428 /* 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
|
2429 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
|
2430 data->in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2431 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2432 /* 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
|
2433 * (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
|
2434 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2435 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
|
2436 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
|
2437 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
|
2438 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2439 /* 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
|
2440 if(ticks < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2441 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2442 ALmixer_Channel_List[channel].expire_ticks = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2443 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2444 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2445 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2446 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
|
2447 } |
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 ALmixer_Channel_List[channel].halted = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2451 ALmixer_Channel_List[channel].paused = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2452 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2453 /* 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
|
2454 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2455 if( (-1 == loops) && (data->decoded_all) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2456 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2457 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
|
2458 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2459 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2460 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2461 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
|
2462 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2463 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2464 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2465 fprintf(stderr, "13Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2466 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2467 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2468 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2469 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2470 /* Because of the corner case, predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2471 * 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
|
2472 * Streams do not have this problem |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2473 * 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
|
2474 * avoid the conflict. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2475 * 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
|
2476 * Since streams, cannot share, only predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2477 * files are affected |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2478 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2479 if(data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2480 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2481 /* 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
|
2482 * 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
|
2483 * 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
|
2484 * must be +1 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2485 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2486 if(-1 == loops) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2487 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2488 /* -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
|
2489 * to add +1 to it */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2490 ALmixer_Channel_List[channel].loops = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2491 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
|
2492 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2493 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2494 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2495 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
|
2496 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
|
2497 } |
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2500 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2501 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2502 /* 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
|
2503 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
|
2504 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2505 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2506 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2507 /* 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
|
2508 /* 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
|
2509 * 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
|
2510 * 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
|
2511 * 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
|
2512 * 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
|
2513 * 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
|
2514 * easier to maintain. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2515 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2516 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2517 /* Clear the error flag */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2518 alGetError(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2519 if(data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2520 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2521 /* Bind the data to the source */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2522 alSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2523 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2524 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2525 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2526 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2527 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2528 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
|
2529 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2530 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2531 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2532 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2533 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2534 /* 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
|
2535 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
|
2536 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2537 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2538 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2539 /* 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
|
2540 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2541 ALuint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2542 ALuint j; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2543 data->num_buffers_in_use=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2544 /****** MODIFICATION must go here *********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2545 /* 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
|
2546 * 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
|
2547 * 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
|
2548 * 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
|
2549 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2550 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2551 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2552 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2553 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2554 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2555 /* No data or error */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2556 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
|
2557 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2558 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2559 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2560 /* 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
|
2561 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2562 |
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 /* 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
|
2565 * 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
|
2566 * before the last buffer is filled. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2567 * 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
|
2568 * 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
|
2569 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2570 |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2571 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2572 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
|
2573 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2574 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
|
2575 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2576 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2577 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
|
2578 fprintf(stderr, ">>>>>>>>>>>>>>>>>>HACK for GetMoreData2\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2579 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2580 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2581 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2582 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2583 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2584 * 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
|
2585 * 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
|
2586 * 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
|
2587 * 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
|
2588 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2589 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2590 if(bytes_returned < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2591 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2592 /* Error found */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2593 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
|
2594 /* 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
|
2595 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2596 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2597 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2598 else if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2599 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2600 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2601 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2602 /* No more data to buffer */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2603 /* Check for loops */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2604 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
|
2605 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2606 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2607 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
|
2608 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2609 if(0 == Sound_Rewind(data->sample)) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2610 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2611 fprintf(stderr, "error in rewind\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2612 ALmixer_SetError( Sound_GetError() ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2613 ALmixer_Channel_List[channel].loops = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2614 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2615 /* 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
|
2616 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2617 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2618 /* 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
|
2619 data->eof = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2620 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
|
2621 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2622 ALmixer_Channel_List[channel].loops--; |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2623 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2624 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
|
2625 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2626 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2627 /* 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
|
2628 * 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
|
2629 * into an infinite loop |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2630 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2631 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2632 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2633 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2634 if(bytes_returned <= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2635 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2636 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
|
2637 /* 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
|
2638 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2639 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2640 } |
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2643 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2644 /* 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
|
2645 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2646 } |
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 /* 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
|
2649 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2650 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2651 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2652 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
|
2653 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2654 data->num_buffers_in_use); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2655 */ |
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 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2658 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2659 data->num_buffers_in_use, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2660 data->buffer); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2661 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2662 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2663 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
|
2664 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2665 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2666 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2667 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2668 /* 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
|
2669 * 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
|
2670 * 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
|
2671 * 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
|
2672 * "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
|
2673 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2674 if(data->circular_buffer_queue != NULL) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2675 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2676 ALuint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2677 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2678 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
|
2679 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2680 // fprintf(stderr, "56c: CircularQueue_PushBack.\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2681 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
|
2682 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2683 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2684 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
|
2685 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
|
2686 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2687 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2688 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2689 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2690 fprintf(stderr, "Queue in PlayTimed\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2691 CircularQueueUnsignedInt_Print(data->circular_buffer_queue); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2692 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2693 */ |
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 /****** END **********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2699 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2700 /* 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
|
2701 * so now we can play |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2702 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2703 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2704 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2705 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2706 ALmixer_SetError("Play failed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2707 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2708 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2709 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2710 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2711 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2712 /* 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
|
2713 Is_Playing_global++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2714 if(-1 == ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2715 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2716 fprintf(stderr, "BACKDOOR ERROR >>>>>>>>>>>>>>>>>>\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2717 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2718 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2719 return channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2720 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2721 |
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 /* 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
|
2724 * 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
|
2725 * 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
|
2726 * PlayChannelTimed() function call. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2727 * 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
|
2728 * 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
|
2729 * 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
|
2730 * 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
|
2731 * 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
|
2732 * 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
|
2733 * 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
|
2734 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2735 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
|
2736 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2737 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2738 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2739 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2740 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2741 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
|
2742 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2743 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2744 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2745 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2746 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2747 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2748 return Internal_GetSource(retval); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2749 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2750 } |
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 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2753 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2754 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2755 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
|
2756 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2757 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2758 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
|
2759 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2760 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2761 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2762 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2763 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2764 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2765 return source; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2766 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2767 /* make compiler happy */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2768 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2769 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2770 |
0 | 2771 |
2772 | |
2773 | |
2774 /* Returns the channel or number of channels actually paused */ | |
2775 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2776 static ALint Internal_PauseChannel(ALint channel) |
0 | 2777 { |
2778 ALenum error; | |
2779 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2780 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2781 ALint counter = 0; |
0 | 2782 |
2783 if(channel >= Number_of_Channels_global) | |
2784 { | |
2785 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2786 return -1; | |
2787 } | |
2788 | |
2789 if((error = alGetError()) != AL_NO_ERROR) | |
2790 { | |
2791 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
|
2792 alGetString(error)); |
0 | 2793 } |
2794 /* Clear error */ | |
2795 alGetError(); | |
2796 | |
2797 /* If the user specified a specific channel */ | |
2798 if(channel >= 0) | |
2799 { | |
2800 /* only need to process channel if in use */ | |
2801 if(ALmixer_Channel_List[channel].channel_in_use) | |
2802 { | |
2803 /* We don't want to repause if already | |
2804 * paused because the fadeout/expire | |
2805 * timing will get messed up | |
2806 */ | |
2807 alGetSourcei( | |
2808 ALmixer_Channel_List[channel].alsource, | |
2809 AL_SOURCE_STATE, &state | |
2810 ); | |
2811 if((error = alGetError()) != AL_NO_ERROR) | |
2812 { | |
2813 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
|
2814 alGetString(error)); |
0 | 2815 } |
2816 if(AL_PLAYING == state) | |
2817 { | |
2818 /* Count the actual number of channels being paused */ | |
2819 counter++; | |
2820 | |
2821 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2822 if((error = alGetError()) != AL_NO_ERROR) | |
2823 { | |
2824 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2825 alGetString(error) ); |
0 | 2826 retval = -1; |
2827 } | |
2828 /* We need to pause the expire time count down */ | |
2829 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
2830 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2831 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2832 ALuint diff_time; |
0 | 2833 diff_time = current_time - |
2834 ALmixer_Channel_List[channel].start_time; | |
2835 /* When we unpause, we will want to reset | |
2836 * the start time so we can continue | |
2837 * to base calculations off GetTicks(). | |
2838 * This means we need to subtract the amount | |
2839 * of time already used up from expire_ticks. | |
2840 */ | |
2841 ALmixer_Channel_List[channel].expire_ticks = | |
2842 ALmixer_Channel_List[channel].expire_ticks - | |
2843 diff_time; | |
2844 /* Because -1 is a special value, we can't | |
2845 * allow the time to go negative | |
2846 */ | |
2847 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2848 { | |
2849 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2850 } | |
2851 } | |
2852 /* Do the same as expire time for fading */ | |
2853 if(ALmixer_Channel_List[channel].fade_enabled) | |
2854 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2855 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2856 ALuint diff_time; |
0 | 2857 diff_time = current_time - |
2858 ALmixer_Channel_List[channel].fade_start_time; | |
2859 /* When we unpause, we will want to reset | |
2860 * the start time so we can continue | |
2861 * to base calculations off GetTicks(). | |
2862 * This means we need to subtract the amount | |
2863 * of time already used up from expire_ticks. | |
2864 */ | |
2865 ALmixer_Channel_List[channel].fade_expire_ticks = | |
2866 ALmixer_Channel_List[channel].fade_expire_ticks - | |
2867 diff_time; | |
2868 /* Don't allow the time to go negative */ | |
2869 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2870 { | |
2871 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2872 } | |
2873 } /* End fade check */ | |
2874 } /* End if PLAYING */ | |
2875 } /* End If in use */ | |
2876 } /* End specific channel */ | |
2877 /* The user wants to halt all channels */ | |
2878 else | |
2879 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2880 ALint i; |
0 | 2881 for(i=0; i<Number_of_Channels_global; i++) |
2882 { | |
2883 /* only need to process channel if in use */ | |
2884 if(ALmixer_Channel_List[i].channel_in_use) | |
2885 { | |
2886 /* We don't want to repause if already | |
2887 * paused because the fadeout/expire | |
2888 * timing will get messed up | |
2889 */ | |
2890 alGetSourcei( | |
2891 ALmixer_Channel_List[i].alsource, | |
2892 AL_SOURCE_STATE, &state | |
2893 ); | |
2894 if((error = alGetError()) != AL_NO_ERROR) | |
2895 { | |
2896 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
|
2897 alGetString(error)); |
0 | 2898 } |
2899 if(AL_PLAYING == state) | |
2900 { | |
2901 /* Count the actual number of channels being paused */ | |
2902 counter++; | |
2903 | |
2904 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2905 if((error = alGetError()) != AL_NO_ERROR) | |
2906 { | |
2907 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2908 alGetString(error) ); |
0 | 2909 retval = -1; |
2910 } | |
2911 /* We need to pause the expire time count down */ | |
2912 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
2913 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2914 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2915 ALuint diff_time; |
0 | 2916 diff_time = current_time - |
2917 ALmixer_Channel_List[i].start_time; | |
2918 /* When we unpause, we will want to reset | |
2919 * the start time so we can continue | |
2920 * to base calculations off GetTicks(). | |
2921 * This means we need to subtract the amount | |
2922 * of time already used up from expire_ticks. | |
2923 */ | |
2924 ALmixer_Channel_List[i].expire_ticks = | |
2925 ALmixer_Channel_List[i].expire_ticks - | |
2926 diff_time; | |
2927 /* Because -1 is a special value, we can't | |
2928 * allow the time to go negative | |
2929 */ | |
2930 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2931 { | |
2932 ALmixer_Channel_List[i].expire_ticks = 0; | |
2933 } | |
2934 } | |
2935 /* Do the same as expire time for fading */ | |
2936 if(ALmixer_Channel_List[i].fade_enabled) | |
2937 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2938 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2939 ALuint diff_time; |
0 | 2940 diff_time = current_time - |
2941 ALmixer_Channel_List[i].fade_start_time; | |
2942 /* When we unpause, we will want to reset | |
2943 * the start time so we can continue | |
2944 * to base calculations off GetTicks(). | |
2945 * This means we need to subtract the amount | |
2946 * of time already used up from expire_ticks. | |
2947 */ | |
2948 ALmixer_Channel_List[i].fade_expire_ticks = | |
2949 ALmixer_Channel_List[i].fade_expire_ticks - | |
2950 diff_time; | |
2951 /* Don't allow the time to go negative */ | |
2952 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2953 { | |
2954 ALmixer_Channel_List[i].expire_ticks = 0; | |
2955 } | |
2956 } /* End fade check */ | |
2957 } /* End if PLAYING */ | |
2958 } /* End channel in use */ | |
2959 } /* End for-loop */ | |
2960 } | |
2961 if(-1 == retval) | |
2962 { | |
2963 return -1; | |
2964 } | |
2965 return counter; | |
2966 } | |
2967 | |
2968 /* 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
|
2969 static ALint Internal_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2970 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2971 ALint channel; |
0 | 2972 if(0 == source) |
2973 { | |
2974 return Internal_PauseChannel(-1); | |
2975 } | |
2976 | |
2977 channel = Internal_GetChannel(source); | |
2978 if(-1 == channel) | |
2979 { | |
2980 ALmixer_SetError("Cannot pause source: %s", ALmixer_GetError()); | |
2981 return -1; | |
2982 } | |
2983 return Internal_PauseChannel(channel); | |
2984 } | |
2985 | |
2986 | |
2987 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2988 static ALint Internal_ResumeChannel(ALint channel) |
0 | 2989 { |
2990 ALint state; | |
2991 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2992 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2993 ALint counter = 0; |
0 | 2994 |
2995 if(channel >= Number_of_Channels_global) | |
2996 { | |
2997 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2998 return -1; | |
2999 } | |
3000 | |
3001 if((error = alGetError()) != AL_NO_ERROR) | |
3002 { | |
3003 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
|
3004 alGetString(error)); |
0 | 3005 } |
3006 /* Clear error */ | |
3007 alGetError(); | |
3008 | |
3009 /* If the user specified a specific channel */ | |
3010 if(channel >= 0) | |
3011 { | |
3012 /* only need to process channel if in use */ | |
3013 if(ALmixer_Channel_List[channel].channel_in_use) | |
3014 { | |
3015 alGetSourcei( | |
3016 ALmixer_Channel_List[channel].alsource, | |
3017 AL_SOURCE_STATE, &state | |
3018 ); | |
3019 if((error = alGetError()) != AL_NO_ERROR) | |
3020 { | |
3021 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
|
3022 alGetString(error)); |
0 | 3023 } |
3024 if(AL_PAUSED == state) | |
3025 { | |
3026 /* Count the actual number of channels resumed */ | |
3027 counter++; | |
3028 | |
3029 /* We need to resume the expire time count down */ | |
3030 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
3031 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3032 ALmixer_Channel_List[channel].start_time = ALmixer_GetTicks(); |
0 | 3033 } |
3034 /* Do the same as expire time for fading */ | |
3035 if(ALmixer_Channel_List[channel].fade_enabled) | |
3036 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3037 ALmixer_Channel_List[channel].fade_start_time = ALmixer_GetTicks(); |
0 | 3038 } |
3039 | |
3040 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
3041 if((error = alGetError()) != AL_NO_ERROR) | |
3042 { | |
3043 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3044 alGetString(error) ); |
0 | 3045 retval = -1; |
3046 } | |
3047 } | |
3048 } | |
3049 } | |
3050 /* The user wants to halt all channels */ | |
3051 else | |
3052 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3053 ALint i; |
0 | 3054 for(i=0; i<Number_of_Channels_global; i++) |
3055 { | |
3056 /* only need to process channel if in use */ | |
3057 if(ALmixer_Channel_List[i].channel_in_use) | |
3058 { | |
3059 alGetSourcei( | |
3060 ALmixer_Channel_List[i].alsource, | |
3061 AL_SOURCE_STATE, &state | |
3062 ); | |
3063 if((error = alGetError()) != AL_NO_ERROR) | |
3064 { | |
3065 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
|
3066 alGetString(error)); |
0 | 3067 } |
3068 if(AL_PAUSED == state) | |
3069 { | |
3070 /* Count the actual number of channels resumed */ | |
3071 counter++; | |
3072 | |
3073 /* We need to resume the expire time count down */ | |
3074 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
3075 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3076 ALmixer_Channel_List[i].start_time = ALmixer_GetTicks(); |
0 | 3077 } |
3078 /* Do the same as expire time for fading */ | |
3079 if(ALmixer_Channel_List[i].fade_enabled) | |
3080 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3081 ALmixer_Channel_List[i].fade_start_time = ALmixer_GetTicks(); |
0 | 3082 } |
3083 | |
3084 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
3085 if((error = alGetError()) != AL_NO_ERROR) | |
3086 { | |
3087 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3088 alGetString(error) ); |
0 | 3089 retval = -1; |
3090 } | |
3091 } | |
3092 } | |
3093 } | |
3094 } | |
3095 if(-1 == retval) | |
3096 { | |
3097 return -1; | |
3098 } | |
3099 return counter; | |
3100 } | |
3101 | |
3102 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3103 static ALint Internal_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3104 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3105 ALint channel; |
0 | 3106 if(0 == source) |
3107 { | |
3108 return Internal_ResumeChannel(-1); | |
3109 } | |
3110 | |
3111 channel = Internal_GetChannel(source); | |
3112 if(-1 == channel) | |
3113 { | |
3114 ALmixer_SetError("Cannot resume source: %s", ALmixer_GetError()); | |
3115 return -1; | |
3116 } | |
3117 return Internal_ResumeChannel(channel); | |
3118 } | |
3119 | |
3120 | |
3121 /* Might consider setting eof to 0 as a "feature" | |
3122 * This will allow seek to end to stay there because | |
3123 * Play automatically rewinds if at the end */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3124 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
|
3125 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3126 ALint retval; |
0 | 3127 |
3128 if(NULL == data) | |
3129 { | |
3130 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
|
3131 return AL_FALSE; |
0 | 3132 } |
3133 | |
3134 /* Seek for predecoded files involves moving the chunk pointer around */ | |
3135 if(data->decoded_all) | |
3136 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3137 ALuint byte_position; |
0 | 3138 |
3139 /* OpenAL doesn't seem to like it if I change the buffer | |
3140 * while playing (crashes), so I must require that Seek only | |
3141 * be done when the data is not in use. | |
3142 * Since data may be shared among multiple sources, | |
3143 * I can't shut them down myself, so I have to return an error. | |
3144 */ | |
3145 if(data->in_use) | |
3146 { | |
3147 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
|
3148 return AL_FALSE; |
0 | 3149 } |
3150 #if 0 | |
3151 #if defined(DISABLE_PREDECODED_SEEK) | |
3152 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
|
3153 return AL_FALSE; |
0 | 3154 |
3155 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
3156 /* By default, ALmixer frees the Sound_Sample for predecoded | |
3157 * samples because of the potential memory waste. | |
3158 * However, to seek a sample, we need to have a full | |
3159 * copy of the data around. So the strategy is to | |
3160 * recreate a hackish Sound_Sample to be used for seeking | |
3161 * purposes. If Sound_Sample is NULL, we will reallocate | |
3162 * memory for it and then procede as if everything | |
3163 * was normal. | |
3164 */ | |
3165 if(NULL == data->sample) | |
3166 { | |
3167 if( -1 == Reconstruct_Sound_Sample(data) ) | |
3168 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3169 return AL_FALSE; |
0 | 3170 } |
3171 } | |
3172 #endif | |
3173 #endif | |
3174 /* If access_data was set, then we still have the | |
3175 * Sound_Sample and we can move around in the data. | |
3176 * If it was not set, the data has been freed and we | |
3177 * cannot do anything because there is no way to | |
3178 * recover the data because OpenAL won't let us | |
3179 * get access to the buffers | |
3180 */ | |
3181 if(NULL == data->sample) | |
3182 { | |
3183 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
|
3184 return AL_FALSE; |
0 | 3185 } |
3186 | |
3187 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
|
3188 retval = Set_Predecoded_Seek_Position(data, byte_position); |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3189 if(-1 == retval) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3190 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3191 return AL_FALSE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3192 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3193 else |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3194 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3195 return AL_TRUE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3196 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3197 |
0 | 3198 } |
3199 else | |
3200 { | |
3201 /* Reset eof flag?? */ | |
3202 data->eof = 0; | |
3203 retval = Sound_Seek(data->sample, msec); | |
3204 if(0 == retval) | |
3205 { | |
3206 ALmixer_SetError(Sound_GetError()); | |
3207 | |
3208 fprintf(stderr, "Sound seek error: %s\n", ALmixer_GetError()); | |
3209 /* Try rewinding to clean up? */ | |
3210 /* | |
3211 Internal_RewindData(data); | |
3212 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3213 return AL_FALSE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3214 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3215 return AL_TRUE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3216 } |
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 return AL_TRUE; |
0 | 3219 } |
3220 | |
3221 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3222 static ALint Internal_SeekChannel(ALint channel, ALuint msec) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3223 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3224 ALint retval = 0; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3225 ALenum error; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3226 ALint state; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3227 ALint running_count = 0; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3228 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3229 if(0 == msec) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3230 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3231 return Internal_RewindChannel(channel); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3232 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3233 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3234 if(channel >= Number_of_Channels_global) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3235 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3236 ALmixer_SetError("Cannot seek channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3237 return -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3238 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3239 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3240 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3241 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3242 fprintf(stderr, "24Testing error: %s\n", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3243 alGetString(error)); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3244 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3245 /* Clear error */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3246 alGetError(); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3247 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3248 /* If the user specified a specific channel */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3249 if(channel >= 0) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3250 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3251 /* only need to process channel if in use */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3252 if(ALmixer_Channel_List[channel].channel_in_use) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3253 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3254 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3255 /* What should I do? Do I just rewind the channel |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3256 * or also rewind the data? Since the data is |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3257 * shared, let's make it the user's responsibility |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3258 * to rewind the data. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3259 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3260 if(ALmixer_Channel_List[channel].almixer_data->decoded_all) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3261 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3262 /* convert milliseconds to seconds */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3263 ALfloat sec_offset = msec / 1000.0f; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3264 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3265 alGetSourcei( |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3266 ALmixer_Channel_List[channel].alsource, |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3267 AL_SOURCE_STATE, &state |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3268 ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3269 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3270 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3271 fprintf(stderr, "25Testing error: %s\n", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3272 alGetString(error)); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3273 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3274 /* OpenAL seek */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3275 alSourcef(ALmixer_Channel_List[channel].alsource, AL_SEC_OFFSET, sec_offset); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3276 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3277 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3278 ALmixer_SetError("%s", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3279 alGetString(error) ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3280 retval = -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3281 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3282 /* Need to resume playback if it was originally playing */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3283 if(AL_PLAYING == state) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3284 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3285 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3286 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3287 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3288 ALmixer_SetError("%s", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3289 alGetString(error) ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3290 retval = -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3291 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3292 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3293 else if(AL_PAUSED == state) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3294 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3295 /* HACK: The problem is that when paused, after |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3296 * the Rewind, I can't get it off the INITIAL |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3297 * state without restarting |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3298 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3299 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3300 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3301 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3302 fprintf(stderr, "25Testing error: %s\n", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3303 alGetString(error)); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3304 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3305 alSourcePause(ALmixer_Channel_List[channel].alsource); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3306 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3307 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3308 ALmixer_SetError("%s", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3309 alGetString(error) ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3310 retval = -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3311 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3312 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3313 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3314 else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3315 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3316 /* Streamed data is different. Rewinding the channel |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3317 * does no good. Rewinding the data will have an |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3318 * effect, but it will be lagged based on how |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3319 * much data is queued. Recommend users call Halt |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3320 * before rewind if they want immediate results. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3321 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3322 retval = Internal_SeekData(ALmixer_Channel_List[channel].almixer_data, msec); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3323 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3324 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3325 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3326 /* The user wants to rewind all channels */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3327 else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3328 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3329 ALint i; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3330 ALfloat sec_offset = msec / 1000.0f; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3331 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3332 for(i=0; i<Number_of_Channels_global; i++) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3333 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3334 /* only need to process channel if in use */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3335 if(ALmixer_Channel_List[i].channel_in_use) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3336 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3337 /* What should I do? Do I just rewind the channel |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3338 * or also rewind the data? Since the data is |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3339 * shared, let's make it the user's responsibility |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3340 * to rewind the data. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3341 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3342 if(ALmixer_Channel_List[i].almixer_data->decoded_all) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3343 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3344 alGetSourcei( |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3345 ALmixer_Channel_List[i].alsource, |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3346 AL_SOURCE_STATE, &state |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3347 ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3348 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3349 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3350 fprintf(stderr, "26Testing error: %s\n", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3351 alGetString(error)); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3352 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3353 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3354 alSourcef(ALmixer_Channel_List[channel].alsource, AL_SEC_OFFSET, sec_offset); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3355 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3356 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3357 ALmixer_SetError("%s", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3358 alGetString(error) ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3359 retval = -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3360 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3361 /* Need to resume playback if it was originally playing */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3362 if(AL_PLAYING == state) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3363 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3364 alSourcePlay(ALmixer_Channel_List[i].alsource); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3365 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3366 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3367 ALmixer_SetError("%s", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3368 alGetString(error) ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3369 retval = -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3370 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3371 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3372 else if(AL_PAUSED == state) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3373 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3374 /* HACK: The problem is that when paused, after |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3375 * the Rewind, I can't get it off the INITIAL |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3376 * state without restarting |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3377 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3378 alSourcePlay(ALmixer_Channel_List[i].alsource); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3379 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3380 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3381 fprintf(stderr, "27Testing error: %s\n", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3382 alGetString(error)); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3383 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3384 alSourcePause(ALmixer_Channel_List[i].alsource); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3385 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3386 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3387 ALmixer_SetError("%s", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3388 alGetString(error) ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3389 retval = -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3390 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3391 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3392 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3393 else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3394 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3395 /* Streamed data is different. Rewinding the channel |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3396 * does no good. Rewinding the data will have an |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3397 * effect, but it will be lagged based on how |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3398 * much data is queued. Recommend users call Halt |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3399 * before rewind if they want immediate results. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3400 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3401 running_count += Internal_SeekData(ALmixer_Channel_List[i].almixer_data, msec); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3402 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3403 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3404 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3405 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3406 if(-1 == retval) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3407 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3408 return -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3409 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3410 else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3411 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3412 return running_count; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3413 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3414 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3415 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3416 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3417 static ALint Internal_SeekSource(ALuint source, ALuint msec) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3418 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3419 ALint channel; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3420 if(0 == source) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3421 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3422 return Internal_SeekChannel(-1, msec); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3423 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3424 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3425 channel = Internal_GetChannel(source); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3426 if(-1 == channel) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3427 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3428 ALmixer_SetError("Cannot seek source: %s", ALmixer_GetError()); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3429 return 0; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3430 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3431 return Internal_SeekChannel(channel, msec); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3432 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3433 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3434 |
0 | 3435 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3436 static ALint Internal_FadeInChannelTimed(ALint channel, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 3437 { |
3438 ALfloat value; | |
3439 ALenum error; | |
3440 ALfloat original_value; | |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
3441 /* ALuint current_time = ALmixer_GetTicks(); */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3442 ALint retval; |
0 | 3443 |
3444 | |
3445 | |
3446 if(channel >= Number_of_Channels_global) | |
3447 { | |
3448 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); | |
3449 return -1; | |
3450 } | |
3451 /* Let's call PlayChannelTimed to do the job. | |
3452 * There are two catches: | |
3453 * First is that we must set the volumes before the play call(s). | |
3454 * Second is that we must initialize the channel values | |
3455 */ | |
3456 | |
3457 if(channel < 0) | |
3458 { | |
3459 /* This might cause a problem for threads/race conditions. | |
3460 * We need to set the volume on an unknown channel, | |
3461 * so we need to request a channel first. Remember | |
3462 * that requesting a channel doesn't lock and it | |
3463 * could be surrendered to somebody else before we claim it. | |
3464 */ | |
3465 channel = Internal_GetChannel(0); | |
3466 if(-1 == channel) | |
3467 { | |
3468 return -1; | |
3469 } | |
3470 } | |
3471 else if(ALmixer_Channel_List[channel].channel_in_use) | |
3472 { | |
3473 ALmixer_SetError("Channel %d is already in use", channel); | |
3474 return -1; | |
3475 } | |
3476 | |
3477 | |
3478 /* Get the original volume in case of a problem */ | |
3479 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
|
3480 AL_GAIN, &original_value); |
0 | 3481 |
3482 if((error = alGetError()) != AL_NO_ERROR) | |
3483 { | |
3484 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
|
3485 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3486 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3487 ALmixer_Channel_List[channel].fade_end_volume = original_value; |
0 | 3488 |
3489 /* Get the Min volume */ | |
3490 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3491 AL_MIN_GAIN, &value); | |
3492 if((error = alGetError()) != AL_NO_ERROR) | |
3493 { | |
3494 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
|
3495 alGetString(error)); |
0 | 3496 } |
3497 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3498 | |
3499 /* Set the actual volume */ | |
3500 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
|
3501 AL_GAIN, value); |
0 | 3502 if((error = alGetError()) != AL_NO_ERROR) |
3503 { | |
3504 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
|
3505 alGetString(error)); |
0 | 3506 } |
3507 | |
3508 | |
3509 /* Now call PlayChannelTimed */ | |
3510 retval = Internal_PlayChannelTimed(channel, data, loops, expire_ticks); | |
3511 if(-1 == retval) | |
3512 { | |
3513 /* Chance of failure is actually pretty high since | |
3514 * a channel might already be in use or streamed | |
3515 * data can be shared | |
3516 */ | |
3517 /* Restore the original value to avoid accidental | |
3518 * distruption of playback | |
3519 */ | |
3520 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
|
3521 AL_GAIN, original_value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3522 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3523 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3524 fprintf(stderr, "38Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3525 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3526 } |
0 | 3527 return retval; |
3528 } | |
3529 | |
3530 /* We can't accept 0 as a value because of div-by-zero. | |
3531 * If zero, just call PlayChannelTimed at normal | |
3532 * volume | |
3533 */ | |
3534 if(0 == fade_ticks) | |
3535 { | |
3536 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
|
3537 AL_GAIN, |
0 | 3538 ALmixer_Channel_List[channel].fade_end_volume |
3539 ); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3540 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3541 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3542 fprintf(stderr, "39Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3543 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3544 } |
0 | 3545 |
3546 return retval; | |
3547 } | |
3548 | |
3549 /* Enable fading effects via the flag */ | |
3550 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3551 /* Set fade start time */ | |
3552 ALmixer_Channel_List[channel].fade_start_time | |
3553 = ALmixer_Channel_List[channel].start_time; | |
3554 /* Set the fade expire ticks */ | |
3555 ALmixer_Channel_List[channel].fade_expire_ticks = fade_ticks; | |
3556 | |
3557 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3558 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / fade_ticks; | |
3559 | |
3560 return retval; | |
3561 | |
3562 } | |
3563 | |
3564 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3565 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
|
3566 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3567 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3568 ALint retval; |
0 | 3569 if(0 == source) |
3570 { | |
3571 retval = Internal_FadeInChannelTimed(-1, data, loops, fade_ticks, expire_ticks); | |
3572 if(-1 == retval) | |
3573 { | |
3574 return 0; | |
3575 } | |
3576 else | |
3577 { | |
3578 return Internal_GetSource(retval); | |
3579 } | |
3580 } | |
3581 | |
3582 channel = Internal_GetChannel(source); | |
3583 if(-1 == channel) | |
3584 { | |
3585 ALmixer_SetError("Cannot FadeIn source: %s", ALmixer_GetError()); | |
3586 return 0; | |
3587 } | |
3588 retval = Internal_FadeInChannelTimed(channel, data, loops, fade_ticks, expire_ticks); | |
3589 if(-1 == retval) | |
3590 { | |
3591 return 0; | |
3592 } | |
3593 else | |
3594 { | |
3595 return source; | |
3596 } | |
3597 /* make compiler happy */ | |
3598 return 0; | |
3599 } | |
3600 | |
3601 | |
3602 | |
3603 | |
3604 /* Will fade out currently playing channels. | |
3605 * 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
|
3606 static ALint Internal_FadeOutChannel(ALint channel, ALuint ticks) |
0 | 3607 { |
3608 ALfloat value; | |
3609 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3610 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3611 ALuint counter = 0; |
0 | 3612 |
3613 /* We can't accept 0 as a value because of div-by-zero. | |
3614 * If zero, just call Halt at normal | |
3615 * volume | |
3616 */ | |
3617 if(0 == ticks) | |
3618 { | |
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
|
3619 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 3620 } |
3621 | |
3622 | |
3623 if(channel >= Number_of_Channels_global) | |
3624 { | |
3625 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); | |
3626 return -1; | |
3627 } | |
3628 | |
3629 if(channel >= 0) | |
3630 { | |
3631 if(ALmixer_Channel_List[channel].channel_in_use) | |
3632 { | |
3633 /* Get the current volume */ | |
3634 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
|
3635 AL_GAIN, &value); |
0 | 3636 ALmixer_Channel_List[channel].fade_start_volume = value; |
3637 if((error = alGetError()) != AL_NO_ERROR) | |
3638 { | |
3639 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
|
3640 alGetString(error)); |
0 | 3641 } |
3642 | |
3643 /* Get the Min volume */ | |
3644 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3645 AL_MIN_GAIN, &value); | |
3646 if((error = alGetError()) != AL_NO_ERROR) | |
3647 { | |
3648 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
|
3649 alGetString(error)); |
0 | 3650 } |
3651 ALmixer_Channel_List[channel].fade_end_volume = value; | |
3652 | |
3653 /* Set expire start time */ | |
3654 ALmixer_Channel_List[channel].start_time = current_time; | |
3655 /* Set the expire ticks */ | |
3656 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
3657 /* Set fade start time */ | |
3658 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3659 /* Set the fade expire ticks */ | |
3660 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3661 /* Enable fading effects via the flag */ | |
3662 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3663 | |
3664 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3665 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3666 | |
3667 counter++; | |
3668 } | |
3669 } | |
3670 /* Else need to fade out all channels */ | |
3671 else | |
3672 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3673 ALint i; |
0 | 3674 for(i=0; i<Number_of_Channels_global; i++) |
3675 { | |
3676 if(ALmixer_Channel_List[i].channel_in_use) | |
3677 { | |
3678 /* Get the current volume */ | |
3679 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
|
3680 AL_GAIN, &value); |
0 | 3681 ALmixer_Channel_List[i].fade_start_volume = value; |
3682 if((error = alGetError()) != AL_NO_ERROR) | |
3683 { | |
3684 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
|
3685 alGetString(error)); |
0 | 3686 } |
3687 | |
3688 /* Get the Min volume */ | |
3689 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
3690 AL_MIN_GAIN, &value); | |
3691 if((error = alGetError()) != AL_NO_ERROR) | |
3692 { | |
3693 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
|
3694 alGetString(error)); |
0 | 3695 } |
3696 ALmixer_Channel_List[i].fade_end_volume = value; | |
3697 | |
3698 /* Set expire start time */ | |
3699 ALmixer_Channel_List[i].start_time = current_time; | |
3700 /* Set the expire ticks */ | |
3701 ALmixer_Channel_List[i].expire_ticks = ticks; | |
3702 /* Set fade start time */ | |
3703 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3704 /* Set the fade expire ticks */ | |
3705 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3706 /* Enable fading effects via the flag */ | |
3707 ALmixer_Channel_List[i].fade_enabled = 1; | |
3708 | |
3709 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3710 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3711 | |
3712 counter++; | |
3713 } | |
3714 } /* End for loop */ | |
3715 } | |
3716 return counter; | |
3717 } | |
3718 | |
3719 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3720 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
|
3721 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3722 ALint channel; |
0 | 3723 if(0 == source) |
3724 { | |
3725 return Internal_FadeOutChannel(-1, ticks); | |
3726 } | |
3727 | |
3728 channel = Internal_GetChannel(source); | |
3729 if(-1 == channel) | |
3730 { | |
3731 ALmixer_SetError("Cannot FadeOut source: %s", ALmixer_GetError()); | |
3732 return -1; | |
3733 } | |
3734 return Internal_FadeOutChannel(channel, ticks); | |
3735 } | |
3736 | |
3737 | |
3738 /* Will fade currently playing channels. | |
3739 * It starts at the current volume level and go to target | |
3740 * Only affects channels that are playing | |
3741 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3742 static ALint Internal_FadeChannel(ALint channel, ALuint ticks, ALfloat volume) |
0 | 3743 { |
3744 ALfloat value; | |
3745 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3746 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3747 ALuint counter = 0; |
0 | 3748 |
3749 if(channel >= Number_of_Channels_global) | |
3750 { | |
3751 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); | |
3752 return -1; | |
3753 } | |
3754 | |
3755 if(channel >= 0) | |
3756 { | |
3757 if(volume < ALmixer_Channel_List[channel].min_volume) | |
3758 { | |
3759 volume = ALmixer_Channel_List[channel].min_volume; | |
3760 } | |
3761 else if(volume > ALmixer_Channel_List[channel].max_volume) | |
3762 { | |
3763 volume = ALmixer_Channel_List[channel].max_volume; | |
3764 } | |
3765 | |
3766 if(ALmixer_Channel_List[channel].channel_in_use) | |
3767 { | |
3768 if(ticks > 0) | |
3769 { | |
3770 /* Get the current volume */ | |
3771 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
|
3772 AL_GAIN, &value); |
0 | 3773 if((error = alGetError()) != AL_NO_ERROR) |
3774 { | |
3775 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
|
3776 alGetString(error)); |
0 | 3777 } |
3778 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3779 | |
3780 /* Set the target volume */ | |
3781 ALmixer_Channel_List[channel].fade_end_volume = volume; | |
3782 | |
3783 /* Set fade start time */ | |
3784 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3785 /* Set the fade expire ticks */ | |
3786 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3787 /* Enable fading effects via the flag */ | |
3788 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3789 | |
3790 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3791 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3792 } | |
3793 else | |
3794 { | |
3795 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
|
3796 AL_GAIN, volume); |
0 | 3797 if((error = alGetError()) != AL_NO_ERROR) |
3798 { | |
3799 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
|
3800 alGetString(error)); |
0 | 3801 } |
3802 } | |
3803 counter++; | |
3804 } | |
3805 } | |
3806 /* Else need to fade out all channels */ | |
3807 else | |
3808 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3809 ALint i; |
0 | 3810 for(i=0; i<Number_of_Channels_global; i++) |
3811 { | |
3812 if(volume < ALmixer_Channel_List[i].min_volume) | |
3813 { | |
3814 volume = ALmixer_Channel_List[i].min_volume; | |
3815 } | |
3816 else if(volume > ALmixer_Channel_List[i].max_volume) | |
3817 { | |
3818 volume = ALmixer_Channel_List[i].max_volume; | |
3819 } | |
3820 | |
3821 if(ALmixer_Channel_List[i].channel_in_use) | |
3822 { | |
3823 if(ticks > 0) | |
3824 { | |
3825 /* Get the current volume */ | |
3826 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
|
3827 AL_GAIN, &value); |
0 | 3828 if((error = alGetError()) != AL_NO_ERROR) |
3829 { | |
3830 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
|
3831 alGetString(error)); |
0 | 3832 } |
3833 ALmixer_Channel_List[i].fade_start_volume = value; | |
3834 | |
3835 /* Set target volume */ | |
3836 ALmixer_Channel_List[i].fade_end_volume = volume; | |
3837 | |
3838 /* Set fade start time */ | |
3839 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3840 /* Set the fade expire ticks */ | |
3841 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3842 /* Enable fading effects via the flag */ | |
3843 ALmixer_Channel_List[i].fade_enabled = 1; | |
3844 | |
3845 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3846 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3847 } | |
3848 else | |
3849 { | |
3850 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
|
3851 AL_GAIN, volume); |
0 | 3852 if((error = alGetError()) != AL_NO_ERROR) |
3853 { | |
3854 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
|
3855 alGetString(error)); |
0 | 3856 } |
3857 } | |
3858 counter++; | |
3859 } | |
3860 } /* End for loop */ | |
3861 } | |
3862 return counter; | |
3863 } | |
3864 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3865 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
|
3866 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3867 ALint channel; |
0 | 3868 if(0 == source) |
3869 { | |
3870 return Internal_FadeChannel(-1, ticks, volume); | |
3871 } | |
3872 | |
3873 channel = Internal_GetChannel(source); | |
3874 if(-1 == channel) | |
3875 { | |
3876 ALmixer_SetError("Cannot Fade source: %s", ALmixer_GetError()); | |
3877 return -1; | |
3878 } | |
3879 return Internal_FadeChannel(channel, ticks, volume); | |
3880 } | |
3881 | |
3882 | |
3883 | |
3884 | |
3885 /* Set a volume regardless if it's in use or not. | |
3886 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3887 static ALboolean Internal_SetVolumeChannel(ALint channel, ALfloat volume) |
0 | 3888 { |
3889 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3890 ALboolean retval = AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3891 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3892 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3893 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3894 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
|
3895 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3896 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3897 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3898 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3899 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3900 if(volume < 0.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3901 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3902 volume = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3903 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3904 else if(volume > 1.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3905 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3906 volume = 1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3907 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3908 alSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3909 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3910 if((error = alGetError()) != AL_NO_ERROR) |
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 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3913 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3914 retval = AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3915 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3916 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3917 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3918 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3919 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3920 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
|
3921 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3922 if(volume < 0.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3923 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3924 volume = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3925 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3926 else if(volume > 1.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3927 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3928 volume = 1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3929 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3930 alSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3931 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3932 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3933 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3934 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3935 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3936 retval = AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3937 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3938 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3939 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3940 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3941 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3942 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3943 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
|
3944 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3945 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3946 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3947 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3948 return Internal_SetVolumeChannel(-1, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3949 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3950 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3951 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3952 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3953 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3954 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
|
3955 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3956 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3957 return Internal_SetVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3958 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3959 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3960 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3961 static ALfloat Internal_GetVolumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3962 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3963 ALfloat value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3964 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3965 ALfloat running_total = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3966 ALfloat retval = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3967 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3968 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3969 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3970 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
|
3971 return -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3972 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3973 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3974 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3975 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3976 alGetSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3977 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3978 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3979 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3980 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3981 retval = -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3982 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3983 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3984 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3985 retval = value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3986 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3987 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3988 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3989 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3990 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3991 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
|
3992 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3993 alGetSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3994 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3995 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3996 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3997 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3998 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3999 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4000 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4001 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4002 running_total += value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4003 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4004 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4005 if(0 == Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4006 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4007 ALmixer_SetError("No channels are allocated"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4008 retval = -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4009 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4010 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4011 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4012 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
|
4013 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4014 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4015 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4016 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4017 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4018 static ALfloat Internal_GetVolumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4019 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4020 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4021 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4022 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4023 return Internal_GetVolumeChannel(-1); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4024 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4025 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4026 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4027 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4028 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4029 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
|
4030 return -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4031 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4032 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4033 return Internal_GetVolumeChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4034 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4035 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4036 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4037 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4038 /* 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
|
4039 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4040 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
|
4041 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4042 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4043 ALboolean retval = AL_TRUE; |
0 | 4044 |
4045 if(channel >= Number_of_Channels_global) | |
4046 { | |
4047 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
|
4048 return AL_FALSE; |
0 | 4049 } |
4050 | |
4051 if(channel >= 0) | |
4052 { | |
4053 if(volume < 0.0f) | |
4054 { | |
4055 volume = 0.0f; | |
4056 } | |
4057 else if(volume > 1.0f) | |
4058 { | |
4059 volume = 1.0f; | |
4060 } | |
4061 ALmixer_Channel_List[channel].max_volume = volume; | |
4062 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4063 AL_MAX_GAIN, volume); | |
4064 if((error = alGetError()) != AL_NO_ERROR) | |
4065 { | |
4066 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4067 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4068 retval = AL_FALSE; |
0 | 4069 } |
4070 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
4071 { | |
4072 ALmixer_Channel_List[channel].min_volume = volume; | |
4073 alSourcef(ALmixer_Channel_List[channel].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 } | |
4082 } | |
4083 else | |
4084 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4085 ALint i; |
0 | 4086 for(i=0; i<Number_of_Channels_global; i++) |
4087 { | |
4088 if(volume < 0.0f) | |
4089 { | |
4090 volume = 0.0f; | |
4091 } | |
4092 else if(volume > 1.0f) | |
4093 { | |
4094 volume = 1.0f; | |
4095 } | |
4096 ALmixer_Channel_List[i].max_volume = volume; | |
4097 alSourcef(ALmixer_Channel_List[i].alsource, | |
4098 AL_MAX_GAIN, volume); | |
4099 if((error = alGetError()) != AL_NO_ERROR) | |
4100 { | |
4101 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4102 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4103 retval = AL_FALSE; |
0 | 4104 } |
4105 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
4106 { | |
4107 ALmixer_Channel_List[i].min_volume = volume; | |
4108 alSourcef(ALmixer_Channel_List[i].alsource, | |
4109 AL_MIN_GAIN, volume); | |
4110 if((error = alGetError()) != AL_NO_ERROR) | |
4111 { | |
4112 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4113 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4114 retval = AL_FALSE; |
0 | 4115 } |
4116 } | |
4117 } | |
4118 } | |
4119 return retval; | |
4120 } | |
4121 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4122 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
|
4123 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4124 ALint channel; |
0 | 4125 if(0 == source) |
4126 { | |
4127 return Internal_SetMaxVolumeChannel(-1, volume); | |
4128 } | |
4129 | |
4130 channel = Internal_GetChannel(source); | |
4131 if(-1 == channel) | |
4132 { | |
4133 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
|
4134 return AL_FALSE; |
0 | 4135 } |
4136 return Internal_SetMaxVolumeChannel(channel, volume); | |
4137 } | |
4138 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4139 static ALfloat Internal_GetMaxVolumeChannel(ALint channel) |
0 | 4140 { |
4141 /* | |
4142 ALfloat value; | |
4143 ALenum error; | |
4144 */ | |
4145 ALfloat running_total = 0.0f; | |
4146 ALfloat retval = 0.0f; | |
4147 | |
4148 if(channel >= Number_of_Channels_global) | |
4149 { | |
4150 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); | |
4151 return -1.0f; | |
4152 } | |
4153 | |
4154 if(channel >= 0) | |
4155 { | |
4156 /* | |
4157 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
4158 AL_GAIN, &value); | |
4159 if((error = alGetError()) != AL_NO_ERROR) | |
4160 { | |
4161 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4162 alGetString(error) ); |
0 | 4163 retval = -1.0f; |
4164 } | |
4165 else | |
4166 { | |
4167 retval = value; | |
4168 } | |
4169 */ | |
4170 retval = ALmixer_Channel_List[channel].max_volume; | |
4171 | |
4172 } | |
4173 else | |
4174 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4175 ALint i; |
0 | 4176 for(i=0; i<Number_of_Channels_global; i++) |
4177 { | |
4178 /* | |
4179 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
4180 AL_GAIN, &value); | |
4181 if((error = alGetError()) != AL_NO_ERROR) | |
4182 { | |
4183 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4184 alGetString(error) ); |
0 | 4185 retval = -1; |
4186 } | |
4187 else | |
4188 { | |
4189 running_total += value; | |
4190 } | |
4191 */ | |
4192 running_total += ALmixer_Channel_List[i].max_volume; | |
4193 } | |
4194 if(0 == Number_of_Channels_global) | |
4195 { | |
4196 ALmixer_SetError("No channels are allocated"); | |
4197 retval = -1.0f; | |
4198 } | |
4199 else | |
4200 { | |
4201 retval = running_total / Number_of_Channels_global; | |
4202 } | |
4203 } | |
4204 return retval; | |
4205 } | |
4206 | |
4207 static ALfloat Internal_GetMaxVolumeSource(ALuint source) | |
4208 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4209 ALint channel; |
0 | 4210 if(0 == source) |
4211 { | |
4212 return Internal_GetMaxVolumeChannel(-1); | |
4213 } | |
4214 | |
4215 channel = Internal_GetChannel(source); | |
4216 if(-1 == channel) | |
4217 { | |
4218 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
4219 return -1.0f; | |
4220 } | |
4221 | |
4222 return Internal_GetMaxVolumeChannel(channel); | |
4223 } | |
4224 | |
4225 | |
4226 /* Set a volume regardless if it's in use or not. | |
4227 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4228 static ALboolean Internal_SetMinVolumeChannel(ALint channel, ALfloat volume) |
0 | 4229 { |
4230 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4231 ALboolean retval = AL_TRUE; |
0 | 4232 |
4233 if(channel >= Number_of_Channels_global) | |
4234 { | |
4235 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
|
4236 return AL_FALSE; |
0 | 4237 } |
4238 | |
4239 if(channel >= 0) | |
4240 { | |
4241 if(volume < 0.0f) | |
4242 { | |
4243 volume = 0.0f; | |
4244 } | |
4245 else if(volume > 1.0f) | |
4246 { | |
4247 volume = 1.0f; | |
4248 } | |
4249 ALmixer_Channel_List[channel].min_volume = volume; | |
4250 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4251 AL_MIN_GAIN, volume); | |
4252 if((error = alGetError()) != AL_NO_ERROR) | |
4253 { | |
4254 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4255 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4256 retval = AL_FALSE; |
0 | 4257 } |
4258 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
4259 { | |
4260 ALmixer_Channel_List[channel].max_volume = volume; | |
4261 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4262 AL_MAX_GAIN, volume); | |
4263 if((error = alGetError()) != AL_NO_ERROR) | |
4264 { | |
4265 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4266 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4267 retval = AL_FALSE; |
0 | 4268 } |
4269 } | |
4270 } | |
4271 else | |
4272 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4273 ALint i; |
0 | 4274 for(i=0; i<Number_of_Channels_global; i++) |
4275 { | |
4276 if(volume < 0.0f) | |
4277 { | |
4278 volume = 0.0f; | |
4279 } | |
4280 else if(volume > 1.0f) | |
4281 { | |
4282 volume = 1.0f; | |
4283 } | |
4284 ALmixer_Channel_List[i].min_volume = volume; | |
4285 alSourcef(ALmixer_Channel_List[i].alsource, | |
4286 AL_MIN_GAIN, volume); | |
4287 if((error = alGetError()) != AL_NO_ERROR) | |
4288 { | |
4289 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4290 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4291 retval = AL_FALSE; |
0 | 4292 } |
4293 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
4294 { | |
4295 ALmixer_Channel_List[i].max_volume = volume; | |
4296 alSourcef(ALmixer_Channel_List[i].alsource, | |
4297 AL_MAX_GAIN, volume); | |
4298 if((error = alGetError()) != AL_NO_ERROR) | |
4299 { | |
4300 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4301 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4302 retval = AL_FALSE; |
0 | 4303 } |
4304 } | |
4305 } | |
4306 } | |
4307 return retval; | |
4308 } | |
4309 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4310 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
|
4311 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4312 ALint channel; |
0 | 4313 if(0 == source) |
4314 { | |
4315 return Internal_SetMinVolumeChannel(-1, volume); | |
4316 } | |
4317 | |
4318 channel = Internal_GetChannel(source); | |
4319 if(-1 == channel) | |
4320 { | |
4321 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
|
4322 return AL_FALSE; |
0 | 4323 } |
4324 return Internal_SetMinVolumeChannel(channel, volume); | |
4325 } | |
4326 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4327 static ALfloat Internal_GetMinVolumeChannel(ALint channel) |
0 | 4328 { |
4329 /* | |
4330 ALfloat value; | |
4331 ALenum error; | |
4332 */ | |
4333 ALfloat running_total = 0.0f; | |
4334 ALfloat retval = 0.0f; | |
4335 | |
4336 if(channel >= Number_of_Channels_global) | |
4337 { | |
4338 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); | |
4339 return -1.0f; | |
4340 } | |
4341 | |
4342 if(channel >= 0) | |
4343 { | |
4344 /* | |
4345 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
4346 AL_GAIN, &value); | |
4347 if((error = alGetError()) != AL_NO_ERROR) | |
4348 { | |
4349 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4350 alGetString(error) ); |
0 | 4351 retval = -1.0f; |
4352 } | |
4353 else | |
4354 { | |
4355 retval = value; | |
4356 } | |
4357 */ | |
4358 retval = ALmixer_Channel_List[channel].min_volume; | |
4359 | |
4360 } | |
4361 else | |
4362 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4363 ALint i; |
0 | 4364 for(i=0; i<Number_of_Channels_global; i++) |
4365 { | |
4366 /* | |
4367 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
4368 AL_GAIN, &value); | |
4369 if((error = alGetError()) != AL_NO_ERROR) | |
4370 { | |
4371 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4372 alGetString(error) ); |
0 | 4373 retval = -1; |
4374 } | |
4375 else | |
4376 { | |
4377 running_total += value; | |
4378 } | |
4379 */ | |
4380 running_total += ALmixer_Channel_List[i].min_volume; | |
4381 } | |
4382 if(0 == Number_of_Channels_global) | |
4383 { | |
4384 ALmixer_SetError("No channels are allocated"); | |
4385 retval = -1.0f; | |
4386 } | |
4387 else | |
4388 { | |
4389 retval = running_total / Number_of_Channels_global; | |
4390 } | |
4391 } | |
4392 return retval; | |
4393 } | |
4394 | |
4395 static ALfloat Internal_GetMinVolumeSource(ALuint source) | |
4396 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4397 ALint channel; |
0 | 4398 if(0 == source) |
4399 { | |
4400 return Internal_GetMinVolumeChannel(-1); | |
4401 } | |
4402 | |
4403 channel = Internal_GetChannel(source); | |
4404 if(-1 == channel) | |
4405 { | |
4406 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
4407 return -1.0f; | |
4408 } | |
4409 | |
4410 return Internal_GetMinVolumeChannel(channel); | |
4411 } | |
4412 | |
4413 | |
4414 /* Changes the listener volume */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4415 static ALboolean Internal_SetMasterVolume(ALfloat volume) |
0 | 4416 { |
4417 ALenum error; | |
4418 alListenerf(AL_GAIN, volume); | |
4419 if((error = alGetError()) != AL_NO_ERROR) | |
4420 { | |
4421 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4422 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4423 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4424 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4425 return AL_TRUE; |
0 | 4426 } |
4427 | |
4428 static ALfloat Internal_GetMasterVolume() | |
4429 { | |
4430 ALenum error; | |
4431 ALfloat volume; | |
4432 alGetListenerf(AL_GAIN, &volume); | |
4433 if((error = alGetError()) != AL_NO_ERROR) | |
4434 { | |
4435 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4436 alGetString(error) ); |
0 | 4437 return -1.0f; |
4438 } | |
4439 return volume; | |
4440 } | |
4441 | |
4442 | |
4443 | |
4444 | |
4445 /* Will fade out currently playing channels. | |
4446 * 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
|
4447 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
|
4448 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4449 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4450 ALuint counter = 0; |
0 | 4451 |
4452 /* We can't accept 0 as a value because of div-by-zero. | |
4453 * If zero, just call Halt at normal | |
4454 * volume | |
4455 */ | |
4456 if(0 == ticks) | |
4457 { | |
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
|
4458 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 4459 } |
4460 if(ticks < -1) | |
4461 { | |
4462 ticks = -1; | |
4463 } | |
4464 | |
4465 | |
4466 if(channel >= Number_of_Channels_global) | |
4467 { | |
4468 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); | |
4469 return -1; | |
4470 } | |
4471 | |
4472 if(channel >= 0) | |
4473 { | |
4474 if(ALmixer_Channel_List[channel].channel_in_use) | |
4475 { | |
4476 /* Set expire start time */ | |
4477 ALmixer_Channel_List[channel].start_time = current_time; | |
4478 /* Set the expire ticks */ | |
4479 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
4480 | |
4481 counter++; | |
4482 } | |
4483 } | |
4484 /* Else need to fade out all channels */ | |
4485 else | |
4486 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4487 ALint i; |
0 | 4488 for(i=0; i<Number_of_Channels_global; i++) |
4489 { | |
4490 if(ALmixer_Channel_List[i].channel_in_use) | |
4491 { | |
4492 /* Set expire start time */ | |
4493 ALmixer_Channel_List[i].start_time = current_time; | |
4494 /* Set the expire ticks */ | |
4495 ALmixer_Channel_List[i].expire_ticks = ticks; | |
4496 | |
4497 counter++; | |
4498 } | |
4499 } /* End for loop */ | |
4500 } | |
4501 return counter; | |
4502 } | |
4503 | |
4504 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4505 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
|
4506 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4507 ALint channel; |
0 | 4508 if(0 == source) |
4509 { | |
4510 return Internal_ExpireChannel(-1, ticks); | |
4511 } | |
4512 | |
4513 channel = Internal_GetChannel(source); | |
4514 if(-1 == channel) | |
4515 { | |
4516 ALmixer_SetError("Cannot Expire source: %s", ALmixer_GetError()); | |
4517 return -1; | |
4518 } | |
4519 return Internal_ExpireChannel(channel, ticks); | |
4520 } | |
4521 | |
4522 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4523 static ALint Internal_QueryChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4524 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4525 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4526 ALint counter = 0; |
0 | 4527 if(channel >= Number_of_Channels_global) |
4528 { | |
4529 ALmixer_SetError("Invalid channel: %d", channel); | |
4530 return -1; | |
4531 } | |
4532 | |
4533 if(channel >= 0) | |
4534 { | |
4535 return ALmixer_Channel_List[channel].channel_in_use; | |
4536 } | |
4537 | |
4538 /* Else, return the number of channels in use */ | |
4539 for(i=0; i<Number_of_Channels_global; i++) | |
4540 { | |
4541 if(ALmixer_Channel_List[i].channel_in_use) | |
4542 { | |
4543 counter++; | |
4544 } | |
4545 } | |
4546 return counter; | |
4547 } | |
4548 | |
4549 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4550 static ALint Internal_QuerySource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4551 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4552 ALint channel; |
0 | 4553 if(0 == source) |
4554 { | |
4555 return Internal_QueryChannel(-1); | |
4556 } | |
4557 | |
4558 channel = Internal_GetChannel(source); | |
4559 if(-1 == channel) | |
4560 { | |
4561 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4562 return -1; | |
4563 } | |
4564 | |
4565 return Internal_QueryChannel(channel); | |
4566 } | |
4567 | |
4568 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4569 static ALuint Internal_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4570 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4571 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4572 ALuint counter = 0; |
0 | 4573 |
4574 | |
4575 /* Else, return the number of channels in use */ | |
4576 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4577 { | |
4578 if(ALmixer_Channel_List[i].channel_in_use) | |
4579 { | |
4580 counter++; | |
4581 } | |
4582 } | |
4583 return counter; | |
4584 } | |
4585 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4586 static ALuint Internal_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4587 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4588 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4589 ALuint counter = 0; |
0 | 4590 |
4591 | |
4592 /* Else, return the number of channels in use */ | |
4593 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4594 { | |
4595 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4596 { | |
4597 counter++; | |
4598 } | |
4599 } | |
4600 return counter; | |
4601 } | |
4602 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4603 static ALuint Internal_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4604 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4605 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4606 ALuint counter = 0; |
0 | 4607 |
4608 | |
4609 /* Else, return the number of channels in use */ | |
4610 for(i=0; i<Number_of_Channels_global; i++) | |
4611 { | |
4612 if(ALmixer_Channel_List[i].channel_in_use) | |
4613 { | |
4614 counter++; | |
4615 } | |
4616 } | |
4617 return counter; | |
4618 } | |
4619 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4620 static ALuint Internal_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4621 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4622 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4623 ALuint counter = 0; |
0 | 4624 |
4625 | |
4626 /* Else, return the number of channels in use */ | |
4627 for(i=0; i<Number_of_Channels_global; i++) | |
4628 { | |
4629 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4630 { | |
4631 counter++; | |
4632 } | |
4633 } | |
4634 return counter; | |
4635 } | |
4636 | |
4637 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4638 static ALint Internal_PlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4639 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4640 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4641 ALint counter = 0; |
0 | 4642 ALint state; |
4643 | |
4644 if(channel >= Number_of_Channels_global) | |
4645 { | |
4646 ALmixer_SetError("Invalid channel: %d", channel); | |
4647 return -1; | |
4648 } | |
4649 | |
4650 if(channel >= 0) | |
4651 { | |
4652 if(ALmixer_Channel_List[channel].channel_in_use) | |
4653 { | |
4654 alGetSourcei( | |
4655 ALmixer_Channel_List[channel].alsource, | |
4656 AL_SOURCE_STATE, &state | |
4657 ); | |
4658 if(AL_PLAYING == state) | |
4659 { | |
4660 return 1; | |
4661 } | |
4662 } | |
4663 return 0; | |
4664 } | |
4665 | |
4666 /* Else, return the number of channels in use */ | |
4667 for(i=0; i<Number_of_Channels_global; i++) | |
4668 { | |
4669 if(ALmixer_Channel_List[i].channel_in_use) | |
4670 { | |
4671 alGetSourcei( | |
4672 ALmixer_Channel_List[i].alsource, | |
4673 AL_SOURCE_STATE, &state | |
4674 ); | |
4675 if(AL_PLAYING == state) | |
4676 { | |
4677 counter++; | |
4678 } | |
4679 } | |
4680 } | |
4681 return counter; | |
4682 } | |
4683 | |
4684 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4685 static ALint Internal_PlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4686 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4687 ALint channel; |
0 | 4688 if(0 == source) |
4689 { | |
4690 return Internal_PlayingChannel(-1); | |
4691 } | |
4692 | |
4693 channel = Internal_GetChannel(source); | |
4694 if(-1 == channel) | |
4695 { | |
4696 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4697 return -1; | |
4698 } | |
4699 | |
4700 return Internal_PlayingChannel(channel); | |
4701 } | |
4702 | |
4703 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4704 static ALint Internal_PausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4705 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4706 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4707 ALint counter = 0; |
0 | 4708 ALint state; |
4709 | |
4710 if(channel >= Number_of_Channels_global) | |
4711 { | |
4712 ALmixer_SetError("Invalid channel: %d", channel); | |
4713 return -1; | |
4714 } | |
4715 | |
4716 if(channel >= 0) | |
4717 { | |
4718 if(ALmixer_Channel_List[channel].channel_in_use) | |
4719 { | |
4720 alGetSourcei( | |
4721 ALmixer_Channel_List[channel].alsource, | |
4722 AL_SOURCE_STATE, &state | |
4723 ); | |
4724 if(AL_PAUSED == state) | |
4725 { | |
4726 return 1; | |
4727 } | |
4728 } | |
4729 return 0; | |
4730 } | |
4731 | |
4732 /* Else, return the number of channels in use */ | |
4733 for(i=0; i<Number_of_Channels_global; i++) | |
4734 { | |
4735 if(ALmixer_Channel_List[i].channel_in_use) | |
4736 { | |
4737 alGetSourcei( | |
4738 ALmixer_Channel_List[i].alsource, | |
4739 AL_SOURCE_STATE, &state | |
4740 ); | |
4741 if(AL_PAUSED == state) | |
4742 { | |
4743 counter++; | |
4744 } | |
4745 } | |
4746 } | |
4747 return counter; | |
4748 } | |
4749 | |
4750 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4751 static ALint Internal_PausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4752 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4753 ALint channel; |
0 | 4754 if(0 == source) |
4755 { | |
4756 return Internal_PausedChannel(-1); | |
4757 } | |
4758 | |
4759 channel = Internal_GetChannel(source); | |
4760 if(-1 == channel) | |
4761 { | |
4762 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4763 return -1; | |
4764 } | |
4765 | |
4766 return Internal_PausedChannel(channel); | |
4767 } | |
4768 | |
4769 | |
4770 | |
4771 | |
4772 | |
4773 | |
4774 /* Private function for Updating ALmixer. | |
4775 * This is a very big and ugly function. | |
4776 * It should return the number of buffers that were | |
4777 * queued during the call. The value might be | |
4778 * used to guage how long you might wait to | |
4779 * call the next update loop in case you are worried | |
4780 * about preserving CPU cycles. The idea is that | |
4781 * when a buffer is queued, there was probably some | |
4782 * CPU intensive looping which took awhile. | |
4783 * 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
|
4784 * Timing the call with ALmixer_GetTicks() would produce |
0 | 4785 * more accurate information. |
4786 * Returns a negative value if there was an error, | |
4787 * the value being the number of errors. | |
4788 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4789 static ALint Update_ALmixer(void* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4790 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4791 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4792 ALint error_flag = 0; |
0 | 4793 ALenum error; |
4794 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4795 ALint i=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4796 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4797 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4798 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4799 #endif |
0 | 4800 if(0 == ALmixer_Initialized) |
4801 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4802 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4803 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4804 #endif |
0 | 4805 return 0; |
4806 } | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4807 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4808 /* Bypass if in interruption event */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4809 if(NULL == alcGetCurrentContext()) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4810 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4811 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4812 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4813 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4814 return 0; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4815 } |
0 | 4816 |
4817 /* Check the quick flag to see if anything needs updating */ | |
4818 /* If anything is playing, then we have to do work */ | |
4819 if( 0 == Is_Playing_global) | |
4820 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4821 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4822 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4823 #endif |
0 | 4824 return 0; |
4825 } | |
4826 /* Clear error */ | |
4827 if((error = alGetError()) != AL_NO_ERROR) | |
4828 { | |
4829 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
|
4830 alGetString(error)); |
0 | 4831 } |
4832 alGetError(); | |
4833 | |
4834 for(i=0; i<Number_of_Channels_global; i++) | |
4835 { | |
4836 if( ALmixer_Channel_List[i].channel_in_use ) | |
4837 { | |
4838 | |
4839 /* For simplicity, before we do anything else, | |
4840 * we can check the timeout and fading values | |
4841 * and do the appropriate things | |
4842 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4843 ALuint current_time = ALmixer_GetTicks(); |
0 | 4844 |
4845 /* Check to see if we need to halt due to Timed play */ | |
4846 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
4847 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4848 ALuint target_time = (ALuint)ALmixer_Channel_List[i].expire_ticks |
0 | 4849 + ALmixer_Channel_List[i].start_time; |
4850 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4851 AL_SOURCE_STATE, &state); | |
4852 if((error = alGetError()) != AL_NO_ERROR) | |
4853 { | |
4854 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
|
4855 alGetString(error)); |
0 | 4856 } |
4857 | |
4858 /* Check the time, and also make sure that it is not | |
4859 * paused (if paused, we don't want to make the | |
4860 * evaluation because when resumed, we will adjust | |
4861 * the times to compensate for the pause). | |
4862 */ | |
4863 if( (current_time >= target_time) | |
4864 && (state != AL_PAUSED) ) | |
4865 { | |
4866 /* 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
|
4867 Internal_HaltChannel(i, AL_FALSE); |
0 | 4868 if((error = alGetError()) != AL_NO_ERROR) |
4869 { | |
4870 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
|
4871 alGetString(error)); |
0 | 4872 } |
4873 | |
4874 /* Everything should be done so go on to the next loop */ | |
4875 continue; | |
4876 } | |
4877 } /* End if time expired check */ | |
4878 | |
4879 /* Check to see if we need to adjust the volume for fading */ | |
4880 if( ALmixer_Channel_List[i].fade_enabled ) | |
4881 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4882 ALuint target_time = ALmixer_Channel_List[i].fade_expire_ticks |
0 | 4883 + ALmixer_Channel_List[i].fade_start_time; |
4884 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4885 AL_SOURCE_STATE, &state); | |
4886 if((error = alGetError()) != AL_NO_ERROR) | |
4887 { | |
4888 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
|
4889 alGetString(error)); |
0 | 4890 } |
4891 | |
4892 /* Check the time, and also make sure that it is not | |
4893 * paused (if paused, we don't want to make the | |
4894 * evaluation because when resumed, we will adjust | |
4895 * the times to compensate for the pause). | |
4896 */ | |
4897 if(state != AL_PAUSED) | |
4898 { | |
4899 ALfloat t; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4900 ALuint delta_time; |
0 | 4901 ALfloat current_volume; |
4902 if(current_time >= target_time) | |
4903 { | |
4904 /* Need to constrain value to the end time | |
4905 * (can't go pass the value for calculations) | |
4906 */ | |
4907 current_time = target_time; | |
4908 /* We can disable the fade flag now */ | |
4909 ALmixer_Channel_List[i].fade_enabled = 0; | |
4910 } | |
4911 /* Use the linear interpolation formula: | |
4912 * X = (1-t)x0 + tx1 | |
4913 * where x0 would be the start value | |
4914 * and x1 is the final value | |
4915 * and t is delta_time*inv_time (adjusts 0 <= time <= 1) | |
4916 * delta_time = current_time-start_time | |
4917 * inv_time = 1/ (end_time-start_time) | |
4918 * so t = current_time-start_time / (end_time-start_time) | |
4919 * | |
4920 */ | |
4921 delta_time = current_time - ALmixer_Channel_List[i].fade_start_time; | |
4922 t = (ALfloat) delta_time * ALmixer_Channel_List[i].fade_inv_time; | |
4923 current_volume = (1.0f-t) * ALmixer_Channel_List[i].fade_start_volume | |
4924 + t * ALmixer_Channel_List[i].fade_end_volume; | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4925 /* |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
4926 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); |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4927 */ |
0 | 4928 /* Set the volume */ |
4929 alSourcef(ALmixer_Channel_List[i].alsource, | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
4930 AL_GAIN, current_volume); |
0 | 4931 if((error = alGetError()) != AL_NO_ERROR) |
4932 { | |
4933 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
|
4934 alGetString(error)); |
0 | 4935 } |
4936 | |
4937 /* | |
4938 fprintf(stderr, "Current time =%d\n", current_time); | |
4939 fprintf(stderr, "Current vol=%f on channel %d\n", current_volume, i); | |
4940 */ | |
4941 } /* End if not PAUSED */ | |
4942 } /* End if fade_enabled */ | |
4943 | |
4944 | |
4945 /* Okay, now that the time expired and fading stuff | |
4946 * is done, do the rest of the hard stuff | |
4947 */ | |
4948 | |
4949 | |
4950 /* For predecoded, check to see if done */ | |
4951 if( ALmixer_Channel_List[i].almixer_data->decoded_all ) | |
4952 { | |
4953 | |
4954 #if 0 | |
4955 /********* Remove this **********/ | |
4956 ALint buffers_processed; | |
4957 ALint buffers_still_queued; | |
4958 fprintf(stderr, "For Predecoded\n"); | |
4959 | |
4960 alGetSourcei( | |
4961 ALmixer_Channel_List[i].alsource, | |
4962 AL_SOURCE_STATE, &state | |
4963 ); | |
4964 switch(state) { | |
4965 case AL_PLAYING: | |
4966 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
4967 break; | |
4968 case AL_PAUSED: | |
4969 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
4970 break; | |
4971 case AL_STOPPED: | |
4972 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
4973 break; | |
4974 case AL_INITIAL: | |
4975 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
4976 break; | |
4977 default: | |
4978 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
4979 break; | |
4980 } | |
4981 | |
4982 alGetSourcei( | |
4983 ALmixer_Channel_List[i].alsource, | |
4984 AL_BUFFERS_PROCESSED, &buffers_processed | |
4985 ); | |
4986 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
4987 | |
4988 alGetSourcei( | |
4989 ALmixer_Channel_List[i].alsource, | |
4990 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4991 ); | |
4992 | |
4993 /******** END REMOVE *******/ | |
4994 #endif | |
4995 /* FIXME: Ugh! Somewhere an alError is being thrown ("Invalid Enum Value"), but I can't | |
4996 * find it. It only seems to be thrown for OS X. I placed error messages after every al* | |
4997 * command I could find in the above loops, but the error doesn't seem to show | |
4998 * up until around here. I mistook it for a get queued buffers | |
4999 * error in OS X. I don't think there's an error down there. | |
5000 * For now, I'm clearing the error here. | |
5001 */ | |
5002 | |
5003 if((error = alGetError()) != AL_NO_ERROR) | |
5004 { | |
5005 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
|
5006 alGetString(error)); |
0 | 5007 } |
5008 | |
5009 | |
5010 alGetSourcei( | |
5011 ALmixer_Channel_List[i].alsource, | |
5012 AL_SOURCE_STATE, &state | |
5013 ); | |
5014 if((error = alGetError()) != AL_NO_ERROR) | |
5015 { | |
5016 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
|
5017 alGetString(error)); |
0 | 5018 } |
5019 | |
5020 | |
5021 if(AL_STOPPED == state) | |
5022 { | |
5023 /* Playback has ended. | |
5024 * Loop if necessary, or launch callback | |
5025 * and clear channel (or clear channel and | |
5026 * then launch callback?) | |
5027 */ | |
5028 | |
5029 | |
5030 /* Need to check for loops */ | |
5031 if(ALmixer_Channel_List[i].loops != 0) | |
5032 { | |
5033 /* Corner Case: If the buffer has | |
5034 * been modified using Seek, | |
5035 * the loop will start at the seek | |
5036 * position. | |
5037 */ | |
5038 if(ALmixer_Channel_List[i].loops != -1) | |
5039 { | |
5040 ALmixer_Channel_List[i].loops--; | |
5041 } | |
5042 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5043 if((error = alGetError()) != AL_NO_ERROR) | |
5044 { | |
5045 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
|
5046 alGetString(error)); |
0 | 5047 } |
5048 continue; | |
5049 } | |
5050 /* No loops. End play. */ | |
5051 else | |
5052 { | |
5053 /* Problem: It seems that when mixing | |
5054 * streamed and predecoded sources, | |
5055 * the previous instance lingers, | |
5056 * so we need to force remove | |
5057 * the data from the source. | |
5058 * The sharing problem | |
5059 * occurs when a previous predecoded buffer is played on | |
5060 * a source, and then a streamed source is played later | |
5061 * on that same source. OpenAL isn't consistently | |
5062 * removing the previous buffer so both get played. | |
5063 * (Different dists seem to have different quirks. | |
5064 * The problem might lead to crashes in the worst case.) | |
5065 */ | |
5066 /* Additional problem: There is another | |
5067 * inconsistency among OpenAL distributions. | |
5068 * Both Loki and Creative Windows seem to keep | |
5069 * the buffer queued which requires removing. | |
5070 * But the Creative Macintosh version does | |
5071 * not have any buffer queued after play | |
5072 * and it returns the error: Invalid Enum Value | |
5073 * if I try to unqueue it. | |
5074 * So I'm going to put in a check to see if I | |
5075 * can detect any buffers queued first | |
5076 * and then unqueue them if I can see them. | |
5077 * Additional note: The new CoreAudio based | |
5078 * implementation leaves it's buffer queued | |
5079 * like Loki and Creative Windows. But | |
5080 * considering all the problems I'm having | |
5081 * with the different distributions, this | |
5082 * check seems reasonable. | |
5083 */ | |
5084 ALint buffers_still_queued; | |
5085 if((error = alGetError()) != AL_NO_ERROR) | |
5086 { | |
5087 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
|
5088 alGetString(error)); |
0 | 5089 } |
5090 | |
5091 alGetSourcei( | |
5092 ALmixer_Channel_List[i].alsource, | |
5093 AL_BUFFERS_QUEUED, &buffers_still_queued | |
5094 ); | |
5095 if((error = alGetError()) != AL_NO_ERROR) | |
5096 { | |
5097 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
|
5098 alGetString(error)); |
0 | 5099 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
|
5100 alGetString(error) ); |
0 | 5101 error_flag--; |
5102 } | |
5103 if(buffers_still_queued > 0) | |
5104 { | |
1 | 5105 |
5106 #if 0 /* This triggers an error in OS X Core Audio. */ | |
5107 alSourceUnqueueBuffers( | |
5108 ALmixer_Channel_List[i].alsource, | |
5109 1, | |
5110 ALmixer_Channel_List[i].almixer_data->buffer | |
5111 ); | |
5112 #else | |
5113 /* fprintf(stderr, "In the Bob Aron section...about to clear source\n"); | |
0 | 5114 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 5115 */ |
0 | 5116 /* Rather than force unqueuing the buffer, let's see if |
5117 * setting the buffer to none works (the OpenAL 1.0 | |
5118 * Reference Annotation suggests this should work). | |
5119 */ | |
5120 alSourcei(ALmixer_Channel_List[i].alsource, | |
5121 AL_BUFFER, AL_NONE); | |
5122 /* | |
5123 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5124 */ | |
1 | 5125 #endif |
0 | 5126 if((error = alGetError()) != AL_NO_ERROR) |
5127 { | |
5128 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
|
5129 alGetString(error)); |
0 | 5130 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
|
5131 alGetString(error) ); |
0 | 5132 error_flag--; |
5133 } | |
5134 | |
5135 } | |
5136 | |
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
|
5137 /* 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
|
5138 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
|
5139 |
0 | 5140 Clean_Channel(i); |
5141 /* Subtract counter */ | |
5142 Is_Playing_global--; | |
5143 | |
5144 | |
5145 /* We're done for this loop. | |
5146 * Go to next channel | |
5147 */ | |
5148 continue; | |
5149 } | |
5150 continue; | |
5151 } | |
5152 } /* End if decoded_all */ | |
5153 /* For streamed */ | |
5154 else | |
5155 { | |
5156 ALint buffers_processed; | |
5157 ALint buffers_still_queued; | |
5158 ALint current_buffer_id; | |
5159 | |
5160 ALuint unqueued_buffer_id; | |
5161 #if 0 | |
5162 /********* Remove this **********/ | |
5163 fprintf(stderr, "For Streamed\n"); | |
5164 | |
5165 alGetSourcei( | |
5166 ALmixer_Channel_List[i].alsource, | |
5167 AL_SOURCE_STATE, &state | |
5168 ); | |
5169 switch(state) { | |
5170 case AL_PLAYING: | |
5171 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
5172 break; | |
5173 case AL_PAUSED: | |
5174 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
5175 break; | |
5176 case AL_STOPPED: | |
5177 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
5178 break; | |
5179 case AL_INITIAL: | |
5180 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
5181 break; | |
5182 default: | |
5183 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
5184 break; | |
5185 } | |
5186 /******** END REMOVE *******/ | |
5187 #endif | |
5188 /* Get the number of buffers still queued */ | |
5189 alGetSourcei( | |
5190 ALmixer_Channel_List[i].alsource, | |
5191 AL_BUFFERS_QUEUED, &buffers_still_queued | |
5192 ); | |
5193 if((error = alGetError()) != AL_NO_ERROR) | |
5194 { | |
5195 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
|
5196 alGetString(error)); |
0 | 5197 } |
5198 /* Get the number of buffers processed | |
5199 * so we know if we need to refill | |
5200 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5201 /* 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
|
5202 * 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
|
5203 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5204 // fprintf(stderr, "calling AL_BUFFERS_PROCESSED on source:%d", ALmixer_Channel_List[i].alsource); |
0 | 5205 alGetSourcei( |
5206 ALmixer_Channel_List[i].alsource, | |
5207 AL_BUFFERS_PROCESSED, &buffers_processed | |
5208 ); | |
5209 if((error = alGetError()) != AL_NO_ERROR) | |
5210 { | |
5211 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
|
5212 alGetString(error)); |
0 | 5213 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5214 // fprintf(stderr, "finished AL_BUFFERS_PROCESSED, buffers_processed=%d", buffers_processed); |
0 | 5215 |
5216 /* WTF!!! The Nvidia distribution is failing on the alGetSourcei(source, AL_BUFFER, buf_id) call. | |
5217 * I need this call to figure out which buffer OpenAL is currently playing. | |
5218 * It keeps returning an "Invalid Enum" error. | |
5219 * This is totally inane! It's a basic query. | |
5220 * By the spec, this functionality is not explicitly defined so Nvidia refuses to | |
5221 * fix this behavior, even though all other distributions work fine with this. | |
5222 * The only workaround for this is for | |
5223 * a significant rewrite of my code which requires me to | |
5224 * duplicate the OpenAL queued buffers state with my own | |
5225 * code and try to derive what the current playing buffer is by indirect observation of | |
5226 * looking at buffers_processed. But of course this has a ton of downsides since my | |
5227 * queries do not give me perfect timing of what OpenAL is actually doing and | |
5228 * the fact that some of the distributions seem to have buffer queuing problems | |
5229 * with their query results (CoreAudio). This also means a ton of extra code | |
5230 * on my side. The lack of support of a 1 line call has required me to | |
5231 * implement yet another entire state machine. <sigh> | |
5232 */ | |
5233 #if 0 /* This code will not work until possibly OpenAL 1.1 because of Nvidia */ | |
5234 /* Get the id to the current buffer playing */ | |
5235 alGetSourcei( | |
5236 ALmixer_Channel_List[i].alsource, | |
5237 AL_BUFFER, ¤t_buffer_id | |
5238 ); | |
5239 if((error = alGetError()) != AL_NO_ERROR) | |
5240 { | |
5241 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
|
5242 alGetString(error)); |
0 | 5243 } |
5244 | |
5245 /* Before the hard stuff, check to see if the | |
5246 * current queued AL buffer has changed. | |
5247 * If it has, we should launch a data callback if | |
5248 * necessary | |
5249 */ | |
5250 if( ((ALuint)current_buffer_id) != | |
5251 ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5252 { | |
5253 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5254 = (ALuint)current_buffer_id; | |
5255 | |
5256 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5257 } | |
5258 #else | |
5259 /* Only do this if "access_data" was requested (i.e. the circular_buffer!=NULL) | |
5260 * And if one of the two are true: | |
5261 * Either buffers_processed > 0 (because the current_buffer might have changed) | |
5262 * or if the current_buffer==0 (because we are in an initial state or recovering from | |
5263 * a buffer underrun) | |
5264 */ | |
5265 if((ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5266 && ( | |
5267 (buffers_processed > 0) || (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5268 ) | |
5269 ) | |
5270 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5271 ALint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5272 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5273 ALubyte is_out_of_sync = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5274 ALuint my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
1 | 5275 /* Ugh, I have to deal with signed/unsigned mismatch here. */ |
5276 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
|
5277 ALuint unplayed_buffers; |
1 | 5278 if(buffers_unplayed_int < 0) |
5279 { | |
5280 unplayed_buffers = 0; | |
5281 } | |
5282 else | |
5283 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5284 unplayed_buffers = (ALuint)buffers_unplayed_int; |
1 | 5285 } |
0 | 5286 /* |
5287 fprintf(stderr, "Queue in processed check, before pop, buffers_processed=%d\n", buffers_processed); | |
5288 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5289 */ | |
5290 /* We can't make any determinations solely based on the number of buffers_processed | |
5291 * because currently, we only unqueue 1 buffer per loop. That means if 2 or more | |
5292 * buffers became processed in one loop, the following loop, we would have | |
5293 * at least that_many-1 buffers_processed (plus possible new processed). | |
5294 * If we tried to just remove 1 buffer from our queue, we would be incorrect | |
5295 * because we would not actually reflect the current playing buffer. | |
5296 * So the solution seems to be to make sure our queue is the same size | |
5297 * as the number of buffers_queued-buffers_processed, and return the head of our queue | |
5298 * as the current playing buffer. | |
5299 */ | |
5300 /* Also, we have a corner case. When we first start playing or if we have | |
5301 * a buffer underrun, we have not done a data callback. | |
5302 * In this case, we need to see if there is any new data in our queue | |
5303 * and if so, launch that data callback. | |
5304 */ | |
5305 /* Warning, this code risks the possibility of no data callback being fired if | |
5306 * the system is really late (or skipped buffers). | |
5307 */ | |
5308 | |
5309 /* First, let's syncronize our queue with the OpenAL queue */ | |
5310 #if 0 | |
5311 fprintf(stderr, "inside, Buffers processed=%d, Buffers queued=%d, my queue=%d\n", | |
5312 buffers_processed, buffers_still_queued, my_queue_size); | |
1 | 5313 #endif |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5314 is_out_of_sync = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5315 for(k=0; k<buffers_processed; k++) |
0 | 5316 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5317 queue_ret_flag = CircularQueueUnsignedInt_PopFront( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5318 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
|
5319 if(0 == queue_ret_flag) |
0 | 5320 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5321 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
|
5322 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5323 } |
0 | 5324 my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
5325 /* We have several possibilities we need to handle: | |
5326 * 1) We are in an initial state or underrun and need to do a data callback on the head. | |
5327 * 2) We were out of sync and need to do a new data callback on the new head. | |
5328 * 3) We were not out of sync but just had left over processed buffers which caused us to | |
5329 * fall in this block of code. (Don't do anything.) | |
5330 */ | |
5331 if( (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) || (1 == is_out_of_sync) ) | |
5332 { | |
5333 if(my_queue_size > 0) | |
5334 { | |
5335 current_buffer_id = CircularQueueUnsignedInt_Front( | |
5336 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5337 if(0 == current_buffer_id) | |
5338 { | |
5339 fprintf(stderr, "53a Internal Error, current_buffer_id=0 when it shouldn't be 0\n"); | |
5340 } | |
5341 /* | |
5342 else | |
5343 { | |
5344 fprintf(stderr, "Queue in processed check, after pop\n"); | |
5345 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5346 } | |
5347 */ | |
5348 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5349 = (ALuint)current_buffer_id; | |
5350 | |
5351 #if 0 | |
5352 /* Remove me...only for checking...doesn't work on Nvidia */ | |
5353 { | |
5354 ALuint real_id; | |
5355 alGetSourcei( | |
5356 ALmixer_Channel_List[i].alsource, | |
5357 AL_BUFFER, &real_id | |
5358 ); | |
5359 alGetError(); | |
5360 fprintf(stderr, "Callback fired on data buffer=%d, real_id shoud be=%d\n", current_buffer_id, real_id); | |
5361 } | |
5362 #endif | |
5363 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5364 } | |
5365 else | |
5366 { | |
1 | 5367 /* |
0 | 5368 fprintf(stderr, "53b, Notice/Warning:, OpenAL queue has been depleted.\n"); |
1 | 5369 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
5370 */ | |
0 | 5371 /* In this case, we might either be in an underrun or finished with playback */ |
5372 ALmixer_Channel_List[i].almixer_data->current_buffer = 0; | |
5373 } | |
5374 } | |
5375 } | |
5376 #endif | |
5377 | |
5378 | |
5379 | |
5380 /* Just a test - remove | |
5381 if( ALmixer_Channel_List[i].loops > 0) | |
5382 { | |
5383 fprintf(stderr, ">>>>>>>>>>>>>>>Loops = %d\n", | |
5384 ALmixer_Channel_List[i].loops); | |
5385 } | |
5386 */ | |
5387 #if 0 | |
5388 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
5389 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5390 #endif | |
5391 /* We've used up a buffer so we need to unqueue and replace */ | |
5392 /* Okay, it gets more complicated here: | |
5393 * We need to Queue more data | |
5394 * if buffers_processed > 0 or | |
5395 * if num_of_buffers_in_use < NUMBER_OF_QUEUE_BUFFERS | |
5396 * but we don't do this if at EOF, | |
5397 * except when there is looping | |
5398 */ | |
5399 /* For this to work, we must rely on EVERYTHING | |
5400 * else to unset the EOF if there is looping. | |
5401 * Remember, even Play() must do this | |
5402 */ | |
5403 | |
5404 /* If not EOF, then we are still playing. | |
5405 * Inside, we might find num_of_buffers < NUM...QUEUE_BUF.. | |
5406 * or buffers_process > 0 | |
5407 * in which case we queue up. | |
5408 * We also might find no buffers we need to fill, | |
5409 * in which case we just keep going | |
5410 */ | |
5411 if( ! ALmixer_Channel_List[i].almixer_data->eof) | |
5412 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5413 ALuint bytes_returned; |
0 | 5414 /* We have a priority. We first must assign |
5415 * unused buffers in reserve. If there is nothing | |
5416 * left, then we may unqueue buffers. We can't | |
5417 * do it the other way around because we will | |
5418 * lose the pointer to the unqueued buffer | |
5419 */ | |
5420 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5421 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5422 { | |
1 | 5423 #if 0 |
0 | 5424 fprintf(stderr, "Getting more data in NOT_EOF and num_buffers_in_use (%d) < max_queue (%d)\n", |
5425 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5426 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5427 #endif |
0 | 5428 /* Going to add an unused packet. |
5429 * Grab next packet */ | |
5430 bytes_returned = GetMoreData( | |
5431 ALmixer_Channel_List[i].almixer_data, | |
5432 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5433 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5434 ); | |
5435 } | |
5436 /* For processed > 0 */ | |
5437 else if(buffers_processed > 0) | |
5438 { | |
5439 /* Unqueue only 1 buffer for now. | |
5440 * If there are more than one, | |
5441 * let the next Update pass deal with it | |
5442 * so we don't stall the program for too long. | |
5443 */ | |
5444 #if 0 | |
5445 fprintf(stderr, "About to Unqueue, Buffers processed = %d\n", buffers_processed); | |
5446 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5447 fprintf(stderr, "Unqueuing a buffer\n"); | |
5448 #endif | |
5449 alSourceUnqueueBuffers( | |
5450 ALmixer_Channel_List[i].alsource, | |
5451 1, &unqueued_buffer_id | |
5452 ); | |
5453 if((error = alGetError()) != AL_NO_ERROR) | |
5454 { | |
5455 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
|
5456 alGetString(error)); |
0 | 5457 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
|
5458 alGetString(error) ); |
0 | 5459 error_flag--; |
5460 } | |
5461 /* | |
5462 fprintf(stderr, "Right after unqueue..."); | |
5463 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5464 fprintf(stderr, "Getting more data for NOT_EOF, max_buffers filled\n"); | |
5465 */ | |
5466 /* Grab unqueued packet */ | |
5467 bytes_returned = GetMoreData( | |
5468 ALmixer_Channel_List[i].almixer_data, | |
5469 unqueued_buffer_id); | |
5470 } | |
5471 /* We are still streaming, but currently | |
5472 * don't need to fill any buffers */ | |
5473 else | |
5474 { | |
5475 /* Might want to check state */ | |
5476 /* In case the playback stopped, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5477 * we need to resume |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5478 * a.k.a. buffer underrun |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5479 */ |
1 | 5480 #if 1 |
5481 /* Try not refetching the state here because I'm getting a duplicate | |
5482 buffer playback (hiccup) */ | |
0 | 5483 alGetSourcei( |
5484 ALmixer_Channel_List[i].alsource, | |
5485 AL_SOURCE_STATE, &state | |
5486 ); | |
1 | 5487 if((error = alGetError()) != AL_NO_ERROR) |
5488 { | |
5489 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
|
5490 alGetString(error)); |
1 | 5491 } |
5492 /* Get the number of buffers processed | |
5493 */ | |
5494 alGetSourcei( | |
5495 ALmixer_Channel_List[i].alsource, | |
5496 AL_BUFFERS_PROCESSED, | |
5497 &buffers_processed | |
5498 ); | |
5499 if((error = alGetError()) != AL_NO_ERROR) | |
5500 { | |
5501 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
|
5502 alGetString(error)); |
1 | 5503 } |
5504 #endif | |
0 | 5505 if(AL_STOPPED == state) |
5506 { | |
5507 /* Resuming in not eof, but nothing to buffer */ | |
1 | 5508 |
5509 /* Okay, here's another lately discovered problem: | |
5510 * I can't find it in the spec, but for at least some of the | |
5511 * implementations, if I call play on a stopped source that | |
5512 * has processed buffers, all those buffers get marked as unprocessed | |
5513 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5514 * processed, on resume, the earlier 24 buffers will get replayed, | |
5515 * causing a "hiccup" like sound in the playback. | |
5516 * To avoid this, I must unqueue all processed buffers before | |
5517 * calling play. But to complicate things, I need to worry about resyncing | |
5518 * the circular queue with this since I designed this thing | |
5519 * with some correlation between the two. However, I might | |
5520 * have already handled this, so I will try writing this code without | |
5521 * syncing for now. | |
5522 * There is currently an assumption that a buffer | |
5523 * was queued above so I actually have something | |
5524 * to play. | |
5525 */ | |
5526 ALint temp_count; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5527 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5528 fprintf(stderr, "STOPPED1, need to clear processed=%d, status is:\n", buffers_processed); |
1 | 5529 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
|
5530 #endif |
1 | 5531 for(temp_count=0; temp_count<buffers_processed; temp_count++) |
5532 { | |
5533 alSourceUnqueueBuffers( | |
5534 ALmixer_Channel_List[i].alsource, | |
5535 1, &unqueued_buffer_id | |
5536 ); | |
5537 if((error = alGetError()) != AL_NO_ERROR) | |
5538 { | |
5539 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
|
5540 alGetString(error)); |
1 | 5541 error_flag--; |
5542 } | |
5543 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5544 #if 0 |
1 | 5545 fprintf(stderr, "After unqueue clear...:\n"); |
5546 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
|
5547 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5548 /* 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
|
5549 * 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
|
5550 * 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
|
5551 * 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
|
5552 * no buffers in queue. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5553 * 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
|
5554 * Then we need to resume playing. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5555 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5556 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5557 int buffers_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5558 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5559 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5560 AL_BUFFERS_QUEUED, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5561 &buffers_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5562 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5563 |
1 | 5564 if((error = alGetError()) != AL_NO_ERROR) |
5565 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5566 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
|
5567 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5568 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5569 assert(buffers_queued == 0); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5570 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
|
5571 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5572 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5573 /* 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
|
5574 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
|
5575 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5576 /* 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
|
5577 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5578 ALmixer_Channel_List[i].almixer_data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5579 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
|
5580 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5581 /* 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
|
5582 * 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
|
5583 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5584 if(bytes_returned > 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5585 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5586 /* Queue up the new data */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5587 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5588 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5589 1, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5590 &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
|
5591 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5592 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5593 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5594 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
|
5595 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5596 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5597 /* 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
|
5598 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
|
5599 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5600 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5601 /* 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
|
5602 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
|
5603 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5604 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5605 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
|
5606 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5607 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
|
5608 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
|
5609 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5610 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5611 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5612 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
|
5613 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
|
5614 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5615 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5616 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5617 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5618 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5619 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5620 /* Resume playback from underrun */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5621 alSourcePlay(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5622 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5623 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5624 fprintf(stderr, "55Tbesting error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5625 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5626 } |
1 | 5627 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5628 |
0 | 5629 } |
5630 /* Let's escape to the next loop. | |
5631 * All code below this point is for queuing up | |
5632 */ | |
5633 /* | |
1 | 5634 fprintf(stderr, "Entry: Nothing to do...continue\n\n"); |
5635 */ | |
0 | 5636 continue; |
5637 } | |
5638 /* We now know we have to fill an available | |
5639 * buffer. | |
5640 */ | |
5641 | |
5642 /* In the previous branch, we just grabbed more data. | |
5643 * Let's check it to make sure it's okay, | |
5644 * and then queue it up | |
5645 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5646 /* This check doesn't work anymore because it is now ALuint */ |
0 | 5647 #if 0 |
5648 if(-1 == bytes_returned) | |
5649 { | |
5650 /* Problem occurred...not sure what to do */ | |
5651 /* Go to next loop? */ | |
5652 error_flag--; | |
5653 /* Set the eof flag to force a quit so | |
5654 * we don't get stuck in an infinite loop | |
5655 */ | |
5656 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5657 continue; | |
5658 } | |
5659 #endif | |
5660 /* This is a special case where we've run | |
5661 * out of data. We should check for loops | |
5662 * and get more data. If there is no loop, | |
5663 * then do nothing and wait for future | |
5664 * update passes to handle the EOF. | |
5665 * The advantage of handling the loop here | |
5666 * instead of waiting for play to stop is | |
5667 * that we should be able to keep the buffer | |
5668 * filled. | |
5669 */ | |
5670 #if 0 | |
5671 else if(0 == bytes_returned) | |
5672 #endif | |
5673 if(0 == bytes_returned) | |
5674 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5675 /* |
0 | 5676 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
|
5677 */ |
0 | 5678 /* Check for loops */ |
5679 if( ALmixer_Channel_List[i].loops != 0 ) | |
5680 { | |
5681 /* We have to loop, so rewind | |
5682 * and fetch more data | |
5683 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5684 /* |
0 | 5685 fprintf(stderr, "Rewinding data\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5686 */ |
0 | 5687 if(0 == Sound_Rewind( |
5688 ALmixer_Channel_List[i].almixer_data->sample)) | |
5689 { | |
5690 fprintf(stderr, "Rewinding failed\n"); | |
5691 ALmixer_SetError( Sound_GetError() ); | |
5692 ALmixer_Channel_List[i].loops = 0; | |
5693 error_flag--; | |
5694 /* We'll continue on because we do have some valid data */ | |
5695 continue; | |
5696 } | |
5697 /* Remember to reset the data->eof flag */ | |
5698 ALmixer_Channel_List[i].almixer_data->eof = 0; | |
5699 if(ALmixer_Channel_List[i].loops > 0) | |
5700 { | |
5701 ALmixer_Channel_List[i].loops--; | |
5702 } | |
5703 /* Try grabbing another packet now. | |
5704 * Since we may have already unqueued a | |
5705 * buffer, we don't want to lose it. | |
5706 */ | |
5707 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5708 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5709 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5710 /* |
0 | 5711 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
|
5712 */ |
0 | 5713 /* Grab next packet */ |
5714 bytes_returned = GetMoreData( | |
5715 ALmixer_Channel_List[i].almixer_data, | |
5716 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5717 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5718 ); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5719 /* |
0 | 5720 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
|
5721 */ |
0 | 5722 } |
5723 /* Refilling unqueued packet */ | |
5724 else | |
5725 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5726 /* |
0 | 5727 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
|
5728 */ |
0 | 5729 /* Grab next packet */ |
5730 bytes_returned = GetMoreData( | |
5731 ALmixer_Channel_List[i].almixer_data, | |
5732 unqueued_buffer_id); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5733 /* |
0 | 5734 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
|
5735 */ |
0 | 5736 } |
5737 /* Another error check */ | |
5738 /* | |
5739 if(bytes_returned <= 0) | |
5740 */ | |
5741 if(0 == bytes_returned) | |
5742 { | |
5743 fprintf(stderr, "??????????ERROR\n"); | |
5744 ALmixer_SetError("Could not loop because after rewind, no data could be retrieved"); | |
5745 /* Problem occurred...not sure what to do */ | |
5746 /* Go to next loop? */ | |
5747 error_flag--; | |
5748 /* Set the eof flag to force a quit so | |
5749 * we don't get stuck in an infinite loop | |
5750 */ | |
5751 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5752 continue; | |
5753 } | |
5754 /* We made it to the end. We still need | |
5755 * to BufferData, so let this branch | |
5756 * fall into the next piece of | |
5757 * code below which will handle that | |
5758 */ | |
5759 | |
5760 | |
5761 } /* END loop check */ | |
5762 else | |
5763 { | |
5764 /* No more loops to do. | |
5765 * EOF flag should be set. | |
5766 * Just go to next loop and | |
5767 * let things be handled correctly | |
5768 * in future update calls | |
5769 */ | |
1 | 5770 /* |
0 | 5771 fprintf(stderr, "SHOULD BE EOF\n"); |
5772 | |
5773 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
1 | 5774 */ |
0 | 5775 continue; |
5776 } | |
5777 } /* END if bytes_returned == 0 */ | |
5778 /********* Possible trouble point. I might be queueing empty buffers on the mac. | |
5779 * This check doesn't say if the buffer is valid. Only the EOF assumption is a clue at this point | |
5780 */ | |
5781 /* Fall here */ | |
5782 /* Everything is normal. We aren't | |
5783 * at an EOF, but need to simply | |
5784 * queue more data. The data is already checked for good, | |
5785 * so queue it up */ | |
5786 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5787 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5788 { | |
5789 /* Keep count of how many buffers we have | |
5790 * to queue so we can return the value | |
5791 */ | |
5792 retval++; | |
1 | 5793 /* |
0 | 5794 fprintf(stderr, "NOT_EOF???, about to Queue more data for num_buffers (%d) < max_queue (%d)\n", |
5795 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5796 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5797 */ |
0 | 5798 alSourceQueueBuffers( |
5799 ALmixer_Channel_List[i].alsource, | |
5800 1, | |
5801 &ALmixer_Channel_List[i].almixer_data->buffer[ | |
5802 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5803 ); | |
5804 if((error = alGetError()) != AL_NO_ERROR) | |
5805 { | |
5806 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
|
5807 alGetString(error)); |
0 | 5808 } |
5809 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5810 * which buffer to show during callbacks (for things like | |
5811 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5812 * data structure. This code will be called only if | |
5813 * "access_data" was set, indicated by whether the queue is NULL. | |
5814 */ | |
5815 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5816 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5817 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5818 // fprintf(stderr, "56d: CircularQueue_PushBack.\n"); |
0 | 5819 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5820 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5821 ALmixer_Channel_List[i].almixer_data->buffer[ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5822 ); | |
5823 if(0 == queue_ret_flag) | |
5824 { | |
5825 fprintf(stderr, "56aSerious internal error: CircularQueue could not push into queue.\n"); | |
5826 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5827 } | |
5828 /* | |
5829 else | |
5830 { | |
5831 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5832 } | |
5833 */ | |
5834 } | |
5835 } | |
5836 /* for processed > 0 */ | |
5837 else | |
5838 { | |
5839 /* Keep count of how many buffers we have | |
5840 * to queue so we can return the value | |
5841 */ | |
5842 retval++; | |
5843 /* | |
5844 fprintf(stderr, "NOT_EOF, about to Queue more data for filled max_queue (%d)\n", | |
5845 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
5846 */ | |
5847 alSourceQueueBuffers( | |
5848 ALmixer_Channel_List[i].alsource, | |
5849 1, &unqueued_buffer_id); | |
5850 if((error = alGetError()) != AL_NO_ERROR) | |
5851 { | |
5852 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
|
5853 alGetString(error) ); |
0 | 5854 error_flag--; |
5855 continue; | |
5856 } | |
5857 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5858 * which buffer to show during callbacks (for things like | |
5859 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5860 * data structure. This code will be called only if | |
5861 * "access_data" was set, indicated by whether the queue is NULL. | |
5862 */ | |
5863 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5864 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5865 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5866 // fprintf(stderr, "56e: CircularQueue_PushBack.\n"); |
0 | 5867 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5868 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5869 unqueued_buffer_id | |
5870 ); | |
5871 if(0 == queue_ret_flag) | |
5872 { | |
5873 fprintf(stderr, "56bSerious internal error: CircularQueue could not push into queue.\n"); | |
5874 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5875 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5876 #if 0 |
0 | 5877 else |
5878 { | |
5879 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5880 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5881 #endif |
0 | 5882 } |
5883 } | |
5884 /* If we used an available buffer queue, | |
5885 * then we need to update the number of them in use | |
5886 */ | |
5887 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5888 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5889 { | |
5890 /* Increment the number of buffers in use */ | |
5891 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use++; | |
5892 } | |
5893 /* Might want to check state */ | |
5894 /* In case the playback stopped, | |
5895 * we need to resume */ | |
1 | 5896 #if 1 |
5897 /* Try not refetching the state here because I'm getting a duplicate | |
5898 buffer playback (hiccup) */ | |
0 | 5899 alGetSourcei( |
5900 ALmixer_Channel_List[i].alsource, | |
5901 AL_SOURCE_STATE, &state | |
5902 ); | |
1 | 5903 if((error = alGetError()) != AL_NO_ERROR) |
5904 { | |
5905 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
|
5906 alGetString(error)); |
1 | 5907 } |
5908 /* Get the number of buffers processed | |
5909 */ | |
5910 alGetSourcei( | |
5911 ALmixer_Channel_List[i].alsource, | |
5912 AL_BUFFERS_PROCESSED, | |
5913 &buffers_processed | |
5914 ); | |
5915 if((error = alGetError()) != AL_NO_ERROR) | |
5916 { | |
5917 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
|
5918 alGetString(error)); |
1 | 5919 } |
5920 #endif | |
0 | 5921 if(AL_STOPPED == state) |
5922 { | |
1 | 5923 /* |
0 | 5924 fprintf(stderr, "Resuming in not eof\n"); |
1 | 5925 */ |
5926 /* Okay, here's another lately discovered problem: | |
5927 * I can't find it in the spec, but for at least some of the | |
5928 * implementations, if I call play on a stopped source that | |
5929 * has processed buffers, all those buffers get marked as unprocessed | |
5930 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5931 * processed, on resume, the earlier 24 buffers will get replayed, | |
5932 * causing a "hiccup" like sound in the playback. | |
5933 * To avoid this, I must unqueue all processed buffers before | |
5934 * calling play. But to complicate things, I need to worry about resyncing | |
5935 * the circular queue with this since I designed this thing | |
5936 * with some correlation between the two. However, I might | |
5937 * have already handled this, so I will try writing this code without | |
5938 * syncing for now. | |
5939 * There is currently an assumption that a buffer | |
5940 * was queued above so I actually have something | |
5941 * to play. | |
5942 */ | |
5943 ALint temp_count; | |
5944 /* | |
5945 fprintf(stderr, "STOPPED2, need to clear processed, status is:\n"); | |
5946 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5947 */ | |
5948 | |
5949 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5950 { | |
5951 alSourceUnqueueBuffers( | |
5952 ALmixer_Channel_List[i].alsource, | |
5953 1, &unqueued_buffer_id | |
5954 ); | |
5955 if((error = alGetError()) != AL_NO_ERROR) | |
5956 { | |
5957 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
|
5958 alGetString(error)); |
1 | 5959 error_flag--; |
5960 } | |
5961 } | |
5962 /* | |
5963 fprintf(stderr, "After unqueue clear...:\n"); | |
5964 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5965 */ | |
5966 | |
5967 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5968 if((error = alGetError()) != AL_NO_ERROR) | |
5969 { | |
5970 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
|
5971 alGetString(error)); |
1 | 5972 } |
0 | 5973 } |
5974 continue; | |
5975 } /* END if( ! eof) */ | |
5976 /* We have hit EOF in the SDL_Sound sample and there | |
5977 * are no more loops. However, there may still be | |
5978 * buffers in the OpenAL queue which still need to | |
5979 * be played out. The following body of code will | |
5980 * determine if play is still happening or | |
5981 * initiate the stop/cleanup sequenece. | |
5982 */ | |
5983 else | |
5984 { | |
5985 /* Let's continue to remove the used up | |
5986 * buffers as they come in. */ | |
5987 if(buffers_processed > 0) | |
5988 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5989 ALint temp_count; |
0 | 5990 /* Do as a for-loop because I don't want |
5991 * to have to create an array for the | |
5992 * unqueued_buffer_id's | |
5993 */ | |
5994 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5995 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5996 /* |
0 | 5997 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
|
5998 */ |
0 | 5999 alSourceUnqueueBuffers( |
6000 ALmixer_Channel_List[i].alsource, | |
6001 1, &unqueued_buffer_id | |
6002 ); | |
6003 if((error = alGetError()) != AL_NO_ERROR) | |
6004 { | |
6005 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
|
6006 alGetString(error)); |
0 | 6007 } |
6008 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6009 /* |
0 | 6010 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
|
6011 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6012 |
0 | 6013 /* Need to update counts since we removed everything. |
6014 * If we don't update the counts here, we end up in the | |
6015 * "Shouldn't be here section, but maybe it's okay due to race conditions" | |
6016 */ | |
6017 alGetSourcei( | |
6018 ALmixer_Channel_List[i].alsource, | |
6019 AL_BUFFERS_QUEUED, &buffers_still_queued | |
6020 ); | |
6021 if((error = alGetError()) != AL_NO_ERROR) | |
6022 { | |
6023 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
|
6024 alGetString(error)); |
0 | 6025 } |
6026 /* Get the number of buffers processed | |
6027 * so we know if we need to refill | |
6028 */ | |
6029 alGetSourcei( | |
6030 ALmixer_Channel_List[i].alsource, | |
6031 AL_BUFFERS_PROCESSED, &buffers_processed | |
6032 ); | |
6033 if((error = alGetError()) != AL_NO_ERROR) | |
6034 { | |
6035 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
|
6036 alGetString(error)); |
0 | 6037 } |
6038 } | |
6039 | |
6040 | |
6041 /* Else if buffers_processed == 0 | |
6042 * and buffers_still_queued == 0. | |
6043 * then we check to see if the source | |
6044 * is still playing. Quit if stopped | |
6045 * We shouldn't need to worry about | |
6046 * looping because that should have | |
6047 * been handled above. | |
6048 */ | |
6049 if(0 == buffers_still_queued) | |
6050 { | |
6051 /* Make sure playback has stopped before | |
6052 * we shutdown. | |
6053 */ | |
6054 alGetSourcei( | |
6055 ALmixer_Channel_List[i].alsource, | |
6056 AL_SOURCE_STATE, &state | |
6057 ); | |
6058 if((error = alGetError()) != AL_NO_ERROR) | |
6059 { | |
6060 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
|
6061 alGetString(error)); |
0 | 6062 } |
6063 if(AL_STOPPED == state) | |
6064 { | |
6065 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use = 0; | |
6066 /* Playback has ended. | |
6067 * Loop if necessary, or launch callback | |
6068 * and clear channel (or clear channel and | |
6069 * 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
|
6070 * Update: Need to do callback first because I reference the mixer_data and source |
0 | 6071 */ |
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
|
6072 |
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
|
6073 /* 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
|
6074 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
|
6075 |
0 | 6076 Clean_Channel(i); |
6077 /* Subtract counter */ | |
6078 Is_Playing_global--; | |
6079 | |
6080 | |
6081 /* We're done for this loop. | |
6082 * Go to next channel | |
6083 */ | |
6084 continue; | |
6085 } | |
6086 } /* End end-playback */ | |
6087 else | |
6088 { | |
6089 /* Need to run out buffer */ | |
6090 #if 1 | |
6091 /* Might want to check state */ | |
6092 /* In case the playback stopped, | |
6093 * we need to resume */ | |
6094 alGetSourcei( | |
6095 ALmixer_Channel_List[i].alsource, | |
6096 AL_SOURCE_STATE, &state | |
6097 ); | |
6098 if((error = alGetError()) != AL_NO_ERROR) | |
6099 { | |
6100 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
|
6101 alGetString(error)); |
0 | 6102 } |
6103 if(AL_STOPPED == state) | |
6104 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6105 /* |
0 | 6106 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
|
6107 */ |
1 | 6108 /* |
0 | 6109 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 6110 */ |
0 | 6111 /* Rather than force unqueuing the buffer, let's see if |
6112 * setting the buffer to none works (the OpenAL 1.0 | |
6113 * Reference Annotation suggests this should work). | |
6114 */ | |
6115 alSourcei(ALmixer_Channel_List[i].alsource, | |
6116 AL_BUFFER, AL_NONE); | |
6117 /* | |
6118 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
6119 */ | |
6120 /* This doesn't work because in some cases, I think | |
6121 * it causes the sound to be replayed | |
6122 */ | |
6123 /* | |
6124 fprintf(stderr, "Resuming in eof (trying to run out buffers\n"); | |
6125 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
6126 */ | |
6127 } | |
6128 #endif | |
6129 } /* End trap section */ | |
6130 } /* End POST-EOF use-up buffer section */ | |
6131 } /* END Streamed section */ | |
6132 } /* END channel in use */ | |
6133 } /* END for-loop for each channel */ | |
6134 | |
6135 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6136 alcProcessContext(alcGetCurrentContext()); | |
6137 if((error = alGetError()) != AL_NO_ERROR) | |
6138 { | |
6139 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
|
6140 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6141 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6142 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6143 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6144 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6145 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6146 #endif |
0 | 6147 /* Return the number of errors */ |
6148 if(error_flag < 0) | |
6149 { | |
6150 return error_flag; | |
6151 } | |
6152 /* Return the number of buffers that were queued */ | |
6153 return retval; | |
6154 } | |
6155 | |
6156 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6157 /* 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
|
6158 static void my_dummy_audio_callback(void* userdata, ALbyte* stream, int len) |
0 | 6159 { |
6160 } | |
6161 #endif | |
6162 | |
6163 | |
6164 | |
6165 | |
6166 #ifdef ENABLE_ALMIXER_THREADS | |
6167 /* We might need threads. We | |
6168 * must constantly poll OpenAL to find out | |
6169 * if sound is being streamed, if play has | |
6170 * ended, etc. Without threads, this must | |
6171 * be explicitly done by the user. | |
6172 * We could try to do it for them if we | |
6173 * finish the threads. | |
6174 */ | |
6175 | |
6176 static int Stream_Data_Thread_Callback(void* data) | |
6177 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6178 ALint retval; |
0 | 6179 |
6180 while(ALmixer_Initialized) | |
6181 { | |
6182 retval = Update_ALmixer(data); | |
6183 /* 0 means that nothing needed updating and | |
6184 * the function returned quickly | |
6185 */ | |
6186 if(0 == retval) | |
6187 { | |
6188 /* Let's be nice and make the thread sleep since | |
6189 * little work was done in update | |
6190 */ | |
6191 /* Make sure times are multiples of 10 | |
6192 * for optimal performance and accuracy in Linux | |
6193 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6194 ALmixer_Delay(10); |
0 | 6195 } |
6196 else | |
6197 { | |
6198 /* 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
|
6199 ALmixer_Delay(0); |
0 | 6200 } |
6201 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6202 /* |
0 | 6203 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
|
6204 */ |
0 | 6205 return 0; |
6206 } | |
6207 #endif /* End of ENABLE_ALMIXER_THREADS */ | |
6208 | |
6209 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6210 /* 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
|
6211 * 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
|
6212 * so SDL_mixer porting people beware. |
0 | 6213 * Warning: SDL_QuitSubSystem(SDL_INIT_AUDIO) is called which |
6214 * means the SDL audio system will be disabled. It will not | |
6215 * be restored (in case SDL is not actually being used) so | |
6216 * the user will need to restart it if they need it after | |
6217 * OpenAL shuts down. | |
6218 */ | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6219 ALboolean ALmixer_Init(ALuint frequency, ALuint num_sources, ALuint refresh) |
0 | 6220 { |
6221 ALCdevice* dev; | |
6222 ALCcontext* context; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6223 ALint i; |
0 | 6224 ALenum error; |
6225 ALuint* source; | |
6226 | |
6227 #ifdef USING_LOKI_AL_DIST | |
6228 /* The Loki dist requires that I set both the | |
6229 * device and context frequency values separately | |
6230 */ | |
6231 /* Hope this won't overflow */ | |
6232 char device_string[256]; | |
6233 #endif | |
6234 | |
6235 /* (Venting frustration) Damn it! Nobody bothered | |
6236 * documenting how you're supposed to use an attribute | |
6237 * list. In fact, the not even the Loki test program | |
6238 * writers seem to know because they use it inconsistently. | |
6239 * For example, how do you terminate that attribute list? | |
6240 * The Loki test code does it 3 different ways. They | |
6241 * set the last value to 0, or they set it to ALC_INVALID, | |
6242 * or they set two final values: ALC_INVALID, 0 | |
6243 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6244 * but with Creative Labs ALC_INVALID is -1. | |
6245 * So something's going to break. Loki's source | |
6246 * code says to terminate with ALC_INVALID. But I | |
6247 * don't know if that's really true, or it happens | |
6248 * to be a coinicidence because it's defined to 0. | |
6249 * Creative provides no source code, so I can't look at how | |
6250 * they terminate it. | |
6251 * So this is really, really ticking me off... | |
6252 * For now, I'm going to use ALC_INVALID. | |
6253 * (Update...after further review of the API spec, | |
6254 * it seems that a NULL terminated string is the correct | |
6255 * termination value to use, so 0 it is.) | |
6256 */ | |
6257 #if 0 | |
6258 ALint attrlist[] = { | |
6259 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6260 /* Don't know anything about these values. | |
6261 * Trust defaults? */ | |
6262 /* Supposed to be the refresh rate in Hz. | |
6263 * I think 15-120 are supposed to be good | |
6264 * values. Though I haven't gotten any effect except | |
6265 * for one strange instance on a Mac. But it was | |
6266 * unrepeatable. | |
6267 */ | |
6268 #if 0 | |
6269 ALC_REFRESH, 15, | |
6270 #endif | |
6271 /* Sync requires a alcProcessContext() call | |
6272 * for every cycle. By default, this is | |
6273 * not used and the value is AL_FALSE | |
6274 * because it will probably perform | |
6275 * pretty badly for me. | |
6276 */ | |
6277 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6278 ALC_SYNC, AL_TRUE, | |
6279 #else | |
6280 ALC_SYNC, AL_FALSE, | |
6281 #endif | |
6282 /* Looking at the API spec, it implies | |
6283 * that the list be a NULL terminated string | |
6284 * so it's probably not safe to use ALC_INVALID | |
6285 */ | |
6286 /* | |
6287 ALC_INVALID }; | |
6288 */ | |
6289 '\0'}; | |
6290 #endif | |
6291 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6292 * However, if no value is specified, I don't | |
6293 * want it in the list so I can get the OpenAL defaults | |
6294 */ | |
6295 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6296 ALsizei current_attrlist_index = 0; |
0 | 6297 |
6298 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6299 /* More problems: I'm getting bit by endian/signedness issues on | |
6300 * different platforms. I can find the endianess easily enough, | |
6301 * but I don't know how to determine what the correct signedness | |
6302 * is (if such a thing exists). I do know that if I try using | |
6303 * unsigned on OSX with an originally signed sample, I get | |
6304 * distortion. However, I don't have any native unsigned samples | |
6305 * to test. But I'm assuming that the platform must be in the | |
6306 * correct signedness no matter what. | |
6307 * I can either assume everybody is signed, or I can try to | |
6308 * determine the value. If I try to determine the values, | |
6309 * I think my only ability to figure it out will be to open | |
6310 * SDL_Audio, and read what the obtained settings were. | |
6311 * Then shutdown everything. However, I don't even know how | |
6312 * reliable this is. | |
6313 * Update: I think I resolved the issues...forgot to update | |
6314 * these comments when it happened. I should check the revision control | |
6315 * log... Anyway, I think the issue was partly related to me not | |
6316 * doing something correctly with the AudioInfo or some kind | |
6317 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6318 * revision control, I think I might have assumed that SDL_Sound would | |
6319 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6320 * and had to fill one out myself. | |
6321 */ | |
6322 SDL_AudioSpec desired; | |
6323 SDL_AudioSpec obtained; | |
6324 #endif | |
6325 | |
6326 | |
6327 /* Make sure ALmixer isn't already initialized */ | |
6328 if(ALmixer_Initialized) | |
6329 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6330 return AL_FALSE; |
0 | 6331 } |
6332 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6333 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6334 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6335 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6336 /* 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
|
6337 /* 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
|
6338 * 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
|
6339 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6340 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6341 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6342 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6343 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6344 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6345 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6346 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6347 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6348 } |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6349 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6350 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6351 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6352 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
|
6353 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
|
6354 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6355 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6356 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6357 |
0 | 6358 /* Set the defaults */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6359 /* |
0 | 6360 attrlist[0] = ALC_FREQUENCY; |
6361 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6362 attrlist[2] = ALC_SYNC; | |
6363 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6364 attrlist[3] = ALC_TRUE; | |
6365 #else | |
6366 attrlist[3] = ALC_FALSE; | |
6367 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6368 */ |
0 | 6369 /* Set frequency value if it is not 0 */ |
6370 if(0 != frequency) | |
6371 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6372 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6373 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6374 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6375 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6376 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6377 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6378 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6379 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6380 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6381 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6382 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6383 #endif |
0 | 6384 |
6385 /* If the user specifies a refresh value, | |
6386 * make room for it | |
6387 */ | |
6388 if(0 != refresh) | |
6389 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6390 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
|
6391 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6392 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6393 current_attrlist_index++; |
0 | 6394 } |
6395 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6396 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6397 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6398 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6399 |
0 | 6400 /* Initialize SDL_Sound */ |
6401 if(! Sound_Init() ) | |
6402 { | |
6403 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6404 return AL_FALSE; |
0 | 6405 } |
6406 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6407 /* Here is the paranoid check that opens | |
6408 * SDL audio in an attempt to find the correct | |
6409 * system values. | |
6410 */ | |
6411 /* Doesn't have to be the actual value I think | |
6412 * (as long as it doesn't influence format, in | |
6413 * which case I'm probably screwed anyway because OpenAL | |
6414 * may easily choose to do something else). | |
6415 */ | |
6416 desired.freq = 44100; | |
6417 desired.channels = 2; | |
6418 desired.format = AUDIO_S16SYS; | |
6419 desired.callback = my_dummy_audio_callback; | |
6420 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6421 { | |
6422 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6423 /* Now to get really paranoid, we should probably | |
6424 * also assume that the 8bit format is also the | |
6425 * same sign type and set that value | |
6426 */ | |
6427 if(AUDIO_S16SYS == obtained.format) | |
6428 { | |
6429 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6430 } | |
6431 /* Should be AUDIO_U16SYS */ | |
6432 else | |
6433 { | |
6434 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6435 } | |
6436 SDL_CloseAudio(); | |
6437 } | |
6438 else | |
6439 { | |
6440 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6441 */ | |
6442 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6443 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6444 } | |
6445 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6446 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6447 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6448 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
6449 * causes OpenAL and SMPEG to conflict. For some reason | |
6450 * if SDL_Init on audio is active, then all the SMPEG | |
6451 * decoded sound comes out silent. Unfortunately, | |
6452 * Sound_Init() invokes SDL_Init on audio. I'm | |
6453 * not sure why it actually needs it... | |
6454 * But we'll attempt to disable it here after the | |
6455 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
6456 */ | |
6457 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6458 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6459 |
0 | 6460 /* I'm told NULL will call the default string |
6461 * and hopefully do the right thing for each platform | |
6462 */ | |
6463 /* | |
6464 dev = alcOpenDevice( NULL ); | |
6465 */ | |
6466 /* Now I'm told I need to set both the device and context | |
6467 * to have the same sampling rate, so I must pass a string | |
6468 * to OpenDevice(). I don't know how portable these strings are. | |
6469 * I don't even know if the format for strings is | |
6470 * compatible | |
6471 * From the testattrib.c in the Loki test section | |
6472 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
6473 */ | |
6474 | |
6475 #ifdef USING_LOKI_AL_DIST | |
6476 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
6477 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
6478 #else | |
6479 dev = alcOpenDevice( NULL ); | |
6480 #endif | |
6481 if(NULL == dev) | |
6482 { | |
6483 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
|
6484 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6485 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6486 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6487 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6488 /* 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
|
6489 /* 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
|
6490 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6491 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6492 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6493 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6494 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
|
6495 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6496 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
|
6497 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6498 #endif |
0 | 6499 |
6500 context = alcCreateContext(dev, attrlist); | |
6501 if(NULL == context) | |
6502 { | |
6503 ALmixer_SetError("Cannot create a context OpenAL"); | |
6504 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6505 return AL_FALSE; |
0 | 6506 } |
6507 | |
6508 | |
6509 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6510 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6511 * According to Garin Hiebert, this is actually an inconsistency | |
6512 * in the Loki version. The function should return a boolean. | |
6513 * instead of ALC_NO_ERROR. Garin suggested I check via | |
6514 * alcGetError(). | |
6515 */ | |
6516 /* clear the error */ | |
6517 alcGetError(dev); | |
6518 alcMakeContextCurrent(context); | |
6519 | |
6520 error = alcGetError(dev); | |
6521 if( (ALC_NO_ERROR != error) ) | |
6522 { | |
6523 ALmixer_SetError("Could not MakeContextCurrent"); | |
6524 alcDestroyContext(context); | |
6525 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6526 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6527 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6528 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6529 /* 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
|
6530 * 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
|
6531 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6532 * 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
|
6533 * 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
|
6534 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6535 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6536 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6537 ALmixer_Frequency_global = frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6538 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6539 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6540 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
|
6541 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6542 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
|
6543 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6544 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6545 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6546 |
0 | 6547 #if 0 |
6548 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
6549 if(alcGetCurrentContext() != context) | |
6550 { | |
6551 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6552 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6553 * I think this is a bug in the OpenAL implementation. | |
6554 */ | |
6555 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
6556 | |
6557 fprintf(stderr, "Making context current\n"); | |
6558 #ifndef __APPLE__ | |
6559 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
6560 #else | |
6561 if(!alcMakeContextCurrent(context)) | |
6562 #endif | |
6563 { | |
6564 ALmixer_SetError("Could not MakeContextCurrent"); | |
6565 alcDestroyContext(context); | |
6566 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6567 return AL_FALSE; |
0 | 6568 } |
6569 } | |
6570 #endif | |
6571 | |
6572 | |
6573 /* #endif */ | |
6574 /* Saw this in the README with the OS X OpenAL distribution. | |
6575 * It looked interesting and simple, so I thought I might | |
6576 * try it out. | |
6577 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
6578 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
6579 * Audio format, the audio data passed to the | |
6580 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
6581 * usage by removing an audio data conversion | |
6582 * (per source) at render timem at the expense of a larger memory footprint. | |
6583 * | |
6584 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
6585 * setting will be applied to all subsequent | |
6586 * calls to alBufferData(). | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6587 * |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6588 * Update: Some people keep reporting that they see the enable fail on Mac, but I can't reproduce it myself. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6589 * Rather than deal with it right now, I think I am going to make it an opt-in thing. |
0 | 6590 */ |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6591 #if defined(__APPLE__) && defined(ALMIXER_USE_OSX_CONVERT_DATA_UPON_LOADING) |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6592 /* |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6593 iPhone is getting this enum, but is failing on the enable, so I guess I'll define it out. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6594 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6595 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6596 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6597 #else |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6598 /* iOS reports this enum exists, but loading it always fails, so make it Mac only. */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6599 ALenum convert_data_enum = alcGetEnumValue(dev, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING"); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6600 /* |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6601 fprintf(stderr, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING=0x%x", convert_data_enum); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6602 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6603 if(0 != convert_data_enum) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6604 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6605 alEnable(convert_data_enum); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6606 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6607 if( (AL_NO_ERROR != alGetError()) ) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6608 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6609 fprintf(stderr, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING attempted but failed"); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6610 ALmixer_SetError("ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING attempted but failed"); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6611 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6612 #endif |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6613 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6614 #endif /* __APPLE__ */ |
0 | 6615 |
6616 | |
6617 | |
6618 | |
6619 ALmixer_Initialized = 1; | |
6620 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6621 if(num_sources == 0) |
0 | 6622 { |
6623 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
6624 } | |
6625 else | |
6626 { | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6627 /* probably should make Number_of_Channels_global an ALuint, but need to cast which_channel all the time */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6628 Number_of_Channels_global = (ALint)num_sources; |
0 | 6629 } |
6630 Number_of_Reserve_Channels_global = 0; | |
6631 Is_Playing_global = 0; | |
6632 /* Set to Null in case system quit and was reinitialized */ | |
6633 Channel_Done_Callback = NULL; | |
6634 Channel_Done_Callback_Userdata = NULL; | |
6635 Channel_Data_Callback = NULL; | |
1 | 6636 Channel_Data_Callback_Userdata = NULL; |
0 | 6637 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6638 /* Allocate memory for linked list of ALmixerData. */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6639 s_listOfALmixerData = LinkedList_Create(); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6640 if(NULL == s_listOfALmixerData) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6641 { |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6642 ALmixer_SetError("Couldn't create linked list"); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6643 alcDestroyContext(context); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6644 alcCloseDevice(dev); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6645 ALmixer_Initialized = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6646 Number_of_Channels_global = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6647 return AL_FALSE; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6648 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6649 |
0 | 6650 /* Allocate memory for the list of channels */ |
6651 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
6652 if(NULL == ALmixer_Channel_List) | |
6653 { | |
6654 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
|
6655 LinkedList_Free(s_listOfALmixerData); |
0 | 6656 alcDestroyContext(context); |
6657 alcCloseDevice(dev); | |
6658 ALmixer_Initialized = 0; | |
6659 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6660 return AL_FALSE; |
0 | 6661 } |
6662 | |
6663 /* Allocate memory for the list of sources that map to the channels */ | |
6664 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
6665 if(NULL == Source_Map_List) | |
6666 { | |
6667 ALmixer_SetError("Out of Memory for Source Map List"); | |
6668 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6669 LinkedList_Free(s_listOfALmixerData); |
0 | 6670 alcDestroyContext(context); |
6671 alcCloseDevice(dev); | |
6672 ALmixer_Initialized = 0; | |
6673 Number_of_Channels_global = 0; | |
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 /* Create array that will hold the sources */ | |
6678 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
6679 if(NULL == source) | |
6680 { | |
6681 ALmixer_SetError("Out of Memory for sources"); | |
6682 free(Source_Map_List); | |
6683 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6684 LinkedList_Free(s_listOfALmixerData); |
0 | 6685 alcDestroyContext(context); |
6686 alcCloseDevice(dev); | |
6687 ALmixer_Initialized = 0; | |
6688 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6689 return AL_FALSE; |
0 | 6690 } |
6691 | |
6692 /* Clear the error state */ | |
6693 alGetError(); | |
6694 /* Generate the OpenAL sources */ | |
6695 alGenSources(Number_of_Channels_global, source); | |
6696 if( (error=alGetError()) != AL_NO_ERROR) | |
6697 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6698 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 6699 free(ALmixer_Channel_List); |
6700 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6701 LinkedList_Free(s_listOfALmixerData); |
0 | 6702 alcDestroyContext(context); |
6703 alcCloseDevice(dev); | |
6704 ALmixer_Initialized = 0; | |
6705 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6706 return AL_FALSE; |
0 | 6707 } |
6708 | |
6709 /* Initialize each channel and associate one source to one channel */ | |
6710 for(i=0; i<Number_of_Channels_global; i++) | |
6711 { | |
6712 if(0 == source[i]) | |
6713 { | |
6714 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"); | |
6715 } | |
6716 | |
6717 Init_Channel(i); | |
6718 /* Keeping the source allocation out of the Init function | |
6719 * in case I want to reuse the Init | |
6720 * function for resetting data | |
6721 */ | |
6722 ALmixer_Channel_List[i].alsource = source[i]; | |
6723 /* Now also keep a copy of the source to channel mapping | |
6724 * in case we need to look up a channel from the source | |
6725 * instead of a source from a channel | |
6726 */ | |
6727 Source_Map_List[i].source = source[i]; | |
6728 Source_Map_List[i].channel = i; | |
6729 /* Clean the channel because there are some things that need to | |
6730 * be done that can't happen until the source is set | |
6731 */ | |
6732 Clean_Channel(i); | |
6733 } | |
6734 | |
6735 /* The Source_Map_List must be sorted by source for binary searches | |
6736 */ | |
6737 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
6738 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6739 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6740 ALmixer_OutputDecoders(); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6741 */ |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6742 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6743 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6744 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6745 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6746 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6747 if(NULL == s_simpleLock) |
0 | 6748 { |
6749 /* SDL sets the error message already? */ | |
6750 free(source); | |
6751 free(ALmixer_Channel_List); | |
6752 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6753 LinkedList_Free(s_listOfALmixerData); |
0 | 6754 alcDestroyContext(context); |
6755 alcCloseDevice(dev); | |
6756 ALmixer_Initialized = 0; | |
6757 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6758 return AL_FALSE; |
0 | 6759 } |
6760 | |
6761 | |
6762 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
6763 if(NULL == Stream_Thread_global) | |
6764 { | |
6765 /* 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
|
6766 SDL_DestroyMutex(s_simpleLock); |
0 | 6767 free(source); |
6768 free(ALmixer_Channel_List); | |
6769 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6770 LinkedList_Free(s_listOfALmixerData); |
0 | 6771 alcDestroyContext(context); |
6772 alcCloseDevice(dev); | |
6773 ALmixer_Initialized = 0; | |
6774 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6775 return AL_FALSE; |
0 | 6776 } |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
6777 |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
6778 /* Note: Only a few platforms change the priority. See implementation for notes. */ |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
6779 Internal_LowerThreadPriority(Stream_Thread_global); |
0 | 6780 |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6781 /* |
0 | 6782 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6783 */ |
0 | 6784 #endif /* End of ENABLE_ALMIXER_THREADS */ |
6785 | |
6786 /* We don't need this array any more because all the sources | |
6787 * are connected to channels | |
6788 */ | |
6789 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6790 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6791 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6792 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6793 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6794 ALboolean ALmixer_InitContext(ALuint frequency, ALuint refresh) |
0 | 6795 { |
6796 ALCdevice* dev; | |
6797 ALCcontext* context; | |
6798 ALCenum error; | |
6799 | |
6800 #ifdef USING_LOKI_AL_DIST | |
6801 /* The Loki dist requires that I set both the | |
6802 * device and context frequency values separately | |
6803 */ | |
6804 /* Hope this won't overflow */ | |
6805 char device_string[256]; | |
6806 #endif | |
6807 | |
6808 /* (Venting frustration) Damn it! Nobody bothered | |
6809 * documenting how you're supposed to use an attribute | |
6810 * list. In fact, the not even the Loki test program | |
6811 * writers seem to know because they use it inconsistently. | |
6812 * For example, how do you terminate that attribute list? | |
6813 * The Loki test code does it 3 different ways. They | |
6814 * set the last value to 0, or they set it to ALC_INVALID, | |
6815 * or they set two final values: ALC_INVALID, 0 | |
6816 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6817 * but with Creative Labs ALC_INVALID is -1. | |
6818 * So something's going to break. Loki's source | |
6819 * code says to terminate with ALC_INVALID. But I | |
6820 * don't know if that's really true, or it happens | |
6821 * to be a coinicidence because it's defined to 0. | |
6822 * Creative provides no source code, so I can't look at how | |
6823 * they terminate it. | |
6824 * So this is really, really ticking me off... | |
6825 * For now, I'm going to use ALC_INVALID. | |
6826 * (Update...after further review of the API spec, | |
6827 * it seems that a NULL terminated string is the correct | |
6828 * termination value to use, so 0 it is.) | |
6829 */ | |
6830 #if 0 | |
6831 ALint attrlist[] = { | |
6832 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6833 /* Don't know anything about these values. | |
6834 * Trust defaults? */ | |
6835 /* Supposed to be the refresh rate in Hz. | |
6836 * I think 15-120 are supposed to be good | |
6837 * values. Though I haven't gotten any effect except | |
6838 * for one strange instance on a Mac. But it was | |
6839 * unrepeatable. | |
6840 */ | |
6841 #if 0 | |
6842 ALC_REFRESH, 15, | |
6843 #endif | |
6844 /* Sync requires a alcProcessContext() call | |
6845 * for every cycle. By default, this is | |
6846 * not used and the value is AL_FALSE | |
6847 * because it will probably perform | |
6848 * pretty badly for me. | |
6849 */ | |
6850 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6851 ALC_SYNC, AL_TRUE, | |
6852 #else | |
6853 ALC_SYNC, AL_FALSE, | |
6854 #endif | |
6855 /* Looking at the API spec, it implies | |
6856 * that the list be a NULL terminated string | |
6857 * so it's probably not safe to use ALC_INVALID | |
6858 */ | |
6859 /* | |
6860 ALC_INVALID }; | |
6861 */ | |
6862 '\0'}; | |
6863 #endif | |
6864 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6865 * However, if no value is specified, I don't | |
6866 * want it in the list so I can get the OpenAL defaults | |
6867 */ | |
6868 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6869 ALsizei current_attrlist_index = 0; |
0 | 6870 |
6871 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6872 /* More problems: I'm getting bit by endian/signedness issues on | |
6873 * different platforms. I can find the endianess easily enough, | |
6874 * but I don't know how to determine what the correct signedness | |
6875 * is (if such a thing exists). I do know that if I try using | |
6876 * unsigned on OSX with an originally signed sample, I get | |
6877 * distortion. However, I don't have any native unsigned samples | |
6878 * to test. But I'm assuming that the platform must be in the | |
6879 * correct signedness no matter what. | |
6880 * I can either assume everybody is signed, or I can try to | |
6881 * determine the value. If I try to determine the values, | |
6882 * I think my only ability to figure it out will be to open | |
6883 * SDL_Audio, and read what the obtained settings were. | |
6884 * Then shutdown everything. However, I don't even know how | |
6885 * reliable this is. | |
6886 * Update: I think I resolved the issues...forgot to update | |
6887 * these comments when it happened. I should check the revision control | |
6888 * log... Anyway, I think the issue was partly related to me not | |
6889 * doing something correctly with the AudioInfo or some kind | |
6890 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6891 * revision control, I think I might have assumed that SDL_Sound would | |
6892 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6893 * and had to fill one out myself. | |
6894 */ | |
6895 SDL_AudioSpec desired; | |
6896 SDL_AudioSpec obtained; | |
6897 #endif | |
6898 | |
6899 | |
6900 | |
6901 | |
6902 /* Make sure ALmixer isn't already initialized */ | |
6903 if(ALmixer_Initialized) | |
6904 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6905 return AL_FALSE; |
0 | 6906 } |
6907 | |
6908 /* Set the defaults */ | |
6909 attrlist[0] = ALC_FREQUENCY; | |
6910 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6911 attrlist[2] = ALC_SYNC; | |
6912 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6913 attrlist[3] = ALC_TRUE; | |
6914 #else | |
6915 attrlist[3] = ALC_FALSE; | |
6916 #endif | |
6917 /* Set frequency value if it is not 0 */ | |
6918 if(0 != frequency) | |
6919 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6920 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6921 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6922 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6923 current_attrlist_index++; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6926 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6927 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6928 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6929 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6930 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6931 #endif |
0 | 6932 |
6933 /* If the user specifies a refresh value, | |
6934 * make room for it | |
6935 */ | |
6936 if(0 != refresh) | |
6937 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6938 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
|
6939 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6940 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6941 current_attrlist_index++; |
0 | 6942 } |
6943 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6944 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6945 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6946 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6947 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6948 |
0 | 6949 /* Initialize SDL_Sound */ |
6950 if(! Sound_Init() ) | |
6951 { | |
6952 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6953 return AL_FALSE; |
0 | 6954 } |
6955 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6956 /* Here is the paranoid check that opens | |
6957 * SDL audio in an attempt to find the correct | |
6958 * system values. | |
6959 */ | |
6960 /* Doesn't have to be the actual value I think | |
6961 * (as long as it doesn't influence format, in | |
6962 * which case I'm probably screwed anyway because OpenAL | |
6963 * may easily choose to do something else). | |
6964 */ | |
6965 desired.freq = 44100; | |
6966 desired.channels = 2; | |
6967 desired.format = AUDIO_S16SYS; | |
6968 desired.callback = my_dummy_audio_callback; | |
6969 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6970 { | |
6971 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6972 /* Now to get really paranoid, we should probably | |
6973 * also assume that the 8bit format is also the | |
6974 * same sign type and set that value | |
6975 */ | |
6976 if(AUDIO_S16SYS == obtained.format) | |
6977 { | |
6978 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6979 } | |
6980 /* Should be AUDIO_U16SYS */ | |
6981 else | |
6982 { | |
6983 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6984 } | |
6985 SDL_CloseAudio(); | |
6986 } | |
6987 else | |
6988 { | |
6989 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6990 */ | |
6991 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6992 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6993 } | |
6994 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6995 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6996 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6997 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
6998 * causes OpenAL and SMPEG to conflict. For some reason | |
6999 * if SDL_Init on audio is active, then all the SMPEG | |
7000 * decoded sound comes out silent. Unfortunately, | |
7001 * Sound_Init() invokes SDL_Init on audio. I'm | |
7002 * not sure why it actually needs it... | |
7003 * But we'll attempt to disable it here after the | |
7004 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
7005 */ | |
7006 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7007 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7008 |
0 | 7009 /* I'm told NULL will call the default string |
7010 * and hopefully do the right thing for each platform | |
7011 */ | |
7012 /* | |
7013 dev = alcOpenDevice( NULL ); | |
7014 */ | |
7015 /* Now I'm told I need to set both the device and context | |
7016 * to have the same sampling rate, so I must pass a string | |
7017 * to OpenDevice(). I don't know how portable these strings are. | |
7018 * I don't even know if the format for strings is | |
7019 * compatible | |
7020 * From the testattrib.c in the Loki test section | |
7021 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
7022 */ | |
7023 | |
7024 #ifdef USING_LOKI_AL_DIST | |
7025 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
7026 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
7027 #else | |
7028 dev = alcOpenDevice( NULL ); | |
7029 #endif | |
7030 if(NULL == dev) | |
7031 { | |
7032 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
|
7033 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7034 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7035 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7036 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7037 /* 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
|
7038 /* 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
|
7039 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7040 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7041 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7042 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7043 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
|
7044 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7045 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
|
7046 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7047 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7048 |
0 | 7049 |
7050 context = alcCreateContext(dev, attrlist); | |
7051 if(NULL == context) | |
7052 { | |
7053 ALmixer_SetError("Cannot create a context OpenAL"); | |
7054 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7055 return AL_FALSE; |
0 | 7056 } |
7057 | |
7058 | |
7059 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
7060 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
7061 * According to Garin Hiebert, this is actually an inconsistency | |
7062 * in the Loki version. The function should return a boolean. | |
7063 * instead of ALC_NO_ERROR. Garin suggested I check via | |
7064 * alcGetError(). | |
7065 */ | |
7066 /* clear the error */ | |
7067 alcGetError(dev); | |
7068 alcMakeContextCurrent(context); | |
7069 | |
7070 error = alcGetError(dev); | |
7071 if( (ALC_NO_ERROR != error) ) | |
7072 { | |
7073 ALmixer_SetError("Could not MakeContextCurrent"); | |
7074 alcDestroyContext(context); | |
7075 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7076 return AL_FALSE; |
0 | 7077 } |
7078 | |
7079 | |
7080 #if 0 | |
7081 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
7082 if(alcGetCurrentContext() != context) | |
7083 { | |
7084 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
7085 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
7086 * I think this is a bug in the OpenAL implementation. | |
7087 */ | |
7088 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
7089 | |
7090 fprintf(stderr, "Making context current\n"); | |
7091 #ifndef __APPLE__ | |
7092 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
7093 #else | |
7094 if(!alcMakeContextCurrent(context)) | |
7095 #endif | |
7096 { | |
7097 ALmixer_SetError("Could not MakeContextCurrent"); | |
7098 alcDestroyContext(context); | |
7099 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7100 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7101 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7102 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7103 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7104 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7105 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7106 /* 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
|
7107 * 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
|
7108 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7109 * 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
|
7110 * 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
|
7111 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7112 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7113 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7114 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
|
7115 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7116 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
|
7117 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7118 #endif |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7119 |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7120 |
0 | 7121 |
7122 /* Saw this in the README with the OS X OpenAL distribution. | |
7123 * It looked interesting and simple, so I thought I might | |
7124 * try it out. | |
7125 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
7126 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
7127 * Audio format, the audio data passed to the | |
7128 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
7129 * usage by removing an audio data conversion | |
7130 * (per source) at render timem at the expense of a larger memory footprint. | |
7131 * | |
7132 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
7133 * setting will be applied to all subsequent | |
7134 * calls to alBufferData(). | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7135 * Update: Some people keep reporting that they see the enable fail on Mac, but I can't reproduce it myself. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7136 * Rather than deal with it right now, I think I am going to make it an opt-in thing. |
0 | 7137 */ |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7138 #if defined(__APPLE__) && defined(ALMIXER_USE_OSX_CONVERT_DATA_UPON_LOADING) |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7139 /* |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7140 iPhone is getting this enum, but is failing on the enable, so I guess I'll define it out. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7141 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7142 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7143 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7144 #else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7145 /* iOS reports this enum exists, but loading it always fails, so make it Mac only. */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7146 ALenum convert_data_enum = alcGetEnumValue(dev, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING"); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7147 /* |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7148 fprintf(stderr, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING=0x%x", convert_data_enum); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7149 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7150 if(0 != convert_data_enum) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7151 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7152 alEnable(convert_data_enum); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7153 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7154 if( (AL_NO_ERROR != alGetError()) ) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7155 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7156 fprintf(stderr, "ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING attempted but failed"); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7157 ALmixer_SetError("ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING attempted but failed"); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7158 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7159 #endif |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7160 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7161 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7162 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7163 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7164 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7165 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7166 ALboolean ALmixer_InitMixer(ALuint num_sources) |
0 | 7167 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7168 ALint i; |
0 | 7169 ALenum error; |
7170 ALuint* source; | |
7171 | |
7172 | |
7173 ALmixer_Initialized = 1; | |
7174 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7175 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7176 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7177 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7178 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7179 /* 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
|
7180 /* 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
|
7181 * 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
|
7182 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7183 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7184 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7185 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7186 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7187 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7188 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7189 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7190 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7191 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7192 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7193 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7194 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7195 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
|
7196 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
|
7197 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7198 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7199 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7200 if(num_sources == 0) |
0 | 7201 { |
7202 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
7203 } | |
7204 else | |
7205 { | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7206 Number_of_Channels_global = (ALint)num_sources; |
0 | 7207 } |
7208 Number_of_Reserve_Channels_global = 0; | |
7209 Is_Playing_global = 0; | |
7210 /* Set to Null in case system quit and was reinitialized */ | |
7211 Channel_Done_Callback = NULL; | |
7212 Channel_Done_Callback_Userdata = NULL; | |
7213 Channel_Data_Callback = NULL; | |
1 | 7214 Channel_Data_Callback_Userdata = NULL; |
0 | 7215 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7216 /* Allocate memory for linked list of ALmixerData. */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7217 s_listOfALmixerData = LinkedList_Create(); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7218 if(NULL == s_listOfALmixerData) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7219 { |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7220 ALmixer_SetError("Couldn't create linked list"); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7221 ALmixer_Initialized = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7222 Number_of_Channels_global = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7223 return AL_FALSE; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7224 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7225 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7226 |
0 | 7227 /* Allocate memory for the list of channels */ |
7228 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
7229 if(NULL == ALmixer_Channel_List) | |
7230 { | |
7231 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
|
7232 LinkedList_Free(s_listOfALmixerData); |
0 | 7233 ALmixer_Initialized = 0; |
7234 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7235 return AL_FALSE; |
0 | 7236 } |
7237 | |
7238 /* Allocate memory for the list of sources that map to the channels */ | |
7239 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
7240 if(NULL == Source_Map_List) | |
7241 { | |
7242 ALmixer_SetError("Out of Memory for Source Map List"); | |
7243 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7244 LinkedList_Free(s_listOfALmixerData); |
0 | 7245 ALmixer_Initialized = 0; |
7246 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7247 return AL_FALSE; |
0 | 7248 } |
7249 | |
7250 /* Create array that will hold the sources */ | |
7251 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
7252 if(NULL == source) | |
7253 { | |
7254 ALmixer_SetError("Out of Memory for sources"); | |
7255 free(Source_Map_List); | |
7256 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7257 LinkedList_Free(s_listOfALmixerData); |
0 | 7258 ALmixer_Initialized = 0; |
7259 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7260 return AL_FALSE; |
0 | 7261 } |
7262 | |
7263 /* Clear the error state */ | |
7264 alGetError(); | |
7265 /* Generate the OpenAL sources */ | |
7266 alGenSources(Number_of_Channels_global, source); | |
7267 if( (error=alGetError()) != AL_NO_ERROR) | |
7268 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7269 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 7270 free(ALmixer_Channel_List); |
7271 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7272 LinkedList_Free(s_listOfALmixerData); |
0 | 7273 ALmixer_Initialized = 0; |
7274 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7275 return AL_FALSE; |
0 | 7276 } |
7277 | |
7278 /* Initialize each channel and associate one source to one channel */ | |
7279 for(i=0; i<Number_of_Channels_global; i++) | |
7280 { | |
7281 Init_Channel(i); | |
7282 /* Keeping the source allocation out of the Init function | |
7283 * in case I want to reuse the Init | |
7284 * function for resetting data | |
7285 */ | |
7286 ALmixer_Channel_List[i].alsource = source[i]; | |
7287 /* Now also keep a copy of the source to channel mapping | |
7288 * in case we need to look up a channel from the source | |
7289 * instead of a source from a channel | |
7290 */ | |
7291 Source_Map_List[i].source = source[i]; | |
7292 Source_Map_List[i].channel = i; | |
7293 /* Clean the channel because there are some things that need to | |
7294 * be done that can't happen until the source is set | |
7295 */ | |
7296 Clean_Channel(i); | |
7297 } | |
7298 | |
7299 /* The Source_Map_List must be sorted by source for binary searches | |
7300 */ | |
7301 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
7302 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7303 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7304 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7305 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7306 if(NULL == s_simpleLock) |
0 | 7307 { |
7308 /* SDL sets the error message already? */ | |
7309 free(source); | |
7310 free(ALmixer_Channel_List); | |
7311 free(Source_Map_List); | |
7312 ALmixer_Initialized = 0; | |
7313 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7314 return AL_FALSE; |
0 | 7315 } |
7316 | |
7317 | |
7318 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
7319 if(NULL == Stream_Thread_global) | |
7320 { | |
7321 /* 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
|
7322 SDL_DestroyMutex(s_simpleLock); |
0 | 7323 free(source); |
7324 free(ALmixer_Channel_List); | |
7325 free(Source_Map_List); | |
7326 ALmixer_Initialized = 0; | |
7327 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7328 return AL_FALSE; |
0 | 7329 } |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
7330 |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
7331 /* Note: Only a few platforms change the priority. See implementation for notes. */ |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
7332 Internal_LowerThreadPriority(Stream_Thread_global); |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
7333 |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7334 /* |
0 | 7335 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7336 */ |
0 | 7337 #endif /* End of ENABLE_ALMIXER_THREADS */ |
7338 | |
7339 /* We don't need this array any more because all the sources | |
7340 * are connected to channels | |
7341 */ | |
7342 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7343 return AL_TRUE; |
0 | 7344 } |
7345 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7346 void ALmixer_BeginInterruption() |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7347 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7348 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7349 SDL_LockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7350 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7351 s_interruptionContext = alcGetCurrentContext(); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7352 if(NULL != s_interruptionContext) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7353 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7354 /* iOS alcSuspendContext is a no-op */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7355 alcSuspendContext(s_interruptionContext); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7356 alcMakeContextCurrent(NULL); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7357 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7358 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7359 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7360 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7361 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7362 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7363 void ALmixer_EndInterruption() |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7364 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7365 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7366 SDL_LockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7367 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7368 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7369 /* Note: iOS, you need to set the AudioSession active. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7370 * But if the AudioSession is not initialized, this SetActive |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7371 * call fails. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7372 * So this is probably better if calling app sets this. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7373 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7374 /* |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7375 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7376 OSStatus the_error = AudioSessionSetActive(true); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7377 if(noErr != the_error) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7378 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7379 fprintf(stderr, "Error setting audio session active! %d\n", the_error); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7380 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7381 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7382 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7383 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7384 if(NULL != s_interruptionContext) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7385 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7386 alcMakeContextCurrent(s_interruptionContext); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7387 alcProcessContext(s_interruptionContext); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7388 s_interruptionContext = NULL; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7389 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7390 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7391 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7392 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7393 } |
0 | 7394 |
7395 /* Keep the return value void to allow easy use with | |
7396 * atexit() | |
7397 */ | |
7398 void ALmixer_Quit() | |
7399 { | |
7400 ALCcontext* context; | |
7401 ALCdevice* dev; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7402 ALint i; |
0 | 7403 |
7404 if( ! ALmixer_Initialized) | |
7405 { | |
7406 return; | |
7407 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7408 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7409 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7410 #endif |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7411 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7412 /* Several things we need to do: |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7413 First, we need to check if we are in an interruption. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7414 If so, we need to reactivate the alcContext so we can call OpenAL functions. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7415 Next, we should delete the OpenAL sources. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7416 Next, we need to free all the sound data via ALmixer_FreeData(). |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7417 Finally, we can delete the OpenAL context. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7418 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7419 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7420 context = alcGetCurrentContext(); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7421 if(NULL == context) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7422 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7423 /* We might have an interruption event where the current context is NULL */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7424 if(NULL == s_interruptionContext) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7425 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7426 /* Nothing left to try. I think we're done. */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7427 fprintf(stderr, "ALmixer_Quit: Assertion Error. Expecting to find an OpenAL context, but could not find one.\n"); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7428 return; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7429 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7430 else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7431 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7432 context = s_interruptionContext; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7433 /* reactivate the context so we can call OpenAL functions */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7434 alcMakeContextCurrent(context); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7435 s_interruptionContext = NULL; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7436 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7437 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7438 |
0 | 7439 /* Shutdown everything before closing context */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7440 Internal_HaltChannel(-1, AL_FALSE); |
0 | 7441 |
7442 /* This flag will cause the thread to terminate */ | |
7443 ALmixer_Initialized = 0; | |
7444 #ifdef ENABLE_ALMIXER_THREADS | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7445 SDL_UnlockMutex(s_simpleLock); |
0 | 7446 SDL_WaitThread(Stream_Thread_global, NULL); |
7447 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7448 SDL_DestroyMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7449 #endif |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7450 |
0 | 7451 /* Delete all the OpenAL sources */ |
7452 for(i=0; i<Number_of_Channels_global; i++) | |
7453 { | |
7454 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
7455 } | |
7456 /* Delete all the channels */ | |
7457 free(ALmixer_Channel_List); | |
7458 free(Source_Map_List); | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7459 |
0 | 7460 /* Reset the Number_of_Channels just in case somebody |
7461 * tries using a ALmixer function. | |
7462 * I probably should put "Initialized" checks everywhere, | |
7463 * but I'm too lazy at the moment. | |
7464 */ | |
7465 Number_of_Channels_global = 0; | |
7466 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7467 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7468 /* 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
|
7469 * 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
|
7470 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7471 while(LinkedList_Size(s_listOfALmixerData) > 0) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7472 { |
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
|
7473 /* 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
|
7474 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
|
7475 ALmixer_FreeData(almixer_data); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7476 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7477 LinkedList_Free(s_listOfALmixerData); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7478 s_listOfALmixerData = NULL; |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7479 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7480 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7481 /* Need to get the device before I close the context */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7482 dev = alcGetContextsDevice(context); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7483 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7484 alcMakeContextCurrent(NULL); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7485 alcDestroyContext(context); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7486 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7487 if(NULL == dev) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7488 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7489 return; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7490 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7491 alcCloseDevice(dev); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7492 |
0 | 7493 Sound_Quit(); |
7494 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7495 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7496 /* 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
|
7497 TError_FreeErrorPool(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7498 s_ALmixerErrorPool = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7499 #endif |
0 | 7500 return; |
7501 } | |
7502 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7503 ALboolean ALmixer_IsInitialized() |
0 | 7504 { |
7505 return ALmixer_Initialized; | |
7506 } | |
7507 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7508 ALuint ALmixer_GetFrequency() |
0 | 7509 { |
7510 return ALmixer_Frequency_global; | |
7511 } | |
7512 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7513 const ALmixer_version* ALmixer_GetLinkedVersion() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7514 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7515 static ALmixer_version linked_mixver; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7516 ALMIXER_GET_COMPILED_VERSION(&linked_mixver); |
0 | 7517 return(&linked_mixver); |
7518 } | |
7519 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7520 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7521 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7522 const char* ALmixer_GetError() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7523 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7524 const char* error_string = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7525 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7526 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7527 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
|
7528 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7529 error_string = TError_GetLastErrorStr(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7530 /* 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
|
7531 if(NULL == error_string) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7532 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7533 return ""; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7534 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7535 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7536 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7537 return error_string; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7538 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7539 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7540 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7541 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
|
7542 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7543 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7544 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7545 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
|
7546 return; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7547 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7548 va_list argp; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7549 va_start(argp, err_str); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7550 // 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
|
7551 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
|
7552 va_end(argp); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7553 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7554 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7555 #endif |
0 | 7556 |
7557 | |
7558 | |
7559 | |
7560 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7561 void ALmixer_OutputAttributes() |
0 | 7562 { |
7563 ALint num_flags = 0; | |
7564 ALint* flags = 0; | |
7565 int i; | |
7566 ALCdevice* dev = alcGetContextsDevice( alcGetCurrentContext() ); | |
7567 | |
7568 | |
7569 printf("custom context\n"); | |
7570 | |
7571 alcGetIntegerv(dev, ALC_ATTRIBUTES_SIZE, | |
7572 sizeof num_flags, &num_flags ); | |
7573 | |
7574 printf("Number of Flags: %d\n", num_flags); | |
7575 | |
7576 if(num_flags) | |
7577 { | |
7578 flags = malloc(sizeof(num_flags) * sizeof(ALint)); | |
7579 | |
7580 alcGetIntegerv(dev, ALC_ALL_ATTRIBUTES, | |
7581 sizeof num_flags * sizeof(ALint), | |
7582 flags ); | |
7583 } | |
7584 for(i = 0; i < num_flags-1; i += 2) | |
7585 { | |
7586 printf("key 0x%x : value %d\n", | |
7587 flags[i], flags[i+1]); | |
7588 } | |
7589 free(flags); | |
7590 } | |
7591 #endif | |
7592 | |
7593 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7594 void ALmixer_OutputDecoders() |
0 | 7595 { |
7596 Sound_Version sound_compile_version; | |
7597 Sound_Version sound_link_version; | |
7598 | |
7599 const Sound_DecoderInfo **rc = Sound_AvailableDecoders(); | |
7600 const Sound_DecoderInfo **i; | |
7601 const char **ext; | |
7602 FILE* stream = stdout; | |
7603 | |
7604 | |
7605 fprintf(stream, "SDL_sound Information:\n"); | |
7606 | |
7607 SOUND_VERSION(&sound_compile_version); | |
7608 fprintf(stream, "\tCompiled with SDL_sound version: %d.%d.%d\n", | |
7609 sound_compile_version.major, | |
7610 sound_compile_version.minor, | |
7611 sound_compile_version.patch); | |
7612 | |
7613 Sound_GetLinkedVersion(&sound_link_version); | |
7614 fprintf(stream, "\tRunning (linked) with SDL_sound version: %d.%d.%d\n", | |
7615 sound_link_version.major, | |
7616 sound_link_version.minor, | |
7617 sound_link_version.patch); | |
7618 | |
7619 fprintf(stream, "Supported sound formats:\n"); | |
7620 if (rc == NULL) | |
7621 fprintf(stream, " * Apparently, NONE!\n"); | |
7622 else | |
7623 { | |
7624 for (i = rc; *i != NULL; i++) | |
7625 { | |
7626 fprintf(stream, " * %s\n", (*i)->description); | |
7627 | |
7628 for (ext = (*i)->extensions; *ext != NULL; ext++) | |
7629 fprintf(stream, " File extension \"%s\"\n", *ext); | |
7630 | |
7631 fprintf(stream, " Written by %s.\n %s\n\n", | |
7632 (*i)->author, (*i)->url); | |
7633 } /* for */ | |
7634 } /* else */ | |
7635 | |
7636 fprintf(stream, "\n"); | |
7637 } | |
7638 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7639 void ALmixer_OutputOpenALInfo() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7640 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7641 ALmixer_version mixer_compile_version; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7642 const ALmixer_version * mixer_link_version=ALmixer_GetLinkedVersion(); |
0 | 7643 FILE* stream = stdout; |
7644 | |
7645 fprintf(stream, "OpenAL Information:\n"); | |
7646 fprintf(stream, "\tAL_VENDOR: %s\n", alGetString( AL_VENDOR ) ); | |
7647 fprintf(stream, "\tAL_VERSION: %s\n", alGetString( AL_VERSION ) ); | |
7648 fprintf(stream, "\tAL_RENDERER: %s\n", alGetString( AL_RENDERER ) ); | |
7649 fprintf(stream, "\tAL_EXTENSIONS: %s\n", alGetString( AL_EXTENSIONS ) ); | |
7650 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7651 ALMIXER_GET_COMPILED_VERSION(&mixer_compile_version); |
0 | 7652 fprintf(stream, "\nSDL_ALmixer Information:\n"); |
7653 fprintf(stream, "\tCompiled with SDL_ALmixer version: %d.%d.%d\n", | |
7654 mixer_compile_version.major, | |
7655 mixer_compile_version.minor, | |
7656 mixer_compile_version.patch); | |
7657 | |
7658 fprintf(stream, "\tRunning (linked) with SDL_ALmixer version: %d.%d.%d\n", | |
7659 mixer_link_version->major, | |
7660 mixer_link_version->minor, | |
7661 mixer_link_version->patch); | |
7662 | |
7663 fprintf(stream, "\tCompile flags: "); | |
7664 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
7665 fprintf(stream, "ENABLE_LOKI_QUEUE_FIX_HACK "); | |
7666 #endif | |
7667 #ifdef ENABLE_ALMIXER_THREADS | |
7668 fprintf(stream, "ENABLE_ALMIXER_THREADS "); | |
7669 #endif | |
7670 #ifdef ENABLE_ALC_SYNC | |
7671 fprintf(stream, "ENABLE_ALC_SYNC "); | |
7672 #endif | |
7673 fprintf(stream, "\n"); | |
7674 } | |
7675 | |
7676 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7677 ALint ALmixer_AllocateChannels(ALint numchans) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7678 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7679 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7680 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7681 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7682 #endif |
0 | 7683 retval = Internal_AllocateChannels(numchans); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7684 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7685 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7686 #endif |
0 | 7687 return retval; |
7688 } | |
7689 | |
7690 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7691 ALint ALmixer_ReserveChannels(ALint num) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7692 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7693 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7694 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7695 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7696 #endif |
0 | 7697 retval = Internal_ReserveChannels(num); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7698 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7699 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7700 #endif |
0 | 7701 return retval; |
7702 } | |
7703 | |
7704 | |
7705 | |
7706 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7707 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
|
7708 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7709 ALuint bytes_decoded; |
0 | 7710 ALmixer_Data* ret_data; |
7711 ALenum error; | |
7712 | |
7713 /* Allocate memory */ | |
7714 ret_data = (ALmixer_Data *)malloc(sizeof(ALmixer_Data)); | |
7715 if (NULL == ret_data) | |
7716 { | |
7717 ALmixer_SetError("Out of memory"); | |
7718 return(NULL); | |
7719 } | |
7720 | |
7721 /* Initialize the data fields */ | |
7722 | |
7723 /* Set the Sound_Sample pointer */ | |
7724 ret_data->sample = sample; | |
7725 | |
7726 /* Flag the data to note that it is not in use */ | |
7727 ret_data->in_use = 0; | |
7728 | |
7729 /* Initialize remaining flags */ | |
7730 ret_data->total_time = -1; | |
7731 ret_data->eof = 0; | |
7732 | |
7733 /* Just initialize */ | |
7734 ret_data->num_buffers_in_use = 0; | |
7735 | |
7736 /* Just initialize */ | |
7737 ret_data->total_bytes = 0; | |
7738 | |
7739 /* Just initialize */ | |
7740 ret_data->loaded_bytes = 0; | |
7741 | |
7742 /* Set the max queue buffers (minimum must be 2) */ | |
7743 if(max_queue_buffers < 2) | |
7744 { | |
7745 max_queue_buffers = ALMIXER_DEFAULT_QUEUE_BUFFERS; | |
7746 } | |
7747 ret_data->max_queue_buffers = max_queue_buffers; | |
7748 /* Set up the start up buffers */ | |
7749 if(0 == num_startup_buffers) | |
7750 { | |
7751 num_startup_buffers = ALMIXER_DEFAULT_STARTUP_BUFFERS; | |
7752 } | |
7753 /* Make sure start up buffers is less or equal to max_queue_buffers */ | |
7754 if(num_startup_buffers > max_queue_buffers) | |
7755 { | |
7756 num_startup_buffers = max_queue_buffers; | |
7757 } | |
7758 ret_data->num_startup_buffers = num_startup_buffers; | |
7759 | |
7760 ret_data->buffer_map_list = NULL; | |
7761 ret_data->current_buffer = 0; | |
7762 | |
7763 ret_data->circular_buffer_queue = NULL; | |
7764 | |
7765 /* Now decode and load the data into a data chunk */ | |
7766 /* Different cases for Streamed and Predecoded | |
7767 * Streamed might turn into a predecoded if buffersize | |
7768 * is large enough */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7769 if(AL_FALSE == decode_mode_is_predecoded) |
0 | 7770 { |
7771 bytes_decoded = Sound_Decode(sample); | |
7772 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7773 { | |
7774 ALmixer_SetError(Sound_GetError()); | |
7775 Sound_FreeSample(sample); | |
7776 free(ret_data); | |
7777 return NULL; | |
7778 } | |
7779 | |
7780 /* If no data, return an error */ | |
7781 if(0 == bytes_decoded) | |
7782 { | |
7783 ALmixer_SetError("File has no data"); | |
7784 Sound_FreeSample(sample); | |
7785 free(ret_data); | |
7786 return NULL; | |
7787 } | |
7788 | |
7789 /* Note, currently, my Ogg conservative modifications | |
7790 * prevent EOF from being detected in the first read | |
7791 * because of the weird packet behavior of ov_read(). | |
7792 * The EAGAIN will get set, but not the EOF. | |
7793 * I don't know the best way to handle this, | |
7794 * so for now, Ogg's can only be explicitly | |
7795 * predecoded. | |
7796 */ | |
7797 | |
7798 /* Correction: Since we no longer actually keep the | |
7799 * streamed data we read here (we rewind and throw | |
7800 * it away, and start over on Play), it is | |
7801 * safe to read another chunk to see if we've hit EOF | |
7802 */ | |
7803 if(sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
7804 { | |
7805 bytes_decoded = Sound_Decode(sample); | |
7806 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7807 { | |
7808 ALmixer_SetError(Sound_GetError()); | |
7809 Sound_FreeSample(sample); | |
7810 free(ret_data); | |
7811 return NULL; | |
7812 } | |
7813 } | |
7814 | |
7815 | |
7816 /* If we found an EOF, the entire file was | |
7817 * decoded, so we can treat it like one. | |
7818 */ | |
7819 | |
7820 if(sample->flags & SOUND_SAMPLEFLAG_EOF) | |
7821 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7822 /* |
0 | 7823 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
|
7824 */ |
0 | 7825 ret_data->decoded_all = 1; |
7826 /* Need to keep this information around for | |
7827 * seek and rewind abilities. | |
7828 */ | |
7829 ret_data->total_bytes = bytes_decoded; | |
7830 /* For now, the loaded bytes is the same as total bytes, but | |
7831 * this could change during a seek operation | |
7832 */ | |
7833 ret_data->loaded_bytes = bytes_decoded; | |
7834 | |
7835 /* Let's compute the total playing time | |
7836 * SDL_sound does not yet provide this (we're working on | |
7837 * that at the moment...) | |
7838 */ | |
7839 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
7840 | |
7841 /* Create one element in the buffer array for data for OpanAL */ | |
7842 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
7843 if(NULL == ret_data->buffer) | |
7844 { | |
7845 ALmixer_SetError("Out of Memory"); | |
7846 Sound_FreeSample(sample); | |
7847 free(ret_data); | |
7848 return NULL; | |
7849 } | |
7850 /* Clear the error code */ | |
7851 alGetError(); | |
7852 /* Now generate an OpenAL buffer using that first element */ | |
7853 alGenBuffers(1, ret_data->buffer); | |
7854 if( (error = alGetError()) != AL_NO_ERROR) | |
7855 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7856 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7857 Sound_FreeSample(sample); |
7858 free(ret_data->buffer); | |
7859 free(ret_data); | |
7860 return NULL; | |
7861 } | |
7862 | |
7863 | |
7864 /* Now copy the data to the OpenAL buffer */ | |
7865 /* We can't just set a pointer because the API needs | |
7866 * its own copy to assist hardware acceleration */ | |
7867 alBufferData(ret_data->buffer[0], | |
7868 TranslateFormat(&sample->desired), | |
7869 sample->buffer, | |
7870 bytes_decoded, | |
7871 sample->desired.rate | |
7872 ); | |
7873 if( (error = alGetError()) != AL_NO_ERROR) | |
7874 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7875 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 7876 Sound_FreeSample(sample); |
7877 alDeleteBuffers(1, ret_data->buffer); | |
7878 free(ret_data->buffer); | |
7879 free(ret_data); | |
7880 return NULL; | |
7881 } | |
7882 | |
7883 /* We should be done with the sample since it's all | |
7884 * predecoded. So we can free the memory */ | |
7885 | |
7886 /* Additional notes: | |
7887 * We need to keep data around in case Seek() is needed | |
7888 * or other Sound_AudioInfo is needed. | |
7889 * This can either be done by not deleting the sample, | |
7890 * or it can be done by dynamically recreating it | |
7891 * when we need it. | |
7892 */ | |
7893 /* Since OpenAL won't let us retrieve it | |
7894 * (aka dynamically), we have to keep the Sample | |
7895 * around because since the user requested | |
7896 * streamed and we offered predecoded, | |
7897 * we don't want to mess up the user who | |
7898 * was expecting seek support | |
7899 * So Don't Do anything | |
7900 */ | |
7901 /* | |
7902 if(0 == access_data) | |
7903 { | |
7904 Sound_FreeSample(sample); | |
7905 ret_data->sample = NULL; | |
7906 } | |
7907 */ | |
7908 /* Else, We keep a copy of the sample around. | |
7909 * so don't do anything. | |
7910 */ | |
7911 | |
7912 #if 0 | |
7913 #if defined(DISABLE_PREDECODED_SEEK) | |
7914 Sound_FreeSample(sample); | |
7915 ret_data->sample = NULL; | |
7916 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
7917 Sound_FreeSample(sample); | |
7918 ret_data->sample = NULL; | |
7919 #else | |
7920 /* We keep a copy of the sample around. | |
7921 * so don't do anything. | |
7922 */ | |
7923 #endif | |
7924 #endif | |
7925 /* okay we're done here */ | |
7926 | |
7927 } | |
7928 /* Else, we need to stream the data, so we'll | |
7929 * create multple buffers for queuing */ | |
7930 else | |
7931 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7932 /* |
0 | 7933 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
|
7934 */ |
0 | 7935 ret_data->decoded_all = 0; |
7936 | |
7937 /* This information is for predecoded. | |
7938 * Set to 0, since we don't know. | |
7939 */ | |
7940 ret_data->total_bytes = 0; | |
7941 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7942 ret_data->total_time = Sound_GetDuration(sample); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7943 |
0 | 7944 /* Create buffers for data |
7945 */ | |
7946 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) * max_queue_buffers); | |
7947 if(NULL == ret_data->buffer) | |
7948 { | |
7949 ALmixer_SetError("Out of Memory"); | |
7950 Sound_FreeSample(sample); | |
7951 free(ret_data); | |
7952 return NULL; | |
7953 } | |
7954 | |
7955 /* Clear the error code */ | |
7956 alGetError(); | |
7957 /* Now generate an OpenAL buffer using that first element */ | |
7958 alGenBuffers(max_queue_buffers, ret_data->buffer); | |
7959 if( (error = alGetError()) != AL_NO_ERROR) | |
7960 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7961 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7962 Sound_FreeSample(sample); |
7963 free(ret_data->buffer); | |
7964 free(ret_data); | |
7965 return NULL; | |
7966 } | |
7967 | |
7968 /* Redesign: Okay, because of the unqueuing problems and such, | |
7969 * I've decided to redesign where and how queuing is handled. | |
7970 * Before, everything was queued up here. However, this | |
7971 * placed a penalty on load and made performance inconsistent | |
7972 * when samples had to be rewound. It did make things easier | |
7973 * to queue because I could let OpenAL decide which buffer | |
7974 * needed to be queued next. | |
7975 * Now, I'm going to push off the queuing to the actual | |
7976 * Play() command. I'm going to add some book keeping, | |
7977 * and allow for additional buffers to be filled at later | |
7978 * times. | |
7979 */ | |
7980 | |
7981 | |
7982 /* So first of all, because of I already decoded the sample | |
7983 * for testing, I need to decide what to do with it. | |
7984 * The best thing would be be to alBufferData() it. | |
7985 * The problem is it may conflict with the rest of | |
7986 * the system because everything now assumes buffers | |
7987 * are entirely stripped (because of the unqueing | |
7988 * problem). | |
7989 * So it looks like I have to do the crappy thing | |
7990 * and throw away the data, and rewind. | |
7991 */ | |
7992 | |
7993 if(0 == Sound_Rewind(ret_data->sample)) | |
7994 { | |
7995 ALmixer_SetError("Cannot use sample for streamed data because it must be rewindable: %s", Sound_GetError() ); | |
7996 Sound_FreeSample(sample); | |
7997 free(ret_data->buffer); | |
7998 free(ret_data); | |
7999 return NULL; | |
8000 } | |
8001 | |
8002 | |
8003 /* If the user has selected access_data, we need to | |
8004 * keep copies of the queuing buffers around because | |
8005 * OpenAL won't let us access the data. | |
8006 * Allocate the memory for the buffers here | |
8007 * and initialize the albuffer-index map | |
8008 */ | |
8009 if(access_data) | |
8010 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8011 ALuint j; |
0 | 8012 /* Create buffers for data access |
8013 * Should be the same number as the number of queue buffers | |
8014 */ | |
1 | 8015 ret_data->buffer_map_list = (ALmixer_Buffer_Map*)malloc( sizeof(ALmixer_Buffer_Map) * max_queue_buffers); |
0 | 8016 if(NULL == ret_data->buffer_map_list) |
8017 { | |
8018 ALmixer_SetError("Out of Memory"); | |
8019 Sound_FreeSample(sample); | |
8020 free(ret_data->buffer); | |
8021 free(ret_data); | |
8022 return NULL; | |
8023 } | |
8024 | |
8025 ret_data->circular_buffer_queue = CircularQueueUnsignedInt_CreateQueue(max_queue_buffers); | |
8026 if(NULL == ret_data->circular_buffer_queue) | |
8027 { | |
8028 ALmixer_SetError("Out of Memory"); | |
8029 free(ret_data->buffer_map_list); | |
8030 Sound_FreeSample(sample); | |
8031 free(ret_data->buffer); | |
8032 free(ret_data); | |
8033 return NULL; | |
8034 } | |
8035 | |
8036 | |
8037 for(j=0; j<max_queue_buffers; j++) | |
8038 { | |
8039 ret_data->buffer_map_list[j].albuffer = ret_data->buffer[j]; | |
8040 ret_data->buffer_map_list[j].index = j; | |
8041 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
|
8042 ret_data->buffer_map_list[j].data = (ALbyte*)malloc( sizeof(ALbyte) * buffersize); |
0 | 8043 if(NULL == ret_data->buffer_map_list[j].data) |
8044 { | |
8045 ALmixer_SetError("Out of Memory"); | |
8046 break; | |
8047 } | |
8048 } | |
8049 /* If an error happened, we have to clean up the memory */ | |
8050 if(j < max_queue_buffers) | |
8051 { | |
8052 fprintf(stderr, "################## Buffer allocation failed\n"); | |
8053 for( ; j>=0; j--) | |
8054 { | |
8055 free(ret_data->buffer_map_list[j].data); | |
8056 } | |
8057 free(ret_data->buffer_map_list); | |
8058 CircularQueueUnsignedInt_FreeQueue(ret_data->circular_buffer_queue); | |
8059 Sound_FreeSample(sample); | |
8060 free(ret_data->buffer); | |
8061 free(ret_data); | |
8062 return NULL; | |
8063 } | |
8064 | |
8065 /* The Buffer_Map_List must be sorted by albuffer for binary searches | |
8066 */ | |
1 | 8067 qsort(ret_data->buffer_map_list, max_queue_buffers, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 8068 } /* End if access_data==true */ |
8069 | |
8070 | |
8071 } /* End of do stream */ | |
8072 } /* end of DECODE_STREAM */ | |
8073 /* 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
|
8074 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
|
8075 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8076 #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
|
8077 /* 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
|
8078 * 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
|
8079 * 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
|
8080 * so looping isn't needed. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8081 * 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
|
8082 * 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
|
8083 * 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
|
8084 * 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
|
8085 * 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
|
8086 * 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
|
8087 * to load a file. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8088 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8089 ALint sound_duration = Sound_GetDuration(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8090 if(sound_duration > 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8091 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8092 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
|
8093 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
|
8094 if(0 == buffer_resize_succeeded) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8095 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8096 ALmixer_SetError(Sound_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8097 Sound_FreeSample(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8098 free(ret_data); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8099 return NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8100 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8101 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8102 #endif /* ALMIXER_DISABLE_PREDECODED_PRECOMPUTE_BUFFER_SIZE_OPTIMIZATION */ |
0 | 8103 bytes_decoded = Sound_DecodeAll(sample); |
8104 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
8105 { | |
8106 ALmixer_SetError(Sound_GetError()); | |
8107 Sound_FreeSample(sample); | |
8108 free(ret_data); | |
8109 return NULL; | |
8110 } | |
8111 | |
8112 /* If no data, return an error */ | |
8113 if(0 == bytes_decoded) | |
8114 { | |
8115 ALmixer_SetError("File has no data"); | |
8116 Sound_FreeSample(sample); | |
8117 free(ret_data); | |
8118 return NULL; | |
8119 } | |
8120 | |
8121 | |
8122 ret_data->decoded_all = 1; | |
8123 /* Need to keep this information around for | |
8124 * seek and rewind abilities. | |
8125 */ | |
8126 ret_data->total_bytes = bytes_decoded; | |
8127 /* For now, the loaded bytes is the same as total bytes, but | |
8128 * this could change during a seek operation | |
8129 */ | |
8130 ret_data->loaded_bytes = bytes_decoded; | |
8131 | |
8132 /* Let's compute the total playing time | |
8133 * SDL_sound does not yet provide this (we're working on | |
8134 * that at the moment...) | |
8135 */ | |
8136 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
8137 | |
8138 /* Create one element in the buffer array for data for OpanAL */ | |
8139 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
8140 if(NULL == ret_data->buffer) | |
8141 { | |
8142 ALmixer_SetError("Out of Memory"); | |
8143 Sound_FreeSample(sample); | |
8144 free(ret_data); | |
8145 return NULL; | |
8146 } | |
8147 /* Clear the error code */ | |
8148 alGetError(); | |
8149 /* Now generate an OpenAL buffer using that first element */ | |
8150 alGenBuffers(1, ret_data->buffer); | |
8151 if( (error = alGetError()) != AL_NO_ERROR) | |
8152 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8153 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 8154 Sound_FreeSample(sample); |
8155 free(ret_data->buffer); | |
8156 free(ret_data); | |
8157 return NULL; | |
8158 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8159 /* |
0 | 8160 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
|
8161 */ |
0 | 8162 /* Now copy the data to the OpenAL buffer */ |
8163 /* We can't just set a pointer because the API needs | |
8164 * its own copy to assist hardware acceleration */ | |
8165 alBufferData(ret_data->buffer[0], | |
8166 TranslateFormat(&sample->desired), | |
8167 sample->buffer, | |
8168 bytes_decoded, | |
8169 sample->desired.rate | |
8170 ); | |
8171 if( (error = alGetError()) != AL_NO_ERROR) | |
8172 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8173 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 8174 Sound_FreeSample(sample); |
8175 alDeleteBuffers(1, ret_data->buffer); | |
8176 free(ret_data->buffer); | |
8177 free(ret_data); | |
8178 return NULL; | |
8179 } | |
8180 | |
8181 /* We should be done with the sample since it's all | |
8182 * predecoded. So we can free the memory */ | |
8183 /* Need to keep around because Seek() needs it */ | |
8184 | |
8185 /* Additional notes: | |
8186 * We need to keep data around in case Seek() is needed | |
8187 * or other Sound_AudioInfo is needed. | |
8188 * This can either be done by not deleting the sample, | |
8189 * or it can be done by dynamically recreating it | |
8190 * when we need it. | |
8191 * Update: I think now it's up to the user by passing the | |
8192 * access_data flag. If they set the flag, then they get | |
8193 * data callbacks and seek support. If not, then they can | |
8194 * get all that stuff at the expense of keeping extra memory | |
8195 * around. | |
8196 */ | |
8197 if(0 == access_data) | |
8198 { | |
8199 Sound_FreeSample(sample); | |
8200 ret_data->sample = NULL; | |
8201 } | |
8202 | |
8203 /* Else, We keep a copy of the sample around. | |
8204 * so don't do anything. | |
8205 */ | |
8206 #if 0 | |
8207 #if defined(DISABLE_PREDECODED_SEEK) | |
8208 Sound_FreeSample(sample); | |
8209 ret_data->sample = NULL; | |
8210 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
8211 Sound_FreeSample(sample); | |
8212 ret_data->sample = NULL; | |
8213 #else | |
8214 /* We keep a copy of the sample around. | |
8215 * so don't do anything. | |
8216 */ | |
8217 #endif | |
8218 #endif | |
8219 | |
8220 /* okay we're done here */ | |
8221 } | |
8222 else | |
8223 { | |
8224 /* Shouldn't get here */ | |
8225 ALmixer_SetError("Unknown decode mode"); | |
8226 Sound_FreeSample(sample); | |
8227 free(ret_data); | |
8228 return NULL; | |
8229 } | |
8230 | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8231 /* 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
|
8232 * 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
|
8233 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8234 LinkedList_PushBack(s_listOfALmixerData, ret_data); |
0 | 8235 return ret_data; |
8236 } | |
8237 | |
8238 | |
8239 /* This will load a sample for us. Most of the uglyness is | |
8240 * error checking and the fact that streamed/predecoded files | |
8241 * must be treated differently. | |
8242 * I don't like the AudioInfo parameter. I removed it once, | |
8243 * but the system will fail on RAW samples because the user | |
8244 * must specify it, so I had to bring it back. | |
8245 * Remember I must close the rwops if there is an error before NewSample() | |
8246 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8247 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 | 8248 { |
8249 Sound_Sample* sample = NULL; | |
8250 Sound_AudioInfo target; | |
8251 | |
8252 /* Initialize target values to defaults | |
8253 * 0 tells SDL_sound to use the "actual" values | |
8254 */ | |
8255 target.channels = 0; | |
8256 target.rate = 0; | |
8257 #if 0 | |
8258 /* This requires my new additions to SDL_sound. It will | |
8259 * convert the sample to the proper endian order. | |
8260 * If the actual is 8-bit, it will do unsigned, if | |
8261 * the actual is 16-bit, it will do signed. | |
8262 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
8263 * in this way. | |
8264 */ | |
8265 target.format = AUDIO_U8S16SYS; | |
8266 #else | |
8267 target.format = AUDIO_S16SYS; | |
8268 #endif | |
8269 | |
8270 /* Set a default buffersize if needed */ | |
8271 if(0 == buffersize) | |
8272 { | |
8273 buffersize = ALMIXER_DEFAULT_BUFFERSIZE; | |
8274 } | |
8275 | |
8276 sample = Sound_NewSample(rwops, fileext, &target, buffersize); | |
8277 if(NULL == sample) | |
8278 { | |
8279 ALmixer_SetError(Sound_GetError()); | |
8280 return NULL; | |
8281 } | |
8282 | |
1 | 8283 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8284 } |
8285 | |
8286 | |
8287 | |
8288 /* This will load a sample for us from | |
8289 * a file (instead of RWops). Most of the uglyness is | |
8290 * error checking and the fact that streamed/predecoded files | |
8291 * must be treated differently. | |
8292 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8293 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 | 8294 { |
8295 Sound_Sample* sample = NULL; | |
8296 Sound_AudioInfo target; | |
8297 | |
8298 /* Initialize target values to defaults | |
8299 * 0 tells SDL_sound to use the "actual" values | |
8300 */ | |
8301 target.channels = 0; | |
8302 target.rate = 0; | |
8303 | |
8304 #if 0 | |
8305 /* This requires my new additions to SDL_sound. It will | |
8306 * convert the sample to the proper endian order. | |
8307 * If the actual is 8-bit, it will do unsigned, if | |
8308 * the actual is 16-bit, it will do signed. | |
8309 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
8310 * in this way. | |
8311 */ | |
8312 target.format = AUDIO_U8S16SYS; | |
8313 #else | |
8314 target.format = AUDIO_S16SYS; | |
8315 #endif | |
8316 | |
8317 #if 0 | |
8318 /* Okay, here's a messy hack. The problem is that we need | |
8319 * to convert the sample to have the correct bitdepth, | |
8320 * endian order, and signedness values. | |
8321 * The bit depth is 8 or 16. | |
8322 * The endian order is the native order of the system. | |
8323 * The signedness depends on what the original value | |
8324 * of the sample. Unfortunately, we can't specify these | |
8325 * values until we after we already know what the original | |
8326 * values were for bitdepth and signedness. | |
8327 * So we must open the file once to get the values, | |
8328 * then close it, and then reopen it with the | |
8329 * correct desired target values. | |
8330 * I tried changing the sample->desired field after | |
8331 * the NewSample call, but it had no effect, so | |
8332 * it looks like it must be set on open. | |
8333 */ | |
8334 /* Pick a small buffersize for the first open to not | |
8335 * waste much time allocating memory */ | |
8336 sample = Sound_NewSampleFromFile(filename, NULL, 512); | |
8337 if(NULL == sample) | |
8338 { | |
8339 ALmixer_SetError(Sound_GetError()); | |
8340 return NULL; | |
8341 } | |
8342 | |
8343 bit_depth = GetBitDepth(sample->actual.format); | |
8344 signedness_value = GetSignednessValue(sample->actual.format); | |
8345 if(8 == bit_depth) | |
8346 { | |
8347 /* If 8 bit, then we don't have to worry about | |
8348 * endian issues. We can just use the actual format | |
8349 * value and it should do the right thing | |
8350 */ | |
8351 target.format = sample->actual.format; | |
8352 } | |
8353 else | |
8354 { | |
8355 /* We'll assume it's 16-bit, and if it's not | |
8356 * hopefully SDL_sound will return an error, | |
8357 * or let us convert to 16-bit | |
8358 */ | |
8359 /* Now we need to get the correct signedness */ | |
8360 if(ALMIXER_UNSIGNED_VALUE == signedness_value) | |
8361 { | |
8362 /* Set to Unsigned 16-bit, system endian order */ | |
8363 target.format = AUDIO_U16SYS; | |
8364 } | |
8365 else | |
8366 { | |
8367 /* Again, we'll assume it's Signed 16-bit system order | |
8368 * or force the conversion and hope it works out | |
8369 */ | |
8370 target.format = AUDIO_S16SYS; | |
8371 } | |
8372 } | |
8373 | |
8374 /* Now we have the correct info. We need to close and reopen */ | |
8375 Sound_FreeSample(sample); | |
8376 #endif | |
8377 | |
8378 sample = Sound_NewSampleFromFile(filename, &target, buffersize); | |
8379 if(NULL == sample) | |
8380 { | |
8381 ALmixer_SetError(Sound_GetError()); | |
8382 return NULL; | |
8383 } | |
8384 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8385 /* |
0 | 8386 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
|
8387 */ |
1 | 8388 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8389 } |
8390 | |
8391 | |
8392 /* This is a back door for RAW samples or if you need the | |
8393 * AudioInfo field. Use at your own risk. | |
8394 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8395 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 | 8396 { |
8397 Sound_Sample* sample = NULL; | |
1 | 8398 Sound_AudioInfo sound_desired; |
8399 /* Rather than copying the data from struct to struct, I could just | |
8400 * cast the thing since the structs are meant to be identical. | |
8401 * But if SDL_sound changes it's implementation, bad things | |
8402 * will probably happen. (Or if I change my implementation and | |
8403 * forget about the cast, same bad scenario.) Since this is a load | |
8404 * function, performance of this is negligible. | |
8405 */ | |
8406 if(NULL == desired) | |
8407 { | |
8408 sample = Sound_NewSample(rwops, fileext, NULL, buffersize); | |
8409 } | |
8410 else | |
8411 { | |
8412 sound_desired.format = desired->format; | |
8413 sound_desired.channels = desired->channels; | |
8414 sound_desired.rate = desired->rate; | |
8415 sample = Sound_NewSample(rwops, fileext, &sound_desired, buffersize); | |
8416 } | |
0 | 8417 if(NULL == sample) |
8418 { | |
8419 ALmixer_SetError(Sound_GetError()); | |
8420 return NULL; | |
8421 } | |
1 | 8422 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8423 } |
8424 | |
8425 | |
8426 | |
8427 | |
8428 /* This is a back door for RAW samples or if you need the | |
8429 * AudioInfo field. Use at your own risk. | |
8430 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8431 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 | 8432 { |
8433 Sound_Sample* sample = NULL; | |
1 | 8434 Sound_AudioInfo sound_desired; |
8435 /* Rather than copying the data from struct to struct, I could just | |
8436 * cast the thing since the structs are meant to be identical. | |
8437 * But if SDL_sound changes it's implementation, bad things | |
8438 * will probably happen. (Or if I change my implementation and | |
8439 * forget about the cast, same bad scenario.) Since this is a load | |
8440 * function, performance of this is negligible. | |
8441 */ | |
8442 if(NULL == desired) | |
8443 { | |
8444 sample = Sound_NewSampleFromFile(filename, NULL, buffersize); | |
8445 } | |
8446 else | |
8447 { | |
8448 sound_desired.format = desired->format; | |
8449 sound_desired.channels = desired->channels; | |
8450 sound_desired.rate = desired->rate; | |
8451 sample = Sound_NewSampleFromFile(filename, &sound_desired, buffersize); | |
8452 } | |
8453 | |
0 | 8454 if(NULL == sample) |
8455 { | |
8456 ALmixer_SetError(Sound_GetError()); | |
8457 return NULL; | |
8458 } | |
1 | 8459 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8460 } |
8461 | |
8462 | |
8463 | |
8464 | |
8465 void ALmixer_FreeData(ALmixer_Data* data) | |
8466 { | |
8467 ALenum error; | |
8468 if(NULL == data) | |
8469 { | |
8470 return; | |
8471 } | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8472 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8473 /* Bypass if in interruption event */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8474 if(NULL == alcGetCurrentContext()) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8475 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8476 fprintf(stderr, "ALmixer_FreeData: Programmer Error. You cannot delete data when the OpenAL content is currently NULL. You may have already called ALmixer_Quit() or are in an interruption event\n"); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8477 return; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8478 } |
0 | 8479 |
8480 if(data->decoded_all) | |
8481 { | |
8482 /* If access_data was enabled, then the Sound_Sample* | |
8483 * still exists. We need to free it | |
8484 */ | |
8485 if(data->sample != NULL) | |
8486 { | |
8487 Sound_FreeSample(data->sample); | |
8488 } | |
8489 alDeleteBuffers(1, data->buffer); | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8490 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8491 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8492 fprintf(stderr, "ALmixer_FreeData: alDeleteBuffers failed. %s\n", alGetString(error)); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8493 } |
0 | 8494 } |
8495 else | |
8496 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8497 ALuint i; |
0 | 8498 |
8499 /* Delete buffer copies if access_data was enabled */ | |
8500 if(data->buffer_map_list != NULL) | |
8501 { | |
8502 for(i=0; i<data->max_queue_buffers; i++) | |
8503 { | |
8504 free(data->buffer_map_list[i].data); | |
8505 } | |
8506 free(data->buffer_map_list); | |
8507 } | |
8508 if(data->circular_buffer_queue != NULL) | |
8509 { | |
8510 CircularQueueUnsignedInt_FreeQueue(data->circular_buffer_queue); | |
8511 } | |
8512 | |
8513 Sound_FreeSample(data->sample); | |
8514 alDeleteBuffers(data->max_queue_buffers, data->buffer); | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8515 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8516 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8517 fprintf(stderr, "ALmixer_FreeData: alDeleteBuffers failed. %s\n", alGetString(error)); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8518 } |
0 | 8519 } |
8520 free(data->buffer); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8521 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8522 LinkedList_Remove(s_listOfALmixerData, |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8523 LinkedList_Find(s_listOfALmixerData, data, NULL) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8524 ); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8525 |
0 | 8526 free(data); |
8527 } | |
8528 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8529 ALint ALmixer_GetTotalTime(ALmixer_Data* data) |
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 if(NULL == data) |
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 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8534 } |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8535 |
0 | 8536 return data->total_time; |
8537 } | |
8538 | |
8539 /* This function will look up the source for the corresponding channel */ | |
8540 /* 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
|
8541 ALuint ALmixer_GetSource(ALint channel) |
0 | 8542 { |
8543 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8544 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8545 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8546 #endif |
0 | 8547 retval = Internal_GetSource(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8548 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8549 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8550 #endif |
0 | 8551 return retval; |
8552 } | |
8553 | |
8554 /* 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
|
8555 ALint ALmixer_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8556 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8557 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8558 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8559 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8560 #endif |
0 | 8561 retval = Internal_GetChannel(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8562 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8563 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8564 #endif |
0 | 8565 return retval; |
8566 } | |
8567 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8568 ALint ALmixer_FindFreeChannel(ALint start_channel) |
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 retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8571 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8572 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8573 #endif |
0 | 8574 retval = Internal_FindFreeChannel(start_channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8575 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8576 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8577 #endif |
0 | 8578 return retval; |
8579 } | |
8580 | |
8581 | |
8582 | |
8583 /* API update function. | |
8584 * It should return the number of buffers that were | |
8585 * queued during the call. The value might be | |
8586 * used to guage how long you might wait to | |
8587 * call the next update loop in case you are worried | |
8588 * about preserving CPU cycles. The idea is that | |
8589 * when a buffer is queued, there was probably some | |
8590 * CPU intensive looping which took awhile. | |
8591 * 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
|
8592 * Timing the call with ALmixer_GetTicks() would produce |
0 | 8593 * more accurate information. |
8594 * Returns a negative value if there was an error, | |
8595 * the value being the number of errors. | |
8596 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8597 ALint ALmixer_Update() |
0 | 8598 { |
8599 #ifdef ENABLE_ALMIXER_THREADS | |
8600 /* The thread will handle all updates by itself. | |
8601 * Don't allow the user to explicitly call update. | |
8602 */ | |
8603 return 0; | |
8604 #else | |
8605 return( Update_ALmixer(NULL) ); | |
8606 #endif | |
8607 } | |
8608 | |
8609 | |
8610 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8611 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
|
8612 { |
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 Channel_Done_Callback = playback_finished_callback; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8617 Channel_Done_Callback_Userdata = user_data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8618 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8619 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8620 #endif |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8624 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
|
8625 { |
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 Channel_Data_Callback = playback_data_callback; |
1 | 8630 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
|
8631 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8632 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8633 #endif |
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 |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8639 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8640 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
|
8641 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8642 ALint retval; |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8645 #endif |
0 | 8646 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
|
8647 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8648 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8649 #endif |
0 | 8650 return retval; |
8651 } | |
8652 | |
8653 | |
8654 /* In case the user wants to specify a source instead of a channel, | |
8655 * they may use this function. This function will look up the | |
8656 * source-to-channel map, and convert the call into a | |
8657 * PlayChannelTimed() function call. | |
8658 * Returns the channel it's being played on. | |
8659 * Note: If you are prefer this method, then you need to be careful | |
8660 * about using PlayChannel, particularly if you request the | |
8661 * first available channels because source and channels have | |
8662 * a one-to-one mapping in this API. It is quite easy for | |
8663 * a channel/source to already be in use because of this. | |
8664 * In this event, an error message will be returned to you. | |
8665 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8666 ALuint ALmixer_PlaySourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALint ticks) |
0 | 8667 { |
8668 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8669 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8670 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8671 #endif |
0 | 8672 retval = Internal_PlaySourceTimed(source, data, loops, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8673 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8674 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8675 #endif |
0 | 8676 return retval; |
8677 } | |
8678 | |
8679 | |
8680 /* Will return the number of channels halted | |
8681 * or 0 for error | |
8682 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8683 ALint ALmixer_HaltChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8684 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8685 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8686 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8687 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8688 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8689 retval = Internal_HaltChannel(channel, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8690 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8691 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8692 #endif |
0 | 8693 return retval; |
8694 } | |
8695 | |
8696 /* Will return the number of channels halted | |
8697 * or 0 for error | |
8698 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8699 ALint ALmixer_HaltSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8700 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8701 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8702 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8703 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8704 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8705 retval = Internal_HaltSource(source, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8706 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8707 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8708 #endif |
0 | 8709 return retval; |
8710 } | |
8711 | |
8712 | |
8713 /* This will rewind the SDL_Sound sample for streamed | |
8714 * samples and start buffering up the data for the next | |
8715 * playback. This may require samples to be halted | |
8716 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8717 ALboolean ALmixer_RewindData(ALmixer_Data* data) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8718 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8719 ALboolean retval; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8720 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8721 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8722 #endif |
0 | 8723 retval = Internal_RewindData(data); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8724 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8725 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8726 #endif |
0 | 8727 return retval; |
8728 } | |
8729 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8730 ALint ALmixer_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8731 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8732 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8733 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8734 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8735 #endif |
0 | 8736 retval = Internal_RewindChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8737 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8738 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8739 #endif |
0 | 8740 return retval; |
8741 } | |
8742 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8743 ALint ALmixer_RewindSource(ALuint source) |
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 ALint 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_RewindSource(source); |
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 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8756 ALint ALmixer_PauseChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8757 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8758 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8759 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8760 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8761 #endif |
0 | 8762 retval = Internal_PauseChannel(channel); |
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_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8770 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8771 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8772 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8773 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8774 #endif |
0 | 8775 retval = Internal_PauseSource(source); |
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_ResumeChannel(ALint channel) |
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_ResumeChannel(channel); |
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_ResumeSource(ALuint source) |
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_ResumeSource(source); |
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 | |
8808 /* Might consider setting eof to 0 as a "feature" | |
8809 * This will allow seek to end to stay there because | |
8810 * Play automatically rewinds if at the end */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8811 ALboolean ALmixer_SeekData(ALmixer_Data* data, ALuint msec) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8812 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8813 ALboolean retval; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8814 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8815 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8816 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8817 retval = Internal_SeekData(data, msec); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8818 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8819 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8820 #endif |
0 | 8821 return retval; |
8822 } | |
8823 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8824 ALint ALmixer_SeekChannel(ALint channel, ALuint msec) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8825 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8826 ALint retval; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8827 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8828 SDL_LockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8829 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8830 retval = Internal_SeekChannel(channel, msec); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8831 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8832 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8833 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8834 return retval; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8835 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8836 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8837 ALint ALmixer_SeekSource(ALuint source, ALuint msec) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8838 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8839 ALint retval; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8840 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8841 SDL_LockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8842 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8843 retval = Internal_SeekSource(source, msec); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8844 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8845 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8846 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8847 return retval; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8848 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8849 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8850 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
|
8851 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8852 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8853 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8854 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8855 #endif |
0 | 8856 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
|
8857 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8858 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8859 #endif |
0 | 8860 return retval; |
8861 } | |
8862 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8863 ALuint ALmixer_FadeInSourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 8864 { |
8865 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8866 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8867 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8868 #endif |
0 | 8869 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
|
8870 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8871 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8872 #endif |
0 | 8873 return retval; |
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 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
|
8877 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8878 ALint 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_FadeOutChannel(channel, ticks); |
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 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8888 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8889 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
|
8890 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8891 ALint 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_FadeOutSource(source, ticks); |
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 |
0 | 8899 return retval; |
8900 } | |
8901 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8902 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
|
8903 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8904 ALint 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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8908 retval = Internal_FadeChannel(channel, ticks, volume); |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8912 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8913 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8914 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8915 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
|
8916 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8917 ALint 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_FadeSource(source, ticks, volume); |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8929 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
|
8930 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8931 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8932 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8933 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8934 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8935 retval = Internal_SetVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8936 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8937 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8938 #endif |
0 | 8939 return retval; |
8940 } | |
8941 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8942 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
|
8943 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8944 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8945 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8946 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8947 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8948 retval = Internal_SetVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8949 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8950 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8951 #endif |
0 | 8952 return retval; |
8953 } | |
8954 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8955 ALfloat ALmixer_GetVolumeChannel(ALint channel) |
0 | 8956 { |
8957 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8958 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8959 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8960 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8961 retval = Internal_GetVolumeChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8962 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8963 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8964 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8965 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8966 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8967 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8968 ALfloat ALmixer_GetVolumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8969 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8970 ALfloat retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8971 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8972 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8973 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8974 retval = Internal_GetVolumeSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8975 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8976 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8977 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8978 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8979 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8980 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8981 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
|
8982 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8983 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8984 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8985 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8986 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8987 retval = Internal_SetMaxVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8988 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8989 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8990 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8991 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8992 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8993 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8994 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
|
8995 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8996 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8997 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8998 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8999 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9000 retval = Internal_SetMaxVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9001 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9002 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9003 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9004 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9005 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9006 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9007 ALfloat ALmixer_GetMaxVolumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9008 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9009 ALfloat retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9010 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9011 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9012 #endif |
0 | 9013 retval = Internal_GetMaxVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9014 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9015 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9016 #endif |
0 | 9017 return retval; |
9018 } | |
9019 | |
9020 ALfloat ALmixer_GetMaxVolumeSource(ALuint source) | |
9021 { | |
9022 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9023 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9024 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9025 #endif |
0 | 9026 retval = Internal_GetMaxVolumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9027 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9028 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9029 #endif |
0 | 9030 return retval; |
9031 } | |
9032 | |
9033 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9034 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
|
9035 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9036 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9037 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9038 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9039 #endif |
0 | 9040 retval = Internal_SetMinVolumeChannel(channel, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9041 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9042 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9043 #endif |
0 | 9044 return retval; |
9045 } | |
9046 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9047 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
|
9048 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9049 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9050 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9051 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9052 #endif |
0 | 9053 retval = Internal_SetMinVolumeSource(source, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9054 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9055 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9056 #endif |
0 | 9057 return retval; |
9058 } | |
9059 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9060 ALfloat ALmixer_GetMinVolumeChannel(ALint channel) |
0 | 9061 { |
9062 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9063 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9064 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9065 #endif |
0 | 9066 retval = Internal_GetMinVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9067 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9068 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9069 #endif |
0 | 9070 return retval; |
9071 } | |
9072 | |
9073 ALfloat ALmixer_GetMinVolumeSource(ALuint source) | |
9074 { | |
9075 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9076 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9077 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9078 #endif |
0 | 9079 retval = Internal_GetMinVolumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9080 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9081 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9082 #endif |
0 | 9083 return retval; |
9084 } | |
9085 | |
9086 | |
9087 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9088 ALboolean ALmixer_SetMasterVolume(ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9089 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9090 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9091 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9092 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9093 #endif |
0 | 9094 retval = Internal_SetMasterVolume(volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9095 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9096 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9097 #endif |
0 | 9098 return retval; |
9099 } | |
9100 | |
9101 ALfloat ALmixer_GetMasterVolume() | |
9102 { | |
9103 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9104 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9105 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9106 #endif |
0 | 9107 retval = Internal_GetMasterVolume(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9108 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9109 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9110 #endif |
0 | 9111 return retval; |
9112 } | |
9113 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9114 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
|
9115 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9116 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9117 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9118 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9119 #endif |
0 | 9120 retval = Internal_ExpireChannel(channel, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9121 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9122 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9123 #endif |
0 | 9124 return retval; |
9125 } | |
9126 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9127 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
|
9128 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9129 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9130 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9131 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9132 #endif |
0 | 9133 retval = Internal_ExpireSource(source, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9134 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9135 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9136 #endif |
0 | 9137 return retval; |
9138 } | |
9139 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9140 ALint ALmixer_IsActiveChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9141 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9142 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9143 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9144 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9145 #endif |
0 | 9146 retval = Internal_QueryChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9147 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9148 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9149 #endif |
0 | 9150 return retval; |
9151 } | |
9152 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9153 ALint ALmixer_IsActiveSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9154 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9155 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9156 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9157 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9158 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9159 retval = Internal_QuerySource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9160 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9161 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9162 #endif |
0 | 9163 return retval; |
9164 } | |
9165 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9166 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9167 ALint ALmixer_IsPlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9168 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9169 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9170 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9171 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9172 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9173 retval = Internal_PlayingChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9174 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9175 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9176 #endif |
0 | 9177 return retval; |
9178 } | |
9179 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9180 ALint ALmixer_IsPlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9181 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9182 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9183 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9184 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9185 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9186 retval = Internal_PlayingSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9187 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9188 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9189 #endif |
0 | 9190 return retval; |
9191 } | |
9192 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9193 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9194 ALint ALmixer_IsPausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9195 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9196 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9197 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9198 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9199 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9200 retval = Internal_PausedChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9201 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9202 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9203 #endif |
0 | 9204 return retval; |
9205 } | |
9206 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9207 ALint ALmixer_IsPausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9208 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9209 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9210 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9211 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9212 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9213 retval = Internal_PausedSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9214 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9215 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9216 #endif |
0 | 9217 return retval; |
9218 } | |
9219 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9220 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9221 ALuint ALmixer_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9222 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9223 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9224 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9225 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9226 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9227 retval = Internal_CountAllFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9228 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9229 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9230 #endif |
0 | 9231 return retval; |
9232 } | |
9233 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9234 ALuint ALmixer_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9235 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9236 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9237 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9238 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9239 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9240 retval = Internal_CountUnreservedFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9241 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9242 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9243 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9244 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9245 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9246 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9247 ALuint ALmixer_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9248 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9249 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9250 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9251 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9252 #endif |
0 | 9253 retval = Internal_CountAllUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9254 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9255 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9256 #endif |
0 | 9257 return retval; |
9258 } | |
9259 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9260 ALuint ALmixer_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9261 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9262 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9263 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9264 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9265 #endif |
0 | 9266 retval = Internal_CountUnreservedUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9267 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9268 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9269 #endif |
0 | 9270 return retval; |
9271 } | |
9272 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9273 ALboolean ALmixer_IsPredecoded(ALmixer_Data* data) |
1 | 9274 { |
9275 if(NULL == data) | |
9276 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9277 return AL_FALSE; |
1 | 9278 } |
9279 return data->decoded_all; | |
9280 } | |
9281 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9282 ALboolean ALmixer_CompiledWithThreadBackend() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9283 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9284 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9285 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9286 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9287 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9288 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9289 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9290 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9291 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9292 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9293 |