Mercurial > almixer_isolated
annotate ALmixer.c @ 29:1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Mon, 28 Mar 2011 16:05:25 -0700 |
parents | 60500a33735a |
children | a554e41eeb13 |
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 */ | |
29
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
226 static ALuint g_StreamThreadEnabled = 0; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
227 static SDL_mutex* s_simpleLock; |
0 | 228 static SDL_Thread* Stream_Thread_global = NULL; |
26
884cce2515eb
Put LowerThreadPriority in ENABLE_ALMIXER_THREADS_BLOCK
Eric Wing <ewing . public |-at-| gmail . com>
parents:
25
diff
changeset
|
229 #endif /* ENABLE_ALMIXER_THREADS */ |
0 | 230 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
231 static LinkedList* s_listOfALmixerData = NULL; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
232 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
233 /* Special stuff for iOS interruption handling */ |
29
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
234 ALuint g_inInterruption = 0; |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
235 static ALCcontext* s_interruptionContext = NULL; |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
236 |
0 | 237 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
238 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
239 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
|
240 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
241 static void (*alcMacOSXMixerOutputRateProcPtr)(const ALdouble) = NULL; |
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 if(NULL == alcMacOSXMixerOutputRateProcPtr) |
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 alcMacOSXMixerOutputRateProcPtr = alGetProcAddress((const ALCchar*) "alcMacOSXMixerOutputRate"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
246 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
247 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
248 if(NULL != alcMacOSXMixerOutputRateProcPtr) |
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 alcMacOSXMixerOutputRateProcPtr(sample_rate); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
251 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
252 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
253 return; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
254 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
255 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
256 ALdouble Internal_alcMacOSXGetMixerOutputRate() |
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 static ALdouble (*alcMacOSXGetMixerOutputRateProcPtr)(void) = NULL; |
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 if(NULL == alcMacOSXGetMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
261 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
262 alcMacOSXGetMixerOutputRateProcPtr = alGetProcAddress((const ALCchar*) "alcMacOSXGetMixerOutputRate"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
263 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
264 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
265 if(NULL != 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 return alcMacOSXGetMixerOutputRateProcPtr(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
268 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
269 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
270 return 0.0; |
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 #endif |
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 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
275 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
276 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
277 #include <QuartzCore/QuartzCore.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
278 #include <unistd.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
279 static CFTimeInterval s_ticksBaseTime = 0.0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
280 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
281 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
282 #define WIN32_LEAN_AND_MEAN |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
283 #include <windows.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
284 #include <winbase.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
285 LARGE_INTEGER s_hiResTicksPerSecond; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
286 double s_hiResSecondsPerTick; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
287 LARGE_INTEGER s_ticksBaseTime; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
288 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
289 #include <unistd.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
290 #include <time.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
291 static struct timespec s_ticksBaseTime; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
292 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
293 static void ALmixer_InitTime() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
294 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
295 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
296 s_ticksBaseTime = CACurrentMediaTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
297 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
298 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
299 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
|
300 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
|
301 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
302 QueryPerformanceCounter(&s_ticksBaseTime); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
303 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
|
304 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
305 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
306 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
307 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
|
308 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
|
309 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
310 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
311 /* clock_gettime is POSIX.1-2001 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
312 clock_gettime(CLOCK_MONOTONIC, &s_ticksBaseTime); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
313 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
314 |
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 static ALuint ALmixer_GetTicks() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
317 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
318 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
319 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
|
320 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
321 LARGE_INTEGER current_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
322 QueryPerformanceCounter(¤t_time); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
323 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
|
324 #else /* assuming POSIX */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
325 /* clock_gettime is POSIX.1-2001 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
326 struct timespec current_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
327 clock_gettime(CLOCK_MONOTONIC, ¤t_time); |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
328 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
|
329 #endif |
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 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
|
332 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
333 #if defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
334 Sleep(milliseconds_delay); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
335 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
336 usleep(milliseconds_delay); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
337 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
338 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
339 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
340 #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
|
341 #define ALmixer_GetTicks SDL_GetTicks |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
342 #define ALmixer_Delay SDL_Delay |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
343 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
344 |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
345 /* 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
|
346 * 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
|
347 * 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
|
348 * This seemed to help the problem. |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
349 * 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
|
350 * 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
|
351 * 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
|
352 * 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
|
353 * 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
|
354 * of the CPU time in Shark/Instruments. |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
355 */ |
26
884cce2515eb
Put LowerThreadPriority in ENABLE_ALMIXER_THREADS_BLOCK
Eric Wing <ewing . public |-at-| gmail . com>
parents:
25
diff
changeset
|
356 #ifdef ENABLE_ALMIXER_THREADS |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
357 #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
|
358 #include <pthread.h> |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
359 #endif |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
360 static void Internal_LowerThreadPriority(SDL_Thread* simple_thread) |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
361 { |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
362 /* Might open to other platforms as needed */ |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
363 #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
|
364 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
365 SimpleThread_SetThreadPriority(Stream_Thread_global, 0); |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
366 #else |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
367 struct sched_param schedule_param; |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
368 int sched_policy; |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
369 int ret_val; |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
370 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
|
371 /* 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
|
372 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
|
373 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
|
374 #endif |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
375 #else |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
376 /* No-Op */ |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
377 #endif |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
378 } |
26
884cce2515eb
Put LowerThreadPriority in ENABLE_ALMIXER_THREADS_BLOCK
Eric Wing <ewing . public |-at-| gmail . com>
parents:
25
diff
changeset
|
379 #endif /* ENABLE_ALMIXER_THREADS */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
380 |
0 | 381 /* If ENABLE_PARANOID_SIGNEDNESS_CHECK is used, |
382 * these values will be reset on Init() | |
383 * Consider these values Read-Only. | |
384 */ | |
385 | |
386 #define ALMIXER_SIGNED_VALUE 127 | |
387 #define ALMIXER_UNSIGNED_VALUE 255 | |
388 | |
389 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
390 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
|
391 static ALushort SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; |
0 | 392 #else |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
393 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
|
394 static const ALushort SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; |
0 | 395 #endif |
396 | |
1 | 397 |
398 /* This can be private instead of being in the header now that I moved | |
399 * ALmixer_Data inside here. | |
400 */ | |
401 typedef struct ALmixer_Buffer_Map ALmixer_Buffer_Map; | |
402 | |
403 | |
404 struct ALmixer_Data | |
405 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
406 ALboolean decoded_all; /* dictates different behaviors */ |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
407 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
|
408 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
409 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
|
410 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
|
411 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
412 ALuint total_bytes; /* For predecoded */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
413 ALuint loaded_bytes; /* For predecoded (for seek) */ |
1 | 414 |
415 Sound_Sample* sample; /* SDL_Sound provides the data */ | |
416 ALuint* buffer; /* array of OpenAL buffers (at least 1 for predecoded) */ | |
417 | |
418 /* Needed for streamed buffers */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
419 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
|
420 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
|
421 ALuint num_buffers_in_use; /* number of buffers in use */ |
28
60500a33735a
Initial backend changes to decouple assumption of 1 buffer queued per channel / per pass. API will eventually be changed/broken to support this.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
27
diff
changeset
|
422 ALuint num_target_buffers_per_pass; /* number of buffers to try to queue in an update pass */ |
1 | 423 |
424 /* This stuff is for streamed buffers that require data access */ | |
425 ALmixer_Buffer_Map* buffer_map_list; /* translate ALbuffer to index | |
426 and holds pointer to copy of data for | |
427 data access */ | |
428 ALuint current_buffer; /* The current playing buffer */ | |
429 | |
430 /* Nvidia distribution refuses to recognize a simple buffer query command | |
431 * unlike all other distributions. It's forcing me to redo the code | |
432 * to accomodate this Nvidia flaw by making me maintain a "best guess" | |
433 * copy of what I think the buffer queue state looks like. | |
434 * A circular queue would a helpful data structure for this task, | |
435 * but I wanted to avoid making an additional header requirement, | |
436 * so I'm making it a void* | |
437 */ | |
438 void* circular_buffer_queue; | |
439 | |
440 | |
441 }; | |
442 | |
0 | 443 static struct ALmixer_Channel |
444 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
445 ALboolean channel_in_use; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
446 ALboolean callback_update; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
447 ALboolean needs_stream; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
448 ALboolean halted; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
449 ALboolean paused; |
0 | 450 ALuint alsource; |
451 ALmixer_Data* almixer_data; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
452 ALint loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
453 ALint expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
454 ALuint start_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
455 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
456 ALboolean fade_enabled; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
457 ALuint fade_expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
458 ALuint fade_start_time; |
0 | 459 ALfloat fade_inv_time; |
460 ALfloat fade_start_volume; | |
461 ALfloat fade_end_volume; | |
462 ALfloat max_volume; | |
463 ALfloat min_volume; | |
464 | |
465 /* Do we need other flags? | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
466 ALbyte *samples; |
0 | 467 int volume; |
468 int looping; | |
469 int tag; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
470 ALuint expire; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
471 ALuint start_time; |
0 | 472 Mix_Fading fading; |
473 int fade_volume; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
474 ALuint fade_length; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
475 ALuint ticks_fade; |
0 | 476 effect_info *effects; |
477 */ | |
478 } *ALmixer_Channel_List = NULL; | |
479 | |
1 | 480 struct ALmixer_Buffer_Map |
481 { | |
482 ALuint albuffer; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
483 ALint index; /* might not need */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
484 ALbyte* data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
485 ALuint num_bytes; |
1 | 486 }; |
487 | |
0 | 488 /* This will be used to find a channel if the user supplies a source */ |
489 typedef struct Source_Map | |
490 { | |
491 ALuint source; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
492 ALint channel; |
0 | 493 } Source_Map; |
494 /* Keep an array of all sources with their associated channel */ | |
495 static Source_Map* Source_Map_List; | |
496 | |
497 static int Compare_Source_Map(const void* a, const void* b) | |
498 { | |
499 return ( ((Source_Map*)a)->source - ((Source_Map*)b)->source ); | |
500 } | |
501 | |
502 /* Sort by channel instead of source */ | |
503 static int Compare_Source_Map_by_channel(const void* a, const void* b) | |
504 { | |
505 return ( ((Source_Map*)a)->channel - ((Source_Map*)b)->channel ); | |
506 } | |
507 | |
508 /* Compare by albuffer */ | |
509 static int Compare_Buffer_Map(const void* a, const void* b) | |
510 { | |
1 | 511 return ( ((ALmixer_Buffer_Map*)a)->albuffer - ((ALmixer_Buffer_Map*)b)->albuffer ); |
0 | 512 } |
513 | |
514 /* This is for the user defined callback via | |
515 * ALmixer_ChannelFinished() | |
516 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
517 static void (*Channel_Done_Callback)(ALint which_channel, ALuint al_source, ALmixer_Data* almixer_data, ALboolean finished_naturally, void* user_data) = NULL; |
0 | 518 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
|
519 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 | 520 static void* Channel_Data_Callback_Userdata = NULL; |
0 | 521 |
522 | |
523 static void PrintQueueStatus(ALuint source) | |
524 { | |
525 ALint buffers_queued = 0; | |
526 ALint buffers_processed = 0; | |
527 ALenum error; | |
528 | |
529 /* Get the number of buffers still queued */ | |
530 alGetSourcei( | |
531 source, | |
532 AL_BUFFERS_QUEUED, | |
533 &buffers_queued | |
534 ); | |
535 | |
536 if((error = alGetError()) != AL_NO_ERROR) | |
537 { | |
538 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
|
539 alGetString(error)); |
0 | 540 } |
541 /* Get the number of buffers processed | |
542 * so we know if we need to refill | |
543 */ | |
544 alGetSourcei( | |
545 source, | |
546 AL_BUFFERS_PROCESSED, | |
547 &buffers_processed | |
548 ); | |
549 if((error = alGetError()) != AL_NO_ERROR) | |
550 { | |
551 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
|
552 alGetString(error)); |
0 | 553 } |
554 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
555 /* |
0 | 556 fprintf(stderr, "For source: %d, buffers_queued=%d, buffers_processed=%d\n", |
557 source, | |
558 buffers_queued, | |
559 buffers_processed); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
560 */ |
0 | 561 } |
562 | |
563 | |
564 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
565 static void Init_Channel(ALint channel) |
0 | 566 { |
567 ALmixer_Channel_List[channel].channel_in_use = 0; | |
568 ALmixer_Channel_List[channel].callback_update = 0; | |
569 ALmixer_Channel_List[channel].needs_stream = 0; | |
570 ALmixer_Channel_List[channel].paused = 0; | |
571 ALmixer_Channel_List[channel].halted = 0; | |
572 ALmixer_Channel_List[channel].loops = 0; | |
573 | |
574 ALmixer_Channel_List[channel].expire_ticks = 0; | |
575 ALmixer_Channel_List[channel].start_time = 0; | |
576 | |
577 ALmixer_Channel_List[channel].fade_enabled = 0; | |
578 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
579 ALmixer_Channel_List[channel].fade_start_time = 0; | |
580 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
581 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
582 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
583 ALmixer_Channel_List[channel].max_volume = 1.0f; | |
584 ALmixer_Channel_List[channel].min_volume = 0.0f; | |
585 | |
586 ALmixer_Channel_List[channel].almixer_data = NULL; | |
587 } | |
588 /* Quick helper function to clean up a channel | |
589 * after it's done playing */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
590 static void Clean_Channel(ALint channel) |
0 | 591 { |
592 ALenum error; | |
593 ALmixer_Channel_List[channel].channel_in_use = 0; | |
594 ALmixer_Channel_List[channel].callback_update = 0; | |
595 ALmixer_Channel_List[channel].needs_stream = 0; | |
596 ALmixer_Channel_List[channel].paused = 0; | |
597 ALmixer_Channel_List[channel].halted = 0; | |
598 ALmixer_Channel_List[channel].loops = 0; | |
599 | |
600 | |
601 ALmixer_Channel_List[channel].expire_ticks = 0; | |
602 ALmixer_Channel_List[channel].start_time = 0; | |
603 | |
604 ALmixer_Channel_List[channel].fade_enabled = 0; | |
605 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
606 ALmixer_Channel_List[channel].fade_start_time = 0; | |
607 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
608 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
609 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
610 | |
611 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MAX_GAIN, | |
612 ALmixer_Channel_List[channel].max_volume); | |
613 | |
614 if((error = alGetError()) != AL_NO_ERROR) | |
615 { | |
616 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
|
617 alGetString(error)); |
0 | 618 } |
619 | |
620 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MIN_GAIN, | |
621 ALmixer_Channel_List[channel].min_volume); | |
622 if((error = alGetError()) != AL_NO_ERROR) | |
623 { | |
624 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
|
625 alGetString(error)); |
0 | 626 } |
627 | |
628 if(ALmixer_Channel_List[channel].almixer_data != NULL) | |
629 { | |
630 if(ALmixer_Channel_List[channel].almixer_data->in_use > 0) | |
631 { | |
632 ALmixer_Channel_List[channel].almixer_data->in_use--; | |
633 } | |
634 } | |
635 /* Needed to determine if rewind is needed, can't reset */ | |
636 /* | |
637 ALmixer_Channel_List[channel].almixer_data->eof = 0; | |
638 */ | |
639 | |
640 ALmixer_Channel_List[channel].almixer_data = NULL; | |
641 } | |
642 | |
643 /* What shoud this return? | |
644 * 127 for signed, 255 for unsigned | |
645 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
646 static ALubyte GetSignednessValue(ALushort format) |
0 | 647 { |
648 switch(format) | |
649 { | |
650 case AUDIO_U8: | |
651 case AUDIO_U16LSB: | |
652 case AUDIO_U16MSB: | |
653 return ALMIXER_UNSIGNED_VALUE; | |
654 break; | |
655 case AUDIO_S8: | |
656 case AUDIO_S16LSB: | |
657 case AUDIO_S16MSB: | |
658 return ALMIXER_SIGNED_VALUE; | |
659 break; | |
660 default: | |
661 return 0; | |
662 } | |
663 return 0; | |
664 } | |
665 | |
666 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
667 static ALubyte GetBitDepth(ALushort format) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
668 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
669 ALubyte bit_depth = 16; |
0 | 670 |
671 switch(format) | |
672 { | |
673 case AUDIO_U8: | |
674 case AUDIO_S8: | |
675 bit_depth = 8; | |
676 break; | |
677 | |
678 case AUDIO_U16LSB: | |
679 /* | |
680 case AUDIO_U16: | |
681 */ | |
682 case AUDIO_S16LSB: | |
683 /* | |
684 case AUDIO_S16: | |
685 */ | |
686 case AUDIO_U16MSB: | |
687 case AUDIO_S16MSB: | |
688 /* | |
689 case AUDIO_U16SYS: | |
690 case AUDIO_S16SYS: | |
691 */ | |
692 bit_depth = 16; | |
693 break; | |
694 default: | |
695 bit_depth = 0; | |
696 } | |
697 return bit_depth; | |
698 } | |
699 | |
700 /* Need to translate between SDL/SDL_Sound audiospec | |
701 * and OpenAL conventions */ | |
702 static ALenum TranslateFormat(Sound_AudioInfo* info) | |
703 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
704 ALubyte bit_depth; |
0 | 705 |
706 bit_depth = GetBitDepth(info->format); | |
707 if(0 == bit_depth) | |
708 { | |
709 fprintf(stderr, "Warning: Unknown bit depth. Setting to 16\n"); | |
710 bit_depth = 16; | |
711 } | |
712 | |
713 if(2 == info->channels) | |
714 { | |
715 if(16 == bit_depth) | |
716 { | |
717 return AL_FORMAT_STEREO16; | |
718 } | |
719 else | |
720 { | |
721 return AL_FORMAT_STEREO8; | |
722 } | |
723 } | |
724 else | |
725 { | |
726 if(16 == bit_depth) | |
727 { | |
728 return AL_FORMAT_MONO16; | |
729 } | |
730 else | |
731 { | |
732 return AL_FORMAT_MONO8; | |
733 } | |
734 } | |
735 /* Make compiler happy. Shouldn't get here */ | |
736 return AL_FORMAT_STEREO16; | |
737 } | |
738 | |
1 | 739 |
740 /* This will compute the total playing time | |
741 * based upon the number of bytes and audio info. | |
742 * (In prinicple, it should compute the time for any given length) | |
743 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
744 static ALuint Compute_Total_Time_Decomposed(ALuint bytes_per_sample, ALuint frequency, ALubyte channels, size_t total_bytes) |
1 | 745 { |
746 double total_sec; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
747 ALuint total_msec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
748 ALuint bytes_per_sec; |
1 | 749 |
750 if(0 == total_bytes) | |
751 { | |
752 return 0; | |
753 } | |
754 /* To compute Bytes per second, do | |
755 * samples_per_sec * bytes_per_sample * number_of_channels | |
756 */ | |
757 bytes_per_sec = frequency * bytes_per_sample * channels; | |
758 | |
759 /* Now to get total time (sec), do | |
760 * total_bytes / bytes_per_sec | |
761 */ | |
762 total_sec = total_bytes / (double)bytes_per_sec; | |
763 | |
764 /* Now convert seconds to milliseconds | |
765 * Add .5 to the float to do rounding before the final cast | |
766 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
767 total_msec = (ALuint) ( (total_sec * 1000) + 0.5 ); |
1 | 768 /* |
769 fprintf(stderr, "freq=%d, bytes_per_sample=%d, channels=%d, total_msec=%d\n", frequency, bytes_per_sample, channels, total_msec); | |
770 */ | |
771 return total_msec; | |
772 } | |
773 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
774 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
|
775 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
776 ALuint bytes_per_sample; |
1 | 777 |
778 if(0 == total_bytes) | |
779 { | |
780 return 0; | |
781 } | |
782 /* 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
|
783 * 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
|
784 * 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
|
785 * 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
|
786 * 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
|
787 * 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
|
788 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
789 bytes_per_sample = (ALuint) ((info->format & 0xFF) / 8); |
1 | 790 |
791 return Compute_Total_Time_Decomposed(bytes_per_sample, info->rate, info->channels, total_bytes); | |
792 } /* End Compute_Total_Time */ | |
793 | |
794 | |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
795 #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
|
796 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
|
797 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
798 double total_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
799 ALuint bytes_per_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
800 size_t total_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
801 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
802 if(0 >= total_msec) |
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 return 0; |
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 /* To compute Bytes per second, do |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
807 * 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
|
808 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
809 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
|
810 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
811 /* convert milliseconds to seconds */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
812 total_sec = total_msec / 1000.0; |
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 /* Now to get total bytes */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
815 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
|
816 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
817 /* 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
|
818 */ |
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 return total_bytes; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
823 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
|
824 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
825 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
826 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
827 if(0 >= total_msec) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
828 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
829 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
830 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
831 /* 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
|
832 * 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
|
833 * 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
|
834 * 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
|
835 * 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
|
836 * 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
|
837 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
838 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
|
839 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
840 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
|
841 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
842 |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
843 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
844 /* 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
|
845 * 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
|
846 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
847 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
|
848 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
849 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
850 ALuint bytes_per_frame; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
851 size_t evenly_divisible_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
852 size_t remainder_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
853 size_t return_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
854 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
855 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
|
856 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
857 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
|
858 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
859 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
|
860 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
861 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
|
862 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
|
863 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
864 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
|
865 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
866 /* 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
|
867 * 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
|
868 * 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
|
869 * 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
|
870 * 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
|
871 * 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
|
872 * 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
|
873 * 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
|
874 * 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
|
875 */ |
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_bytes += 64; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
878 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
879 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
880 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
|
881 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
882 return return_bytes; |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
883 } |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
884 #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
|
885 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
886 |
1 | 887 |
0 | 888 /**************** REMOVED ****************************/ |
889 /* This was removed because I originally thought | |
890 * OpenAL could return a pointer to the buffer data, | |
891 * but I was wrong. If something like that is ever | |
892 * implemented, then this might become useful. | |
893 */ | |
894 #if 0 | |
895 /* Reconstruct_Sound_Sample and Set_AudioInfo only | |
896 * are needed if the Seek memory optimization is | |
897 * used. Also, the Loki dist doesn't seem to support | |
898 * AL_DATA which I need for it. | |
899 */ | |
900 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION | |
901 | |
902 static void Set_AudioInfo(Sound_AudioInfo* info, ALint frequency, ALint bits, ALint channels) | |
903 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
904 info->rate = (ALuint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
905 info->channels = (ALubyte)channels; |
0 | 906 |
907 /* Not sure if it should be signed or unsigned. Hopefully | |
908 * that detail won't be needed. | |
909 */ | |
910 if(8 == bits) | |
911 { | |
912 info->format = AUDIO_U8; | |
913 } | |
914 else | |
915 { | |
916 info->format = AUDIO_U16SYS; | |
917 } | |
918 fprintf(stderr, "Audio info: freq=%d, chan=%d, format=%d\n", | |
919 info->rate, info->channels, info->format); | |
920 | |
921 } | |
922 | |
923 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
924 static ALint Reconstruct_Sound_Sample(ALmixer_Data* data) |
0 | 925 { |
926 ALenum error; | |
927 ALint* data_from_albuffer; | |
928 ALint freq; | |
929 ALint bits; | |
930 ALint channels; | |
931 ALint size; | |
932 | |
933 /* Create memory all initiallized to 0. */ | |
934 data->sample = (Sound_Sample*)calloc(1, sizeof(Sound_Sample)); | |
935 if(NULL == data->sample) | |
936 { | |
937 ALmixer_SetError("Out of memory for Sound_Sample"); | |
938 return -1; | |
939 } | |
940 | |
941 /* Clear errors */ | |
942 alGetError(); | |
943 | |
944 alGetBufferi(data->buffer[0], AL_FREQUENCY, &freq); | |
945 if((error = alGetError()) != AL_NO_ERROR) | |
946 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
947 ALmixer_SetError("alGetBufferi(AL_FREQUENCY): %s", alGetString(error) ); |
0 | 948 free(data->sample); |
949 data->sample = NULL; | |
950 return -1; | |
951 } | |
952 | |
953 alGetBufferi(data->buffer[0], AL_BITS, &bits); | |
954 if((error = alGetError()) != AL_NO_ERROR) | |
955 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
956 ALmixer_SetError("alGetBufferi(AL_BITS): %s", alGetString(error) ); |
0 | 957 free(data->sample); |
958 data->sample = NULL; | |
959 return -1; | |
960 } | |
961 | |
962 alGetBufferi(data->buffer[0], AL_CHANNELS, &channels); | |
963 if((error = alGetError()) != AL_NO_ERROR) | |
964 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
965 ALmixer_SetError("alGetBufferi(AL_CHANNELS): %s", alGetString(error) ); |
0 | 966 free(data->sample); |
967 data->sample = NULL; | |
968 return -1; | |
969 } | |
970 | |
971 alGetBufferi(data->buffer[0], AL_SIZE, &size); | |
972 if((error = alGetError()) != AL_NO_ERROR) | |
973 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
974 ALmixer_SetError("alGetBufferi(AL_SIZE): %s", alGetString(error) ); |
0 | 975 free(data->sample); |
976 data->sample = NULL; | |
977 return -1; | |
978 } | |
979 | |
980 alGetBufferi(data->buffer[0], AL_DATA, data_from_albuffer); | |
981 if((error = alGetError()) != AL_NO_ERROR) | |
982 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
983 ALmixer_SetError("alGetBufferi(AL_DATA): %s", alGetString(error) ); |
0 | 984 free(data->sample); |
985 data->sample = NULL; | |
986 return -1; | |
987 } | |
988 | |
989 if(size <= 0) | |
990 { | |
991 ALmixer_SetError("No data in al buffer"); | |
992 free(data->sample); | |
993 data->sample = NULL; | |
994 return -1; | |
995 } | |
996 | |
997 /* Now that we have all the attributes, we need to | |
998 * allocate memory for the buffer and reconstruct | |
999 * the AudioInfo attributes. | |
1000 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1001 data->sample->buffer = malloc(size*sizeof(ALbyte)); |
0 | 1002 if(NULL == data->sample->buffer) |
1003 { | |
1004 ALmixer_SetError("Out of memory for sample->buffer"); | |
1005 free(data->sample); | |
1006 data->sample = NULL; | |
1007 return -1; | |
1008 } | |
1009 | |
1010 memcpy(data->sample->buffer, data_from_albuffer, size); | |
1011 data->sample->buffer_size = size; | |
1012 | |
1013 /* Fill up the Sound_AudioInfo structures */ | |
1014 Set_AudioInfo(&data->sample->desired, freq, bits, channels); | |
1015 Set_AudioInfo(&data->sample->actual, freq, bits, channels); | |
1016 | |
1017 return 0; | |
1018 } | |
1019 | |
1020 #endif /* End DISABLE_SEEK_MEMORY_OPTIMIZATION */ | |
1021 #endif | |
1022 /*************** END REMOVED *************************/ | |
1023 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1024 static void Invoke_Channel_Done_Callback(ALint which_channel, ALboolean did_finish_naturally) |
0 | 1025 { |
1026 if(NULL == Channel_Done_Callback) | |
1027 { | |
1028 return; | |
1029 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1030 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
|
1031 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1032 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1033 static ALint LookUpBuffer(ALuint buffer, ALmixer_Buffer_Map* buffer_map_list, ALuint num_items_in_list) |
0 | 1034 { |
1035 /* Only the first value is used for the key */ | |
1 | 1036 ALmixer_Buffer_Map key = { 0, 0, NULL, 0 }; |
1037 ALmixer_Buffer_Map* found_item = NULL; | |
0 | 1038 key.albuffer = buffer; |
1039 | |
1040 /* Use the ANSI C binary search feature (yea!) */ | |
1 | 1041 found_item = (ALmixer_Buffer_Map*)bsearch(&key, buffer_map_list, num_items_in_list, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 1042 if(NULL == found_item) |
1043 { | |
1044 ALmixer_SetError("Can't find buffer"); | |
1045 return -1; | |
1046 } | |
1047 return found_item->index; | |
1048 } | |
1049 | |
1050 | |
1051 /* FIXME: Need to pass back additional info to be useful. | |
1052 * Bit rate, stereo/mono (num chans), time in msec? | |
1053 * Precoded/streamed flag so user can plan for future data? | |
1054 */ | |
1 | 1055 /* |
1056 * channels: 1 for mono, 2 for stereo | |
1057 * | |
1058 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1059 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
|
1060 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1061 ALboolean is_unsigned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1062 ALubyte bits_per_sample = GetBitDepth(format); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1063 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1064 ALuint length_in_msec; |
1 | 1065 |
1066 if(GetSignednessValue(format) == ALMIXER_UNSIGNED_VALUE) | |
1067 { | |
1068 is_unsigned = 1; | |
1069 } | |
1070 else | |
1071 { | |
1072 is_unsigned = 0; | |
1073 } | |
1074 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1075 bytes_per_sample = (ALuint) (bits_per_sample / 8); |
1 | 1076 |
1077 length_in_msec = Compute_Total_Time_Decomposed(bytes_per_sample, frequency, channels, num_bytes); | |
1078 | |
0 | 1079 /* |
1080 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); | |
1081 */ | |
1082 if(NULL == Channel_Data_Callback) | |
1083 { | |
1084 return; | |
1085 } | |
1 | 1086 /* |
1087 * Channel_Data_Callback(which_channel, data, num_bytes, frequency, channels, GetBitDepth(format), format, decode_mode_is_predecoded); | |
1088 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1089 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
|
1090 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1091 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1092 static void Invoke_Predecoded_Channel_Data_Callback(ALint channel, ALmixer_Data* data) |
0 | 1093 { |
1094 if(NULL == data->sample) | |
1095 { | |
1096 return; | |
1097 } | |
1098 /* The buffer position is complicated because if the current data was seeked, | |
1099 * we must adjust the buffer to the seek position | |
1100 */ | |
1101 Invoke_Channel_Data_Callback(channel, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1102 (((ALbyte*) data->sample->buffer) + (data->total_bytes - data->loaded_bytes) ), |
0 | 1103 data->loaded_bytes, |
1104 data->sample->desired.rate, | |
1105 data->sample->desired.channels, | |
1106 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1107 AL_TRUE |
0 | 1108 ); |
1109 } | |
1110 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1111 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
|
1112 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1113 ALint index; |
0 | 1114 if(NULL == data->buffer_map_list) |
1115 { | |
1116 return; | |
1117 } | |
1118 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1119 /* This should catch the case where all buffers are unqueued | |
1120 * and the "current" buffer is id: 0 | |
1121 */ | |
1122 if(-1 == index) | |
1123 { | |
1124 return; | |
1125 } | |
1126 Invoke_Channel_Data_Callback(channel, | |
1127 data->buffer_map_list[index].data, | |
1128 data->buffer_map_list[index].num_bytes, | |
1129 data->sample->desired.rate, | |
1130 data->sample->desired.channels, | |
1131 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1132 AL_FALSE |
0 | 1133 ); |
1134 } | |
1135 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1136 /* Converts milliseconds to byte positions. |
0 | 1137 * This is needed for seeking on predecoded samples |
1138 */ | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1139 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
|
1140 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1141 ALuint bytes_per_sample; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1142 ALuint bytes_per_frame; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1143 float bytes_per_millisecond; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1144 float byte_position; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1145 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1146 if(audio_info == NULL) |
0 | 1147 { |
1148 fprintf(stderr, "Error, info is NULL\n"); | |
1149 } | |
1150 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1151 /* 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
|
1152 * 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
|
1153 * 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
|
1154 * 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
|
1155 * 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
|
1156 * Uint32 to unspecified size types like ALuint. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1157 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1158 bytes_per_sample = (ALuint) ((audio_info->format & 0xFF) / 8); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1159 bytes_per_frame = bytes_per_sample * audio_info->channels; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1160 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
|
1161 byte_position = ((float)(number_of_milliseconds)) * bytes_per_millisecond; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1162 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
|
1163 } |
0 | 1164 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1165 static ALint Set_Predecoded_Seek_Position(ALmixer_Data* data, ALuint byte_position) |
0 | 1166 { |
1167 ALenum error; | |
1168 /* clear error */ | |
1169 alGetError(); | |
1170 | |
1171 /* Is it greater than, or greater-than or equal to ?? */ | |
1172 if(byte_position > data->total_bytes) | |
1173 { | |
1174 /* 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
|
1175 /* |
0 | 1176 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
|
1177 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1178 |
0 | 1179 /* In case the below thing doesn't work, |
1180 * just rewind the whole thing. | |
1181 * | |
1182 alBufferData(data->buffer[0], | |
1183 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1184 (ALbyte*) data->sample->buffer, |
0 | 1185 data->total_bytes, |
1186 data->sample->desired.rate | |
1187 ); | |
1188 */ | |
1189 | |
1190 /* I was trying to set to the end, (1 byte remaining), | |
1191 * but I was getting freezes. I'm thinking it might be | |
1192 * another Power of 2 bug in the Loki dist. I tried 2, | |
1193 * and it still hung. 4 didn't hang, but I got a clip | |
1194 * artifact. 8 seemed to work okay. | |
1195 */ | |
1196 alBufferData(data->buffer[0], | |
1197 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1198 (((ALbyte*) data->sample->buffer) + (data->total_bytes - 8) ), |
0 | 1199 8, |
1200 data->sample->desired.rate | |
1201 ); | |
1202 if( (error = alGetError()) != AL_NO_ERROR) | |
1203 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1204 ALmixer_SetError("Can't seek past end and alBufferData failed: %s\n", alGetString(error)); |
0 | 1205 return -1; |
1206 } | |
1207 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1208 * query command to work because I don't know if it will mutilate the | |
1209 * size for its own purposes or return the original size | |
1210 */ | |
1211 data->loaded_bytes = 8; | |
1212 | |
1213 /* Not sure if this should be an error or not */ | |
1214 /* | |
1215 ALmixer_SetError("Can't Seek past end"); | |
1216 return -1; | |
1217 */ | |
1218 return 0; | |
1219 } | |
1220 | |
1221 alBufferData(data->buffer[0], | |
1222 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1223 &(((ALbyte*)data->sample->buffer)[byte_position]), |
0 | 1224 data->total_bytes - byte_position, |
1225 data->sample->desired.rate | |
1226 ); | |
1227 if( (error = alGetError()) != AL_NO_ERROR) | |
1228 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1229 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1230 return -1; |
1231 } | |
1232 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1233 * query command to work because I don't know if it will mutilate the | |
1234 * size for its own purposes or return the original size | |
1235 */ | |
1236 data->loaded_bytes = data->total_bytes - byte_position; | |
1237 | |
1238 return 0; | |
1239 } | |
1240 | |
1241 /* Because we have multiple queue buffers and OpenAL won't let | |
1242 * us access them, we need to keep copies of each buffer around | |
1243 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1244 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
|
1245 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1246 ALint index; |
0 | 1247 /* We only want to copy if access_data is true. |
1248 * This is determined by whether memory has been | |
1249 * allocated in the buffer_map_list or not | |
1250 */ | |
1251 if(NULL == data->buffer_map_list) | |
1252 { | |
1253 return -1; | |
1254 } | |
1255 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1256 if(-1 == index) | |
1257 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1258 /* |
0 | 1259 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
|
1260 */ |
0 | 1261 return -1; |
1262 } | |
1263 /* Copy the data to the access buffer */ | |
1264 memcpy(data->buffer_map_list[index].data, data->sample->buffer, num_bytes); | |
1265 data->buffer_map_list[index].num_bytes = data->sample->buffer_size; | |
1266 | |
1267 return 0; | |
1268 } | |
1269 | |
1270 | |
1271 /* For streamed data, gets more data | |
1272 * and prepares it in the active Mix_chunk | |
1273 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1274 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
|
1275 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1276 ALuint bytes_decoded; |
0 | 1277 ALenum error; |
1278 if(NULL == data) | |
1279 { | |
1280 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1281 return 0; | |
1282 } | |
1283 | |
1284 bytes_decoded = Sound_Decode(data->sample); | |
1285 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1286 { | |
1287 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1288 ALmixer_SetError(Sound_GetError()); | |
1289 /* Force cleanup through FreeData | |
1290 Sound_FreeSample(data->sample); | |
1291 */ | |
1292 return 0; | |
1293 } | |
1294 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1295 /* 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
|
1296 |
0 | 1297 /* Don't forget to add check for EOF */ |
1298 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1299 if(0 == bytes_decoded) | |
1300 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1301 data->eof = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1302 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1303 #if 0 |
0 | 1304 fprintf(stderr, "Hit eof while trying to buffer\n"); |
1305 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1306 { | |
1307 fprintf(stderr, "\tEOF flag\n"); | |
1308 } | |
1309 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1310 { | |
1311 fprintf(stderr, "\tCanSeek flag\n"); | |
1312 } | |
1313 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1314 { | |
1315 fprintf(stderr, "\tEAGAIN flag\n"); | |
1316 } | |
1317 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1318 { | |
1319 fprintf(stderr, "\tNONE flag\n"); | |
1320 } | |
1321 #endif | |
1322 return 0; | |
1323 } | |
1324 | |
1325 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
1326 /******* REMOVE ME ********************************/ | |
1327 /***************** ANOTHER EXPERIEMENT *******************/ | |
1328 /* The PROBLEM: It seems that the Loki distribution has problems | |
1329 * with Queuing when the buffer size is not a power of two | |
1330 * and additional buffers must come after it. | |
1331 * The behavior is inconsistent, but one of several things | |
1332 * usually happens: | |
1333 * Playback is normal | |
1334 * Playback immediately stops after the non-pow2 buffer | |
1335 * Playback gets distorted on the non-pow2 buffer | |
1336 * The entire program segfaults. | |
1337 * The workaround is to always specify a power of two buffer size | |
1338 * and hope that SDL_sound always fill it. (By lucky coincidence, | |
1339 * I already submitted the Ogg fix.) However, this won't catch | |
1340 * cases where a loop happens because the read at the end of the | |
1341 * file is typically less than the buffer size. | |
1342 * | |
1343 * This fix addresses this issue, however it may break in | |
1344 * other conditions. Always decode in buffer sizes of powers of 2. | |
1345 * | |
1346 * The HACK: | |
1347 * If the buffer is short, try filling it up with 0's | |
1348 * to meet the user requested buffer_size which | |
1349 * is probably a nice number OpenAL likes, in | |
1350 * hopes to avoid a possible Loki bug with | |
1351 * short buffers. If looping (which is the main | |
1352 * reason for this), the negative side effect is | |
1353 * that it may take longer for the loop to start | |
1354 * because it must play dead silence. Or if the decoder | |
1355 * doesn't guarantee to return the requested bytes | |
1356 * (like Ogg), then you will get breakup in between | |
1357 * packets. | |
1358 */ | |
1359 if( (bytes_decoded) < data->sample->buffer_size) | |
1360 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1361 ALubyte bit_depth; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1362 ALubyte signedness_value; |
0 | 1363 int silence_value; |
1364 /* Crap, memset value needs to be the "silent" value, | |
1365 * but it will differ for signed/unsigned and bit depth | |
1366 */ | |
1367 bit_depth = GetBitDepth(data->sample->desired.format); | |
1368 signedness_value = GetSignednessValue(data->sample->desired.format); | |
1369 if(ALMIXER_SIGNED_VALUE == signedness_value) | |
1370 { | |
1371 /* I'm guessing that if it's signed, then 0 is the | |
1372 * "silent" value */ | |
1373 silence_value = 0; | |
1374 } | |
1375 else | |
1376 { | |
1377 if(8 == bit_depth) | |
1378 { | |
1379 /* If 8 bit, I'm guessing it's (2^7)-1 = 127 */ | |
1380 silence_value = 127; | |
1381 } | |
1382 else | |
1383 { | |
1384 /* For 16 bit, I'm guessing it's (2^15)-1 = 32767 */ | |
1385 silence_value = 32767; | |
1386 } | |
1387 } | |
1388 /* Now fill up the rest of the data buffer with the | |
1389 * silence_value. | |
1390 * I don't think I have to worry about endian issues for | |
1391 * this part since the data is for internal use only | |
1392 * at this point. | |
1393 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1394 memset( &( ((ALbyte*)(data->sample->buffer))[bytes_decoded] ), silence_value, data->sample->buffer_size - bytes_decoded); |
0 | 1395 /* Now reset the bytes_decoded to reflect the entire |
1396 * buffer to tell alBufferData what our full size is. | |
1397 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1398 /* |
0 | 1399 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
|
1400 */ |
0 | 1401 bytes_decoded = data->sample->buffer_size; |
1402 } | |
1403 /*********** END EXPERIMENT ******************************/ | |
1404 /******* END REMOVE ME ********************************/ | |
1405 #endif | |
1406 | |
1407 /* Now copy the data to the OpenAL buffer */ | |
1408 /* We can't just set a pointer because the API needs | |
1409 * its own copy to assist hardware acceleration */ | |
1410 alBufferData(buffer, | |
1411 TranslateFormat(&data->sample->desired), | |
1412 data->sample->buffer, | |
1413 bytes_decoded, | |
1414 data->sample->desired.rate | |
1415 ); | |
1416 if( (error = alGetError()) != AL_NO_ERROR) | |
1417 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1418 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1419 return 0; |
1420 } | |
1421 | |
1422 /* If we need to, copy the data also to the access area | |
1423 * (the function will do the check for us) | |
1424 */ | |
1425 CopyDataToAccessBuffer(data, bytes_decoded, buffer); | |
1426 return bytes_decoded; | |
1427 } | |
1428 | |
1429 | |
1430 | |
1431 | |
1432 /******************** EXPERIEMENT **************************** | |
1433 * Test function to force maximum buffer filling during loops | |
1434 * REMOVE LATER | |
1435 *********************************************/ | |
1436 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1437 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
|
1438 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1439 ALint bytes_decoded; |
0 | 1440 ALenum error; |
1441 if(NULL == data) | |
1442 { | |
1443 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1444 return -1; | |
1445 } | |
1446 | |
1447 if(AL_FALSE == alIsBuffer(buffer)) | |
1448 { | |
1449 fprintf(stderr, "NOT A BUFFER>>>>>>>>>>>>>>>\n"); | |
1450 return -1; | |
1451 } | |
1452 fprintf(stderr, "Entered GetMoreData222222: buffer id is %d\n", buffer); | |
1453 | |
1454 /* | |
1455 fprintf(stderr, "Decode in GetMoreData\n"); | |
1456 */ | |
1457 | |
1458 #if 0 | |
1459 if(buffer%2 == 1) | |
1460 { | |
1461 fprintf(stderr, "Setting buffer size to 16384\n"); | |
1462 Sound_SetBufferSize(data->sample, 16384); | |
1463 } | |
1464 else | |
1465 { | |
1466 fprintf(stderr, "Setting buffer size to 8192\n"); | |
1467 Sound_SetBufferSize(data->sample, 8192); | |
1468 } | |
1469 #endif | |
1470 | |
1471 bytes_decoded = Sound_Decode(data->sample); | |
1472 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1473 { | |
1474 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1475 ALmixer_SetError(Sound_GetError()); | |
1476 /* | |
1477 Sound_FreeSample(data->sample); | |
1478 */ | |
1479 return -1; | |
1480 } | |
1481 /* Don't forget to add check for EOF */ | |
1482 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1483 if(0 == bytes_decoded) | |
1484 { | |
1485 #if 1 | |
1486 fprintf(stderr, "Hit eof while trying to buffer\n"); | |
1487 data->eof = 1; | |
1488 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1489 { | |
1490 fprintf(stderr, "\tEOF flag\n"); | |
1491 } | |
1492 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1493 { | |
1494 fprintf(stderr, "\tCanSeek flag\n"); | |
1495 } | |
1496 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1497 { | |
1498 fprintf(stderr, "\tEAGAIN flag\n"); | |
1499 } | |
1500 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1501 { | |
1502 fprintf(stderr, "\tNONE flag\n"); | |
1503 } | |
1504 #endif | |
1505 return 0; | |
1506 } | |
1507 | |
1508 if(bytes_decoded < 16384) | |
1509 { | |
1510 char* tempbuffer1 = (char*)malloc(16384); | |
1511 char* tempbuffer2 = (char*)malloc(16384); | |
1512 int retval; | |
1513 memcpy(tempbuffer1, data->sample->buffer, bytes_decoded); | |
1514 retval = Sound_SetBufferSize(data->sample, 16384-bytes_decoded); | |
1515 if(retval == 1) | |
1516 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1517 ALuint new_bytes; |
0 | 1518 Sound_Rewind(data->sample); |
1519 new_bytes = Sound_Decode(data->sample); | |
1520 fprintf(stderr, "Orig bytes: %d, Make up bytes_decoded=%d, total=%d\n", bytes_decoded, new_bytes, new_bytes+bytes_decoded); | |
1521 | |
1522 memcpy(tempbuffer2, data->sample->buffer, new_bytes); | |
1523 | |
1524 retval = Sound_SetBufferSize(data->sample, 16384); | |
1525 fprintf(stderr, "Finished reset...now danger copy\n"); | |
1526 memcpy(data->sample->buffer, tempbuffer1,bytes_decoded); | |
1527 | |
1528 fprintf(stderr, "Finished reset...now danger copy2\n"); | |
1529 memcpy( &( ((char*)(data->sample->buffer))[bytes_decoded] ), tempbuffer2, new_bytes); | |
1530 | |
1531 fprintf(stderr, "Finished \n"); | |
1532 | |
1533 free(tempbuffer1); | |
1534 free(tempbuffer2); | |
1535 bytes_decoded += new_bytes; | |
1536 fprintf(stderr, "ASSERT bytes should equal 16384: %d\n", bytes_decoded); | |
1537 } | |
1538 else | |
1539 { | |
1540 fprintf(stderr, "Experiment failed: %s\n", Sound_GetError()); | |
1541 } | |
1542 } | |
1543 | |
1544 /* Now copy the data to the OpenAL buffer */ | |
1545 /* We can't just set a pointer because the API needs | |
1546 * its own copy to assist hardware acceleration */ | |
1547 alBufferData(buffer, | |
1548 TranslateFormat(&data->sample->desired), | |
1549 data->sample->buffer, | |
1550 bytes_decoded, | |
1551 data->sample->desired.rate | |
1552 ); | |
1553 if( (error = alGetError()) != AL_NO_ERROR) | |
1554 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1555 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1556 return -1; |
1557 } | |
1558 | |
1559 fprintf(stderr, "GetMoreData2222 returning %d bytes decoded\n", bytes_decoded); | |
1560 return bytes_decoded; | |
1561 } | |
1562 #endif | |
1563 | |
1564 /************ END EXPERIEMENT - REMOVE ME *************************/ | |
1565 | |
1566 | |
1567 | |
1568 | |
1569 | |
1570 | |
1571 | |
1572 | |
1573 | |
1574 /* This function will look up the source for the corresponding channel */ | |
1575 /* 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
|
1576 static ALuint Internal_GetSource(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1577 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1578 ALint i; |
0 | 1579 /* Make sure channel is in bounds */ |
1580 if(channel >= Number_of_Channels_global) | |
1581 { | |
1582 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); | |
1583 return 0; | |
1584 } | |
1585 /* If the user specified -1, then return the an available source */ | |
1586 if(channel < 0) | |
1587 { | |
1588 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1589 { | |
1590 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1591 { | |
1592 return ALmixer_Channel_List[i].alsource; | |
1593 } | |
1594 } | |
1595 /* If we get here, all sources are in use */ | |
1596 /* Error message seems too harsh | |
1597 ALmixer_SetError("All sources are in use"); | |
1598 */ | |
1599 return 0; | |
1600 } | |
1601 /* Last case: Return the source for the channel */ | |
1602 return ALmixer_Channel_List[channel].alsource; | |
1603 } | |
1604 | |
1605 /* 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
|
1606 static ALint Internal_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1607 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1608 ALint i; |
0 | 1609 /* Only the first value is used for the key */ |
1610 Source_Map key = { 0, 0 }; | |
1611 Source_Map* found_item = NULL; | |
1612 key.source = source; | |
1613 | |
1614 /* If the source is 0, look up the first available channel */ | |
1615 if(0 == source) | |
1616 { | |
1617 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1618 { | |
1619 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1620 { | |
1621 return i; | |
1622 } | |
1623 } | |
1624 /* If we get here, all sources are in use */ | |
1625 /* Error message seems too harsh | |
1626 ALmixer_SetError("All channels are in use"); | |
1627 */ | |
1628 return -1; | |
1629 } | |
1630 | |
1631 | |
1632 /* Else, look up the source and return the channel */ | |
1633 if(AL_FALSE == alIsSource(source)) | |
1634 { | |
1635 ALmixer_SetError("Is not a source"); | |
1636 return -1; | |
1637 } | |
1638 | |
1639 /* Use the ANSI C binary search feature (yea!) */ | |
1640 found_item = (Source_Map*)bsearch(&key, Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
1641 if(NULL == found_item) | |
1642 { | |
1643 ALmixer_SetError("Source is valid but not registered with ALmixer (to a channel)"); | |
1644 return -1; | |
1645 } | |
1646 return found_item->channel; | |
1647 } | |
1648 | |
1649 | |
1650 | |
1651 /* This function will find the first available channel (not in use) | |
1652 * from the specified start channel. Reserved channels to not qualify | |
1653 * as available. | |
1654 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1655 static ALint Internal_FindFreeChannel(ALint start_channel) |
0 | 1656 { |
1657 /* Start at the number of reserved so we skip over | |
1658 * all the reserved channels. | |
1659 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1660 ALint i = Number_of_Reserve_Channels_global; |
0 | 1661 /* Quick check to see if we're out of bounds */ |
1662 if(start_channel >= Number_of_Channels_global) | |
1663 { | |
1664 return -1; | |
1665 } | |
1666 | |
1667 /* If the start channel is even higher than the reserved, | |
1668 * then start at the higher value. | |
1669 */ | |
1670 if(start_channel > Number_of_Reserve_Channels_global) | |
1671 { | |
1672 i = start_channel; | |
1673 } | |
1674 | |
1675 /* i has already been set */ | |
1676 for( ; i<Number_of_Channels_global; i++) | |
1677 { | |
1678 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1679 { | |
1680 return i; | |
1681 } | |
1682 } | |
1683 /* If we get here, all sources are in use */ | |
1684 return -1; | |
1685 } | |
1686 | |
1687 | |
1688 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1689 /* 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
|
1690 * or 0 for error |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1691 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1692 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
|
1693 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1694 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1695 ALint counter = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1696 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1697 ALint buffers_still_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1698 ALint buffers_processed; |
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(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1701 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1702 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
|
1703 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1704 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1705 /* 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
|
1706 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1707 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1708 /* 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
|
1709 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
|
1710 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1711 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1712 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1713 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1714 fprintf(stderr, "14Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1715 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1716 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1717 /* 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
|
1718 * 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
|
1719 * 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
|
1720 * 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
|
1721 * 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
|
1722 * 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
|
1723 * 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
|
1724 * 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
|
1725 * 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
|
1726 * 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
|
1727 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1728 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1729 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1730 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1731 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1732 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1733 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1734 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1735 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
|
1736 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1737 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
|
1738 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1739 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1740 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1741 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1742 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1743 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1744 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1745 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1746 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1747 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
|
1748 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1749 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
|
1750 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1751 retval = -1; |
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 /* 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
|
1754 * to clear the source |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1755 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1756 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
|
1757 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1758 alSourcei(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1759 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1760 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1761 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1762 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1763 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
|
1764 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1765 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
|
1766 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1767 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1768 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1769 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1770 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1771 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
|
1772 |
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
|
1773 /* 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
|
1774 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
|
1775 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1776 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1777 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1778 counter++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1779 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1780 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1781 /* 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
|
1782 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1783 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1784 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1785 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
|
1786 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1787 /* 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
|
1788 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
|
1789 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1790 alSourceStop(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1791 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1792 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1793 fprintf(stderr, "19Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1794 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1795 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1796 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1797 /* 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
|
1798 * 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
|
1799 * 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
|
1800 * 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
|
1801 * 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
|
1802 * 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
|
1803 * 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
|
1804 * 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
|
1805 * 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
|
1806 * 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
|
1807 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1808 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1809 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1810 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1811 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1812 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1813 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1814 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1815 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
|
1816 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1817 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
|
1818 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1819 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1820 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1821 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1822 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1823 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1824 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1825 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1826 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1827 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
|
1828 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1829 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
|
1830 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1831 retval = -1; |
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 /* 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
|
1834 * to clear the source |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1835 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1836 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
|
1837 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1838 alSourcei(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1839 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1840 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1841 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1842 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1843 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
|
1844 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1845 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
|
1846 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1847 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1848 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1849 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1850 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1851 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
|
1852 |
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
|
1853 /* 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
|
1854 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
|
1855 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1856 Clean_Channel(i); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1857 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1858 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1859 /* Increment the counter */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1860 counter++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1861 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1862 /* 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
|
1863 * are bugs. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1864 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1865 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1866 else |
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 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1869 / * 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
|
1870 * data will get messed up * / |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1871 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1872 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1873 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1874 /* Just in case */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1875 Is_Playing_global = 0; |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1878 if(-1 == retval) |
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 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1881 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1882 return counter; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1883 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1884 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1885 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1886 /* 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
|
1887 * 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
|
1888 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1889 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
|
1890 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1891 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1892 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1893 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1894 /* 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
|
1895 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
|
1896 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1897 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1898 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1899 if(-1 == channel) |
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 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
|
1902 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1903 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1904 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
|
1905 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1906 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1907 |
0 | 1908 |
1909 /* Note: Behaves, almost like SDL_mixer, but keep in mind | |
1910 * that there is no "music" channel anymore, so 0 | |
1911 * will remove everything. (Note, I no longer allow 0 | |
1912 * so it gets set to the default number.) | |
1913 * Also, callbacks for deleted channels will not be called. | |
1914 * I really need to do error checking, for realloc and | |
1915 * GenSources, but reversing the damage is too painful | |
1916 * for me to think about at the moment, so it's not in here. | |
1917 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1918 static ALint Internal_AllocateChannels(ALint numchans) |
0 | 1919 { |
1920 ALenum error; | |
1921 int i; | |
1922 /* Return info */ | |
1923 if(numchans < 0) | |
1924 { | |
1925 return Number_of_Channels_global; | |
1926 } | |
1927 if(0 == numchans) | |
1928 { | |
1929 numchans = ALMIXER_DEFAULT_NUM_CHANNELS; | |
1930 } | |
1931 /* No change */ | |
1932 if(numchans == Number_of_Channels_global) | |
1933 { | |
1934 return Number_of_Channels_global; | |
1935 } | |
1936 /* We need to increase the number of channels */ | |
1937 if(numchans > Number_of_Channels_global) | |
1938 { | |
1939 /* Not sure how safe this is, but SDL_mixer does it | |
1940 * the same way */ | |
1941 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1942 | |
1943 /* Allocate memory for the list of sources that map to the channels */ | |
1944 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
1945 | |
1946 for(i=Number_of_Channels_global; i<numchans; i++) | |
1947 { | |
1948 Init_Channel(i); | |
1949 /* Generate a new source and associate it with the channel */ | |
1950 alGenSources(1, &ALmixer_Channel_List[i].alsource); | |
1951 if((error = alGetError()) != AL_NO_ERROR) | |
1952 { | |
1953 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
|
1954 alGetString(error)); |
0 | 1955 } |
1956 /* Copy the source so the SourceMap has it too */ | |
1957 Source_Map_List[i].source = ALmixer_Channel_List[i].alsource; | |
1958 Source_Map_List[i].channel = i; | |
1959 /* Clean the channel because there are some things that need to | |
1960 * be done that can't happen until the source is set | |
1961 */ | |
1962 Clean_Channel(i); | |
1963 } | |
1964 | |
1965 /* The Source_Map_List must be sorted by source for binary searches | |
1966 */ | |
1967 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
1968 | |
1969 Number_of_Channels_global = numchans; | |
1970 return numchans; | |
1971 } | |
1972 /* Need to remove channels. This might be dangerous */ | |
1973 if(numchans < Number_of_Channels_global) | |
1974 { | |
1975 for(i=numchans; i<Number_of_Channels_global; i++) | |
1976 { | |
1977 /* Halt the channel */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1978 Internal_HaltChannel(i, AL_FALSE); |
0 | 1979 |
1980 /* Delete source associated with the channel */ | |
1981 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
1982 if((error = alGetError()) != AL_NO_ERROR) | |
1983 { | |
1984 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
|
1985 alGetString(error)); |
0 | 1986 } |
1987 } | |
1988 | |
1989 | |
1990 /* Not sure how safe this is, but SDL_mixer does it | |
1991 * the same way */ | |
1992 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1993 | |
1994 /* The tricky part is that we must remove the entries | |
1995 * in the source map that correspond to the deleted channels. | |
1996 * We'll resort the map by channels so we can pick them off | |
1997 * in order. | |
1998 */ | |
1999 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map_by_channel); | |
2000 | |
2001 /* Deallocate memory for the list of sources that map to the channels */ | |
2002 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
2003 | |
2004 /* Now resort the map by source and the correct num of chans */ | |
2005 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
2006 | |
2007 /* Reset the number of channels */ | |
2008 Number_of_Channels_global = numchans; | |
2009 return numchans; | |
2010 } | |
2011 /* Shouldn't ever reach here */ | |
2012 return -1; | |
2013 | |
2014 } | |
2015 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2016 static ALint Internal_ReserveChannels(ALint num) |
0 | 2017 { |
2018 /* Can't reserve more than the max num of channels */ | |
2019 /* Actually, I'll allow it for people who just want to | |
2020 * set the value really high to effectively disable | |
2021 * auto-assignment | |
2022 */ | |
2023 | |
2024 /* Return the current number of reserved channels */ | |
2025 if(num < 0) | |
2026 { | |
2027 return Number_of_Reserve_Channels_global; | |
2028 } | |
2029 Number_of_Reserve_Channels_global = num; | |
2030 return Number_of_Reserve_Channels_global; | |
2031 } | |
2032 | |
2033 | |
2034 /* This will rewind the SDL_Sound sample for streamed | |
2035 * samples and start buffering up the data for the next | |
2036 * playback. This may require samples to be halted | |
2037 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2038 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
|
2039 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2040 ALint retval = 0; |
0 | 2041 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2042 ALint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2043 ALint i; |
0 | 2044 */ |
2045 if(NULL == data) | |
2046 { | |
2047 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
|
2048 return AL_FALSE; |
0 | 2049 } |
2050 | |
2051 | |
2052 /* Might have to require Halt */ | |
2053 /* Okay, we assume Halt or natural stop has already | |
2054 * cleared the data buffers | |
2055 */ | |
2056 if(data->in_use) | |
2057 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2058 /* |
0 | 2059 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
|
2060 */ |
0 | 2061 /* |
2062 ALmixer_SetError("Data is in use. Cannot rewind unless all sources using the data are halted\n"); | |
2063 return -1; | |
2064 */ | |
2065 } | |
2066 | |
2067 | |
2068 /* Because Seek can alter things even in predecoded data, | |
2069 * decoded data must also be rewound | |
2070 */ | |
2071 if(data->decoded_all) | |
2072 { | |
2073 data->eof = 0; | |
2074 | |
2075 #if 0 | |
2076 #if defined(DISABLE_PREDECODED_SEEK) | |
2077 /* 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
|
2078 return AL_TRUE; |
0 | 2079 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) |
2080 /* This case is if the Sound_Sample has been deleted. | |
2081 * It assumes the data is already at the beginning. | |
2082 */ | |
2083 if(NULL == data->sample) | |
2084 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2085 return AL_TRUE; |
0 | 2086 } |
2087 /* Else, the sample has already been reallocated, | |
2088 * and we can fall to normal behavior | |
2089 */ | |
2090 #endif | |
2091 #endif | |
2092 /* If access_data, was enabled, the sound sample | |
2093 * still exists and we can do stuff. | |
2094 * If it's NULL, we can't do anything, but | |
2095 * it should already be "rewound". | |
2096 */ | |
2097 if(NULL == data->sample) | |
2098 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2099 return AL_TRUE; |
0 | 2100 } |
2101 /* Else, the sample has already been reallocated, | |
2102 * and we can fall to normal behavior | |
2103 */ | |
2104 | |
2105 Set_Predecoded_Seek_Position(data, 0); | |
2106 /* | |
2107 return data->total_bytes; | |
2108 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2109 return AL_TRUE; |
0 | 2110 } |
2111 | |
2112 /* Remaining stuff for streamed data */ | |
2113 | |
2114 data->eof = 0; | |
2115 retval = Sound_Rewind(data->sample); | |
2116 if(0 == retval) | |
2117 { | |
2118 ALmixer_SetError( Sound_GetError() ); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2119 return AL_FALSE; |
0 | 2120 } |
2121 #if 0 | |
2122 /* Clear error */ | |
2123 alGetError(); | |
2124 for(i=0; i<data->num_buffers; i++) | |
2125 { | |
2126 bytes_returned = GetMoreData(data, data->buffer[i]); | |
2127 if(-1 == bytes_returned) | |
2128 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2129 return AL_FALSE; |
0 | 2130 } |
2131 else if(0 == bytes_returned) | |
2132 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2133 return AL_FALSE; |
0 | 2134 } |
2135 retval += bytes_returned; | |
2136 | |
2137 } | |
2138 #endif | |
2139 | |
2140 | |
2141 | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2142 return AL_TRUE; |
0 | 2143 } |
2144 | |
2145 | |
2146 | |
2147 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2148 static ALint Internal_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2149 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2150 ALint retval = 0; |
0 | 2151 ALenum error; |
2152 ALint state; | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2153 ALint running_count = 0; |
0 | 2154 |
2155 if(channel >= Number_of_Channels_global) | |
2156 { | |
2157 ALmixer_SetError("Cannot rewind channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2158 return -1; | |
2159 } | |
2160 | |
2161 if((error = alGetError()) != AL_NO_ERROR) | |
2162 { | |
2163 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
|
2164 alGetString(error)); |
0 | 2165 } |
2166 /* Clear error */ | |
2167 alGetError(); | |
2168 | |
2169 /* If the user specified a specific channel */ | |
2170 if(channel >= 0) | |
2171 { | |
2172 /* only need to process channel if in use */ | |
2173 if(ALmixer_Channel_List[channel].channel_in_use) | |
2174 { | |
2175 | |
2176 /* What should I do? Do I just rewind the channel | |
2177 * or also rewind the data? Since the data is | |
2178 * shared, let's make it the user's responsibility | |
2179 * to rewind the data. | |
2180 */ | |
2181 if(ALmixer_Channel_List[channel].almixer_data->decoded_all) | |
2182 { | |
2183 alGetSourcei( | |
2184 ALmixer_Channel_List[channel].alsource, | |
2185 AL_SOURCE_STATE, &state | |
2186 ); | |
2187 if((error = alGetError()) != AL_NO_ERROR) | |
2188 { | |
2189 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
|
2190 alGetString(error)); |
0 | 2191 } |
2192 alSourceRewind(ALmixer_Channel_List[channel].alsource); | |
2193 if((error = alGetError()) != AL_NO_ERROR) | |
2194 { | |
2195 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2196 alGetString(error) ); |
0 | 2197 retval = -1; |
2198 } | |
2199 /* Need to resume playback if it was originally playing */ | |
2200 if(AL_PLAYING == state) | |
2201 { | |
2202 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2203 if((error = alGetError()) != AL_NO_ERROR) | |
2204 { | |
2205 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2206 alGetString(error) ); |
0 | 2207 retval = -1; |
2208 } | |
2209 } | |
2210 else if(AL_PAUSED == state) | |
2211 { | |
2212 /* HACK: The problem is that when paused, after | |
2213 * the Rewind, I can't get it off the INITIAL | |
2214 * state without restarting | |
2215 */ | |
2216 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2217 if((error = alGetError()) != AL_NO_ERROR) | |
2218 { | |
2219 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
|
2220 alGetString(error)); |
0 | 2221 } |
2222 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2223 if((error = alGetError()) != AL_NO_ERROR) | |
2224 { | |
2225 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2226 alGetString(error) ); |
0 | 2227 retval = -1; |
2228 } | |
2229 } | |
2230 } | |
2231 else | |
2232 { | |
2233 /* Streamed data is different. Rewinding the channel | |
2234 * does no good. Rewinding the data will have an | |
2235 * effect, but it will be lagged based on how | |
2236 * much data is queued. Recommend users call Halt | |
2237 * before rewind if they want immediate results. | |
2238 */ | |
2239 retval = Internal_RewindData(ALmixer_Channel_List[channel].almixer_data); | |
2240 } | |
2241 } | |
2242 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2243 /* The user wants to rewind all channels */ |
0 | 2244 else |
2245 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2246 ALint i; |
0 | 2247 for(i=0; i<Number_of_Channels_global; i++) |
2248 { | |
2249 /* only need to process channel if in use */ | |
2250 if(ALmixer_Channel_List[i].channel_in_use) | |
2251 { | |
2252 /* What should I do? Do I just rewind the channel | |
2253 * or also rewind the data? Since the data is | |
2254 * shared, let's make it the user's responsibility | |
2255 * to rewind the data. | |
2256 */ | |
2257 if(ALmixer_Channel_List[i].almixer_data->decoded_all) | |
2258 { | |
2259 alGetSourcei( | |
2260 ALmixer_Channel_List[i].alsource, | |
2261 AL_SOURCE_STATE, &state | |
2262 ); | |
2263 if((error = alGetError()) != AL_NO_ERROR) | |
2264 { | |
2265 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
|
2266 alGetString(error)); |
0 | 2267 } |
2268 alSourceRewind(ALmixer_Channel_List[i].alsource); | |
2269 if((error = alGetError()) != AL_NO_ERROR) | |
2270 { | |
2271 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2272 alGetString(error) ); |
0 | 2273 retval = -1; |
2274 } | |
2275 /* Need to resume playback if it was originally playing */ | |
2276 if(AL_PLAYING == state) | |
2277 { | |
2278 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2279 if((error = alGetError()) != AL_NO_ERROR) | |
2280 { | |
2281 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2282 alGetString(error) ); |
0 | 2283 retval = -1; |
2284 } | |
2285 } | |
2286 else if(AL_PAUSED == state) | |
2287 { | |
2288 /* HACK: The problem is that when paused, after | |
2289 * the Rewind, I can't get it off the INITIAL | |
2290 * state without restarting | |
2291 */ | |
2292 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2293 if((error = alGetError()) != AL_NO_ERROR) | |
2294 { | |
2295 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
|
2296 alGetString(error)); |
0 | 2297 } |
2298 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2299 if((error = alGetError()) != AL_NO_ERROR) | |
2300 { | |
2301 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2302 alGetString(error) ); |
0 | 2303 retval = -1; |
2304 } | |
2305 } | |
2306 } | |
2307 else | |
2308 { | |
2309 /* Streamed data is different. Rewinding the channel | |
2310 * does no good. Rewinding the data will have an | |
2311 * effect, but it will be lagged based on how | |
2312 * much data is queued. Recommend users call Halt | |
2313 * before rewind if they want immediate results. | |
2314 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2315 running_count += Internal_RewindData(ALmixer_Channel_List[i].almixer_data); |
0 | 2316 } |
2317 } | |
2318 } | |
2319 } | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2320 if(-1 == retval) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2321 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2322 return -1; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2323 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2324 else |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2325 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2326 return running_count; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2327 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2328 |
0 | 2329 } |
2330 | |
2331 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2332 static ALint Internal_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2333 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2334 ALint channel; |
0 | 2335 if(0 == source) |
2336 { | |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
2337 return Internal_RewindChannel(-1); |
0 | 2338 } |
2339 | |
2340 channel = Internal_GetChannel(source); | |
2341 if(-1 == channel) | |
2342 { | |
2343 ALmixer_SetError("Cannot rewind source: %s", ALmixer_GetError()); | |
2344 return 0; | |
2345 } | |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
2346 return Internal_RewindChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2347 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2348 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2349 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2350 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2351 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2352 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2353 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
|
2354 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2355 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2356 int ret_flag = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2357 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2358 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2359 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
|
2360 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2361 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2362 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2363 /* 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
|
2364 * 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
|
2365 * 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
|
2366 * 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
|
2367 * 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
|
2368 * to prevent sharing |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2369 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2370 if(0 == data->decoded_all) |
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 if(data->in_use) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2373 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2374 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
|
2375 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2376 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2377 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2378 /* 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
|
2379 * This mainly affects streamed files, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2380 * so the check is placed here |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2381 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2382 if(data->eof) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2383 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2384 if( -1 == Internal_RewindData(data) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2385 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2386 ALmixer_SetError("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
|
2387 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2388 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2389 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2390 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2391 /* 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
|
2392 if(-1 == channel) |
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 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2395 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
|
2396 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2397 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
|
2398 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2399 channel = i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2400 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2401 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2402 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2403 /* 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
|
2404 if(i == Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2405 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2406 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
|
2407 return -1; |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2410 /* 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
|
2411 * out of bounds or in use */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2412 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2413 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2414 if(channel >= Number_of_Channels_global) |
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) 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
|
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 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
|
2420 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2421 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
|
2422 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2423 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2424 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2425 /* 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
|
2426 if(loops < -1) |
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 loops = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2429 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2430 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2431 /* 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
|
2432 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2433 /* 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
|
2434 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
|
2435 data->in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2436 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2437 /* 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
|
2438 * (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
|
2439 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2440 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
|
2441 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
|
2442 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
|
2443 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2444 /* 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
|
2445 if(ticks < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2446 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2447 ALmixer_Channel_List[channel].expire_ticks = -1; |
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2450 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2451 ALmixer_Channel_List[channel].expire_ticks = ticks; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2454 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2455 ALmixer_Channel_List[channel].halted = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2456 ALmixer_Channel_List[channel].paused = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2457 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2458 /* 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
|
2459 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2460 if( (-1 == loops) && (data->decoded_all) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2461 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2462 alSourcei(ALmixer_Channel_List[channel].alsource, AL_LOOPING, AL_TRUE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2463 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2464 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2465 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2466 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
|
2467 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2468 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2469 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2470 fprintf(stderr, "13Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2471 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2472 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2473 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2474 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2475 /* Because of the corner case, predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2476 * 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
|
2477 * Streams do not have this problem |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2478 * 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
|
2479 * avoid the conflict. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2480 * 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
|
2481 * Since streams, cannot share, only predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2482 * files are affected |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2483 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2484 if(data->decoded_all) |
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 /* 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
|
2487 * 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
|
2488 * 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
|
2489 * must be +1 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2490 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2491 if(-1 == loops) |
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 /* -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
|
2494 * to add +1 to it */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2495 ALmixer_Channel_List[channel].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_TRUE); |
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2499 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2500 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
|
2501 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
|
2502 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2503 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2504 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2505 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2506 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2507 /* 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
|
2508 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
|
2509 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2510 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2511 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2512 /* 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
|
2513 /* 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
|
2514 * 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
|
2515 * 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
|
2516 * 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
|
2517 * 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
|
2518 * 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
|
2519 * easier to maintain. |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2522 /* Clear the error flag */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2523 alGetError(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2524 if(data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2525 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2526 /* Bind the data to the source */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2527 alSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2528 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2529 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2530 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2531 if((error = alGetError()) != AL_NO_ERROR) |
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 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
|
2534 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2535 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2536 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2537 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2538 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2539 /* 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
|
2540 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
|
2541 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2542 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2543 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2544 /* 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
|
2545 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2546 ALuint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2547 ALuint j; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2548 data->num_buffers_in_use=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2549 /****** MODIFICATION must go here *********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2550 /* 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
|
2551 * 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
|
2552 * 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
|
2553 * 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
|
2554 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2555 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2556 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2557 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2558 if(0 == bytes_returned) |
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 /* No data or error */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2561 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
|
2562 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2563 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2564 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2565 /* 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
|
2566 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2567 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2568 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2569 /* 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
|
2570 * 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
|
2571 * before the last buffer is filled. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2572 * 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
|
2573 * 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
|
2574 */ |
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", 0, data->buffer[0]); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2578 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2579 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
|
2580 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2581 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2582 fprintf(stderr, "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
|
2583 fprintf(stderr, ">>>>>>>>>>>>>>>>>>HACK for GetMoreData2\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2584 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2585 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2586 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2587 data->buffer[j]); |
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 * 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
|
2590 * 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
|
2591 * 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
|
2592 * 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
|
2593 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2594 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2595 if(bytes_returned < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2596 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2597 /* Error found */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2598 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
|
2599 /* 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
|
2600 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2601 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2602 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2603 else if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2604 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2605 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2606 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2607 /* No more data to buffer */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2608 /* Check for loops */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2609 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
|
2610 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2611 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2612 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
|
2613 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2614 if(0 == Sound_Rewind(data->sample)) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2615 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2616 fprintf(stderr, "error in rewind\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2617 ALmixer_SetError( Sound_GetError() ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2618 ALmixer_Channel_List[channel].loops = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2619 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2620 /* 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
|
2621 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2622 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2623 /* 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
|
2624 data->eof = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2625 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
|
2626 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2627 ALmixer_Channel_List[channel].loops--; |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2628 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2629 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
|
2630 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2631 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2632 /* 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
|
2633 * 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
|
2634 * into an infinite loop |
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 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2637 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2638 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2639 if(bytes_returned <= 0) |
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 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
|
2642 /* 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
|
2643 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2644 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2645 } |
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2648 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2649 /* 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
|
2650 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2651 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2652 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2653 /* 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
|
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 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
|
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 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2661 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2662 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2663 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2664 data->num_buffers_in_use, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2665 data->buffer); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2666 if((error = alGetError()) != AL_NO_ERROR) |
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 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
|
2669 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2670 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2671 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2672 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2673 /* 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
|
2674 * 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
|
2675 * 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
|
2676 * 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
|
2677 * "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
|
2678 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2679 if(data->circular_buffer_queue != NULL) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2680 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2681 ALuint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2682 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2683 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
|
2684 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2685 // fprintf(stderr, "56c: CircularQueue_PushBack.\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2686 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
|
2687 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2688 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2689 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
|
2690 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
|
2691 } |
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 else |
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 fprintf(stderr, "Queue in PlayTimed\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2696 CircularQueueUnsignedInt_Print(data->circular_buffer_queue); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2697 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2698 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2699 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2700 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2701 |
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 /****** END **********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2704 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2705 /* 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
|
2706 * so now we can play |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2707 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2708 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2709 if((error = alGetError()) != AL_NO_ERROR) |
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 ALmixer_SetError("Play failed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2712 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2713 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2714 return -1; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2717 /* 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
|
2718 Is_Playing_global++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2719 if(-1 == ret_flag) |
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 fprintf(stderr, "BACKDOOR ERROR >>>>>>>>>>>>>>>>>>\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2722 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2723 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2724 return channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2725 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2726 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2727 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2728 /* 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
|
2729 * 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
|
2730 * 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
|
2731 * PlayChannelTimed() function call. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2732 * 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
|
2733 * 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
|
2734 * 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
|
2735 * 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
|
2736 * 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
|
2737 * 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
|
2738 * 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
|
2739 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2740 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
|
2741 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2742 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2743 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2744 if(0 == source) |
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 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
|
2747 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2748 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2749 return 0; |
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2752 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2753 return Internal_GetSource(retval); |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2756 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2757 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2758 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2759 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2760 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
|
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 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
|
2764 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2765 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2766 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2767 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2768 else |
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 return source; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2771 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2772 /* make compiler happy */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2773 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2774 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2775 |
0 | 2776 |
2777 | |
2778 | |
2779 /* Returns the channel or number of channels actually paused */ | |
2780 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2781 static ALint Internal_PauseChannel(ALint channel) |
0 | 2782 { |
2783 ALenum error; | |
2784 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2785 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2786 ALint counter = 0; |
0 | 2787 |
2788 if(channel >= Number_of_Channels_global) | |
2789 { | |
2790 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2791 return -1; | |
2792 } | |
2793 | |
2794 if((error = alGetError()) != AL_NO_ERROR) | |
2795 { | |
2796 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
|
2797 alGetString(error)); |
0 | 2798 } |
2799 /* Clear error */ | |
2800 alGetError(); | |
2801 | |
2802 /* If the user specified a specific channel */ | |
2803 if(channel >= 0) | |
2804 { | |
2805 /* only need to process channel if in use */ | |
2806 if(ALmixer_Channel_List[channel].channel_in_use) | |
2807 { | |
2808 /* We don't want to repause if already | |
2809 * paused because the fadeout/expire | |
2810 * timing will get messed up | |
2811 */ | |
2812 alGetSourcei( | |
2813 ALmixer_Channel_List[channel].alsource, | |
2814 AL_SOURCE_STATE, &state | |
2815 ); | |
2816 if((error = alGetError()) != AL_NO_ERROR) | |
2817 { | |
2818 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
|
2819 alGetString(error)); |
0 | 2820 } |
2821 if(AL_PLAYING == state) | |
2822 { | |
2823 /* Count the actual number of channels being paused */ | |
2824 counter++; | |
2825 | |
2826 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2827 if((error = alGetError()) != AL_NO_ERROR) | |
2828 { | |
2829 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2830 alGetString(error) ); |
0 | 2831 retval = -1; |
2832 } | |
2833 /* We need to pause the expire time count down */ | |
2834 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
2835 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2836 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2837 ALuint diff_time; |
0 | 2838 diff_time = current_time - |
2839 ALmixer_Channel_List[channel].start_time; | |
2840 /* When we unpause, we will want to reset | |
2841 * the start time so we can continue | |
2842 * to base calculations off GetTicks(). | |
2843 * This means we need to subtract the amount | |
2844 * of time already used up from expire_ticks. | |
2845 */ | |
2846 ALmixer_Channel_List[channel].expire_ticks = | |
2847 ALmixer_Channel_List[channel].expire_ticks - | |
2848 diff_time; | |
2849 /* Because -1 is a special value, we can't | |
2850 * allow the time to go negative | |
2851 */ | |
2852 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2853 { | |
2854 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2855 } | |
2856 } | |
2857 /* Do the same as expire time for fading */ | |
2858 if(ALmixer_Channel_List[channel].fade_enabled) | |
2859 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2860 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2861 ALuint diff_time; |
0 | 2862 diff_time = current_time - |
2863 ALmixer_Channel_List[channel].fade_start_time; | |
2864 /* When we unpause, we will want to reset | |
2865 * the start time so we can continue | |
2866 * to base calculations off GetTicks(). | |
2867 * This means we need to subtract the amount | |
2868 * of time already used up from expire_ticks. | |
2869 */ | |
2870 ALmixer_Channel_List[channel].fade_expire_ticks = | |
2871 ALmixer_Channel_List[channel].fade_expire_ticks - | |
2872 diff_time; | |
2873 /* Don't allow the time to go negative */ | |
2874 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2875 { | |
2876 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2877 } | |
2878 } /* End fade check */ | |
2879 } /* End if PLAYING */ | |
2880 } /* End If in use */ | |
2881 } /* End specific channel */ | |
2882 /* The user wants to halt all channels */ | |
2883 else | |
2884 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2885 ALint i; |
0 | 2886 for(i=0; i<Number_of_Channels_global; i++) |
2887 { | |
2888 /* only need to process channel if in use */ | |
2889 if(ALmixer_Channel_List[i].channel_in_use) | |
2890 { | |
2891 /* We don't want to repause if already | |
2892 * paused because the fadeout/expire | |
2893 * timing will get messed up | |
2894 */ | |
2895 alGetSourcei( | |
2896 ALmixer_Channel_List[i].alsource, | |
2897 AL_SOURCE_STATE, &state | |
2898 ); | |
2899 if((error = alGetError()) != AL_NO_ERROR) | |
2900 { | |
2901 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
|
2902 alGetString(error)); |
0 | 2903 } |
2904 if(AL_PLAYING == state) | |
2905 { | |
2906 /* Count the actual number of channels being paused */ | |
2907 counter++; | |
2908 | |
2909 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2910 if((error = alGetError()) != AL_NO_ERROR) | |
2911 { | |
2912 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2913 alGetString(error) ); |
0 | 2914 retval = -1; |
2915 } | |
2916 /* We need to pause the expire time count down */ | |
2917 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
2918 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2919 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2920 ALuint diff_time; |
0 | 2921 diff_time = current_time - |
2922 ALmixer_Channel_List[i].start_time; | |
2923 /* When we unpause, we will want to reset | |
2924 * the start time so we can continue | |
2925 * to base calculations off GetTicks(). | |
2926 * This means we need to subtract the amount | |
2927 * of time already used up from expire_ticks. | |
2928 */ | |
2929 ALmixer_Channel_List[i].expire_ticks = | |
2930 ALmixer_Channel_List[i].expire_ticks - | |
2931 diff_time; | |
2932 /* Because -1 is a special value, we can't | |
2933 * allow the time to go negative | |
2934 */ | |
2935 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2936 { | |
2937 ALmixer_Channel_List[i].expire_ticks = 0; | |
2938 } | |
2939 } | |
2940 /* Do the same as expire time for fading */ | |
2941 if(ALmixer_Channel_List[i].fade_enabled) | |
2942 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2943 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2944 ALuint diff_time; |
0 | 2945 diff_time = current_time - |
2946 ALmixer_Channel_List[i].fade_start_time; | |
2947 /* When we unpause, we will want to reset | |
2948 * the start time so we can continue | |
2949 * to base calculations off GetTicks(). | |
2950 * This means we need to subtract the amount | |
2951 * of time already used up from expire_ticks. | |
2952 */ | |
2953 ALmixer_Channel_List[i].fade_expire_ticks = | |
2954 ALmixer_Channel_List[i].fade_expire_ticks - | |
2955 diff_time; | |
2956 /* Don't allow the time to go negative */ | |
2957 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2958 { | |
2959 ALmixer_Channel_List[i].expire_ticks = 0; | |
2960 } | |
2961 } /* End fade check */ | |
2962 } /* End if PLAYING */ | |
2963 } /* End channel in use */ | |
2964 } /* End for-loop */ | |
2965 } | |
2966 if(-1 == retval) | |
2967 { | |
2968 return -1; | |
2969 } | |
2970 return counter; | |
2971 } | |
2972 | |
2973 /* 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
|
2974 static ALint Internal_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2975 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2976 ALint channel; |
0 | 2977 if(0 == source) |
2978 { | |
2979 return Internal_PauseChannel(-1); | |
2980 } | |
2981 | |
2982 channel = Internal_GetChannel(source); | |
2983 if(-1 == channel) | |
2984 { | |
2985 ALmixer_SetError("Cannot pause source: %s", ALmixer_GetError()); | |
2986 return -1; | |
2987 } | |
2988 return Internal_PauseChannel(channel); | |
2989 } | |
2990 | |
2991 | |
2992 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2993 static ALint Internal_ResumeChannel(ALint channel) |
0 | 2994 { |
2995 ALint state; | |
2996 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2997 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2998 ALint counter = 0; |
0 | 2999 |
3000 if(channel >= Number_of_Channels_global) | |
3001 { | |
3002 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
3003 return -1; | |
3004 } | |
3005 | |
3006 if((error = alGetError()) != AL_NO_ERROR) | |
3007 { | |
3008 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
|
3009 alGetString(error)); |
0 | 3010 } |
3011 /* Clear error */ | |
3012 alGetError(); | |
3013 | |
3014 /* If the user specified a specific channel */ | |
3015 if(channel >= 0) | |
3016 { | |
3017 /* only need to process channel if in use */ | |
3018 if(ALmixer_Channel_List[channel].channel_in_use) | |
3019 { | |
3020 alGetSourcei( | |
3021 ALmixer_Channel_List[channel].alsource, | |
3022 AL_SOURCE_STATE, &state | |
3023 ); | |
3024 if((error = alGetError()) != AL_NO_ERROR) | |
3025 { | |
3026 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
|
3027 alGetString(error)); |
0 | 3028 } |
3029 if(AL_PAUSED == state) | |
3030 { | |
3031 /* Count the actual number of channels resumed */ | |
3032 counter++; | |
3033 | |
3034 /* We need to resume the expire time count down */ | |
3035 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
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].start_time = ALmixer_GetTicks(); |
0 | 3038 } |
3039 /* Do the same as expire time for fading */ | |
3040 if(ALmixer_Channel_List[channel].fade_enabled) | |
3041 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3042 ALmixer_Channel_List[channel].fade_start_time = ALmixer_GetTicks(); |
0 | 3043 } |
3044 | |
3045 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
3046 if((error = alGetError()) != AL_NO_ERROR) | |
3047 { | |
3048 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3049 alGetString(error) ); |
0 | 3050 retval = -1; |
3051 } | |
3052 } | |
3053 } | |
3054 } | |
3055 /* The user wants to halt all channels */ | |
3056 else | |
3057 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3058 ALint i; |
0 | 3059 for(i=0; i<Number_of_Channels_global; i++) |
3060 { | |
3061 /* only need to process channel if in use */ | |
3062 if(ALmixer_Channel_List[i].channel_in_use) | |
3063 { | |
3064 alGetSourcei( | |
3065 ALmixer_Channel_List[i].alsource, | |
3066 AL_SOURCE_STATE, &state | |
3067 ); | |
3068 if((error = alGetError()) != AL_NO_ERROR) | |
3069 { | |
3070 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
|
3071 alGetString(error)); |
0 | 3072 } |
3073 if(AL_PAUSED == state) | |
3074 { | |
3075 /* Count the actual number of channels resumed */ | |
3076 counter++; | |
3077 | |
3078 /* We need to resume the expire time count down */ | |
3079 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
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].start_time = ALmixer_GetTicks(); |
0 | 3082 } |
3083 /* Do the same as expire time for fading */ | |
3084 if(ALmixer_Channel_List[i].fade_enabled) | |
3085 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3086 ALmixer_Channel_List[i].fade_start_time = ALmixer_GetTicks(); |
0 | 3087 } |
3088 | |
3089 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
3090 if((error = alGetError()) != AL_NO_ERROR) | |
3091 { | |
3092 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3093 alGetString(error) ); |
0 | 3094 retval = -1; |
3095 } | |
3096 } | |
3097 } | |
3098 } | |
3099 } | |
3100 if(-1 == retval) | |
3101 { | |
3102 return -1; | |
3103 } | |
3104 return counter; | |
3105 } | |
3106 | |
3107 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3108 static ALint Internal_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3109 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3110 ALint channel; |
0 | 3111 if(0 == source) |
3112 { | |
3113 return Internal_ResumeChannel(-1); | |
3114 } | |
3115 | |
3116 channel = Internal_GetChannel(source); | |
3117 if(-1 == channel) | |
3118 { | |
3119 ALmixer_SetError("Cannot resume source: %s", ALmixer_GetError()); | |
3120 return -1; | |
3121 } | |
3122 return Internal_ResumeChannel(channel); | |
3123 } | |
3124 | |
3125 | |
3126 /* Might consider setting eof to 0 as a "feature" | |
3127 * This will allow seek to end to stay there because | |
3128 * Play automatically rewinds if at the end */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3129 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
|
3130 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3131 ALint retval; |
0 | 3132 |
3133 if(NULL == data) | |
3134 { | |
3135 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
|
3136 return AL_FALSE; |
0 | 3137 } |
3138 | |
3139 /* Seek for predecoded files involves moving the chunk pointer around */ | |
3140 if(data->decoded_all) | |
3141 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3142 ALuint byte_position; |
0 | 3143 |
3144 /* OpenAL doesn't seem to like it if I change the buffer | |
3145 * while playing (crashes), so I must require that Seek only | |
3146 * be done when the data is not in use. | |
3147 * Since data may be shared among multiple sources, | |
3148 * I can't shut them down myself, so I have to return an error. | |
3149 */ | |
3150 if(data->in_use) | |
3151 { | |
3152 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
|
3153 return AL_FALSE; |
0 | 3154 } |
3155 #if 0 | |
3156 #if defined(DISABLE_PREDECODED_SEEK) | |
3157 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
|
3158 return AL_FALSE; |
0 | 3159 |
3160 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
3161 /* By default, ALmixer frees the Sound_Sample for predecoded | |
3162 * samples because of the potential memory waste. | |
3163 * However, to seek a sample, we need to have a full | |
3164 * copy of the data around. So the strategy is to | |
3165 * recreate a hackish Sound_Sample to be used for seeking | |
3166 * purposes. If Sound_Sample is NULL, we will reallocate | |
3167 * memory for it and then procede as if everything | |
3168 * was normal. | |
3169 */ | |
3170 if(NULL == data->sample) | |
3171 { | |
3172 if( -1 == Reconstruct_Sound_Sample(data) ) | |
3173 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3174 return AL_FALSE; |
0 | 3175 } |
3176 } | |
3177 #endif | |
3178 #endif | |
3179 /* If access_data was set, then we still have the | |
3180 * Sound_Sample and we can move around in the data. | |
3181 * If it was not set, the data has been freed and we | |
3182 * cannot do anything because there is no way to | |
3183 * recover the data because OpenAL won't let us | |
3184 * get access to the buffers | |
3185 */ | |
3186 if(NULL == data->sample) | |
3187 { | |
3188 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
|
3189 return AL_FALSE; |
0 | 3190 } |
3191 | |
3192 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
|
3193 retval = Set_Predecoded_Seek_Position(data, byte_position); |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3194 if(-1 == retval) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3195 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3196 return AL_FALSE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3197 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3198 else |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3199 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3200 return AL_TRUE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3201 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3202 |
0 | 3203 } |
3204 else | |
3205 { | |
3206 /* Reset eof flag?? */ | |
3207 data->eof = 0; | |
3208 retval = Sound_Seek(data->sample, msec); | |
3209 if(0 == retval) | |
3210 { | |
3211 ALmixer_SetError(Sound_GetError()); | |
3212 | |
3213 fprintf(stderr, "Sound seek error: %s\n", ALmixer_GetError()); | |
3214 /* Try rewinding to clean up? */ | |
3215 /* | |
3216 Internal_RewindData(data); | |
3217 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3218 return AL_FALSE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3219 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3220 return AL_TRUE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3221 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3222 |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3223 return AL_TRUE; |
0 | 3224 } |
3225 | |
3226 | |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3227 static ALint Internal_SeekChannel(ALint channel, ALuint msec) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3228 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3229 ALint retval = 0; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3230 ALenum error; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3231 ALint state; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3232 ALint running_count = 0; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3233 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3234 if(0 == msec) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3235 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3236 return Internal_RewindChannel(channel); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3237 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3238 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3239 if(channel >= Number_of_Channels_global) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3240 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3241 ALmixer_SetError("Cannot seek channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3242 return -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3243 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3244 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3245 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3246 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3247 fprintf(stderr, "24Testing error: %s\n", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3248 alGetString(error)); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3249 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3250 /* Clear error */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3251 alGetError(); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3252 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3253 /* If the user specified a specific channel */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3254 if(channel >= 0) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3255 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3256 /* only need to process channel if in use */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3257 if(ALmixer_Channel_List[channel].channel_in_use) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3258 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3259 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3260 /* What should I do? Do I just rewind the channel |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3261 * or also rewind the data? Since the data is |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3262 * shared, let's make it the user's responsibility |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3263 * to rewind the data. |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3264 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3265 if(ALmixer_Channel_List[channel].almixer_data->decoded_all) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3266 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3267 /* convert milliseconds to seconds */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3268 ALfloat sec_offset = msec / 1000.0f; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3269 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3270 alGetSourcei( |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3271 ALmixer_Channel_List[channel].alsource, |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3272 AL_SOURCE_STATE, &state |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3273 ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3274 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3275 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3276 fprintf(stderr, "25Testing error: %s\n", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3277 alGetString(error)); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3278 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3279 /* OpenAL seek */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3280 alSourcef(ALmixer_Channel_List[channel].alsource, AL_SEC_OFFSET, sec_offset); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3281 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3282 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3283 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3284 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3285 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3286 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3287 /* Need to resume playback if it was originally playing */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3288 if(AL_PLAYING == state) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3289 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3290 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3291 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3292 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3293 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3294 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3295 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3296 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3297 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3298 else if(AL_PAUSED == state) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3299 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3300 /* HACK: The problem is that when paused, after |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3301 * the Rewind, I can't get it off the INITIAL |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3302 * state without restarting |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3303 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3304 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3305 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3306 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3307 fprintf(stderr, "25Testing error: %s\n", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3308 alGetString(error)); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3309 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3310 alSourcePause(ALmixer_Channel_List[channel].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3311 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3312 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3313 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3314 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3315 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3316 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3317 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3318 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3319 else |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3320 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3321 /* Streamed data is different. Rewinding the channel |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3322 * does no good. Rewinding the data will have an |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3323 * effect, but it will be lagged based on how |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3324 * much data is queued. Recommend users call Halt |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3325 * before rewind if they want immediate results. |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3326 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3327 retval = Internal_SeekData(ALmixer_Channel_List[channel].almixer_data, msec); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3328 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3329 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3330 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3331 /* The user wants to rewind all channels */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3332 else |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3333 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3334 ALint i; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3335 ALfloat sec_offset = msec / 1000.0f; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3336 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3337 for(i=0; i<Number_of_Channels_global; i++) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3338 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3339 /* only need to process channel if in use */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3340 if(ALmixer_Channel_List[i].channel_in_use) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3341 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3342 /* What should I do? Do I just rewind the channel |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3343 * or also rewind the data? Since the data is |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3344 * shared, let's make it the user's responsibility |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3345 * to rewind the data. |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3346 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3347 if(ALmixer_Channel_List[i].almixer_data->decoded_all) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3348 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3349 alGetSourcei( |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3350 ALmixer_Channel_List[i].alsource, |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3351 AL_SOURCE_STATE, &state |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3352 ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3353 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3354 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3355 fprintf(stderr, "26Testing error: %s\n", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3356 alGetString(error)); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3357 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3358 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3359 alSourcef(ALmixer_Channel_List[channel].alsource, AL_SEC_OFFSET, sec_offset); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3360 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3361 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3362 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3363 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3364 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3365 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3366 /* Need to resume playback if it was originally playing */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3367 if(AL_PLAYING == state) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3368 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3369 alSourcePlay(ALmixer_Channel_List[i].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3370 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3371 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3372 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3373 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3374 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3375 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3376 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3377 else if(AL_PAUSED == state) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3378 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3379 /* HACK: The problem is that when paused, after |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3380 * the Rewind, I can't get it off the INITIAL |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3381 * state without restarting |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3382 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3383 alSourcePlay(ALmixer_Channel_List[i].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3384 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3385 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3386 fprintf(stderr, "27Testing error: %s\n", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3387 alGetString(error)); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3388 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3389 alSourcePause(ALmixer_Channel_List[i].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3390 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3391 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3392 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3393 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3394 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3395 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3396 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3397 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3398 else |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3399 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3400 /* Streamed data is different. Rewinding the channel |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3401 * does no good. Rewinding the data will have an |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3402 * effect, but it will be lagged based on how |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3403 * much data is queued. Recommend users call Halt |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3404 * before rewind if they want immediate results. |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3405 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3406 running_count += Internal_SeekData(ALmixer_Channel_List[i].almixer_data, msec); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3407 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3408 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3409 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3410 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3411 if(-1 == retval) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3412 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3413 return -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3414 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3415 else |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3416 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3417 return running_count; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3418 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3419 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3420 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3421 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3422 static ALint Internal_SeekSource(ALuint source, ALuint msec) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3423 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3424 ALint channel; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3425 if(0 == source) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3426 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3427 return Internal_SeekChannel(-1, msec); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3428 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3429 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3430 channel = Internal_GetChannel(source); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3431 if(-1 == channel) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3432 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3433 ALmixer_SetError("Cannot seek source: %s", ALmixer_GetError()); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3434 return 0; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3435 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3436 return Internal_SeekChannel(channel, msec); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3437 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3438 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3439 |
0 | 3440 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3441 static ALint Internal_FadeInChannelTimed(ALint channel, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 3442 { |
3443 ALfloat value; | |
3444 ALenum error; | |
3445 ALfloat original_value; | |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
3446 /* ALuint current_time = ALmixer_GetTicks(); */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3447 ALint retval; |
0 | 3448 |
3449 | |
3450 | |
3451 if(channel >= Number_of_Channels_global) | |
3452 { | |
3453 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); | |
3454 return -1; | |
3455 } | |
3456 /* Let's call PlayChannelTimed to do the job. | |
3457 * There are two catches: | |
3458 * First is that we must set the volumes before the play call(s). | |
3459 * Second is that we must initialize the channel values | |
3460 */ | |
3461 | |
3462 if(channel < 0) | |
3463 { | |
3464 /* This might cause a problem for threads/race conditions. | |
3465 * We need to set the volume on an unknown channel, | |
3466 * so we need to request a channel first. Remember | |
3467 * that requesting a channel doesn't lock and it | |
3468 * could be surrendered to somebody else before we claim it. | |
3469 */ | |
3470 channel = Internal_GetChannel(0); | |
3471 if(-1 == channel) | |
3472 { | |
3473 return -1; | |
3474 } | |
3475 } | |
3476 else if(ALmixer_Channel_List[channel].channel_in_use) | |
3477 { | |
3478 ALmixer_SetError("Channel %d is already in use", channel); | |
3479 return -1; | |
3480 } | |
3481 | |
3482 | |
3483 /* Get the original volume in case of a problem */ | |
3484 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
|
3485 AL_GAIN, &original_value); |
0 | 3486 |
3487 if((error = alGetError()) != AL_NO_ERROR) | |
3488 { | |
3489 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
|
3490 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3491 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3492 ALmixer_Channel_List[channel].fade_end_volume = original_value; |
0 | 3493 |
3494 /* Get the Min volume */ | |
3495 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3496 AL_MIN_GAIN, &value); | |
3497 if((error = alGetError()) != AL_NO_ERROR) | |
3498 { | |
3499 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
|
3500 alGetString(error)); |
0 | 3501 } |
3502 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3503 | |
3504 /* Set the actual volume */ | |
3505 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
|
3506 AL_GAIN, value); |
0 | 3507 if((error = alGetError()) != AL_NO_ERROR) |
3508 { | |
3509 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
|
3510 alGetString(error)); |
0 | 3511 } |
3512 | |
3513 | |
3514 /* Now call PlayChannelTimed */ | |
3515 retval = Internal_PlayChannelTimed(channel, data, loops, expire_ticks); | |
3516 if(-1 == retval) | |
3517 { | |
3518 /* Chance of failure is actually pretty high since | |
3519 * a channel might already be in use or streamed | |
3520 * data can be shared | |
3521 */ | |
3522 /* Restore the original value to avoid accidental | |
3523 * distruption of playback | |
3524 */ | |
3525 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
|
3526 AL_GAIN, original_value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3527 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3528 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3529 fprintf(stderr, "38Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3530 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3531 } |
0 | 3532 return retval; |
3533 } | |
3534 | |
3535 /* We can't accept 0 as a value because of div-by-zero. | |
3536 * If zero, just call PlayChannelTimed at normal | |
3537 * volume | |
3538 */ | |
3539 if(0 == fade_ticks) | |
3540 { | |
3541 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
|
3542 AL_GAIN, |
0 | 3543 ALmixer_Channel_List[channel].fade_end_volume |
3544 ); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3545 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3546 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3547 fprintf(stderr, "39Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3548 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3549 } |
0 | 3550 |
3551 return retval; | |
3552 } | |
3553 | |
3554 /* Enable fading effects via the flag */ | |
3555 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3556 /* Set fade start time */ | |
3557 ALmixer_Channel_List[channel].fade_start_time | |
3558 = ALmixer_Channel_List[channel].start_time; | |
3559 /* Set the fade expire ticks */ | |
3560 ALmixer_Channel_List[channel].fade_expire_ticks = fade_ticks; | |
3561 | |
3562 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3563 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / fade_ticks; | |
3564 | |
3565 return retval; | |
3566 | |
3567 } | |
3568 | |
3569 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3570 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
|
3571 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3572 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3573 ALint retval; |
0 | 3574 if(0 == source) |
3575 { | |
3576 retval = Internal_FadeInChannelTimed(-1, data, loops, fade_ticks, expire_ticks); | |
3577 if(-1 == retval) | |
3578 { | |
3579 return 0; | |
3580 } | |
3581 else | |
3582 { | |
3583 return Internal_GetSource(retval); | |
3584 } | |
3585 } | |
3586 | |
3587 channel = Internal_GetChannel(source); | |
3588 if(-1 == channel) | |
3589 { | |
3590 ALmixer_SetError("Cannot FadeIn source: %s", ALmixer_GetError()); | |
3591 return 0; | |
3592 } | |
3593 retval = Internal_FadeInChannelTimed(channel, data, loops, fade_ticks, expire_ticks); | |
3594 if(-1 == retval) | |
3595 { | |
3596 return 0; | |
3597 } | |
3598 else | |
3599 { | |
3600 return source; | |
3601 } | |
3602 /* make compiler happy */ | |
3603 return 0; | |
3604 } | |
3605 | |
3606 | |
3607 | |
3608 | |
3609 /* Will fade out currently playing channels. | |
3610 * 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
|
3611 static ALint Internal_FadeOutChannel(ALint channel, ALuint ticks) |
0 | 3612 { |
3613 ALfloat value; | |
3614 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3615 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3616 ALuint counter = 0; |
0 | 3617 |
3618 /* We can't accept 0 as a value because of div-by-zero. | |
3619 * If zero, just call Halt at normal | |
3620 * volume | |
3621 */ | |
3622 if(0 == ticks) | |
3623 { | |
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
|
3624 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 3625 } |
3626 | |
3627 | |
3628 if(channel >= Number_of_Channels_global) | |
3629 { | |
3630 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); | |
3631 return -1; | |
3632 } | |
3633 | |
3634 if(channel >= 0) | |
3635 { | |
3636 if(ALmixer_Channel_List[channel].channel_in_use) | |
3637 { | |
3638 /* Get the current volume */ | |
3639 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
|
3640 AL_GAIN, &value); |
0 | 3641 ALmixer_Channel_List[channel].fade_start_volume = value; |
3642 if((error = alGetError()) != AL_NO_ERROR) | |
3643 { | |
3644 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
|
3645 alGetString(error)); |
0 | 3646 } |
3647 | |
3648 /* Get the Min volume */ | |
3649 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3650 AL_MIN_GAIN, &value); | |
3651 if((error = alGetError()) != AL_NO_ERROR) | |
3652 { | |
3653 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
|
3654 alGetString(error)); |
0 | 3655 } |
3656 ALmixer_Channel_List[channel].fade_end_volume = value; | |
3657 | |
3658 /* Set expire start time */ | |
3659 ALmixer_Channel_List[channel].start_time = current_time; | |
3660 /* Set the expire ticks */ | |
3661 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
3662 /* Set fade start time */ | |
3663 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3664 /* Set the fade expire ticks */ | |
3665 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3666 /* Enable fading effects via the flag */ | |
3667 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3668 | |
3669 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3670 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3671 | |
3672 counter++; | |
3673 } | |
3674 } | |
3675 /* Else need to fade out all channels */ | |
3676 else | |
3677 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3678 ALint i; |
0 | 3679 for(i=0; i<Number_of_Channels_global; i++) |
3680 { | |
3681 if(ALmixer_Channel_List[i].channel_in_use) | |
3682 { | |
3683 /* Get the current volume */ | |
3684 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
|
3685 AL_GAIN, &value); |
0 | 3686 ALmixer_Channel_List[i].fade_start_volume = value; |
3687 if((error = alGetError()) != AL_NO_ERROR) | |
3688 { | |
3689 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
|
3690 alGetString(error)); |
0 | 3691 } |
3692 | |
3693 /* Get the Min volume */ | |
3694 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
3695 AL_MIN_GAIN, &value); | |
3696 if((error = alGetError()) != AL_NO_ERROR) | |
3697 { | |
3698 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
|
3699 alGetString(error)); |
0 | 3700 } |
3701 ALmixer_Channel_List[i].fade_end_volume = value; | |
3702 | |
3703 /* Set expire start time */ | |
3704 ALmixer_Channel_List[i].start_time = current_time; | |
3705 /* Set the expire ticks */ | |
3706 ALmixer_Channel_List[i].expire_ticks = ticks; | |
3707 /* Set fade start time */ | |
3708 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3709 /* Set the fade expire ticks */ | |
3710 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3711 /* Enable fading effects via the flag */ | |
3712 ALmixer_Channel_List[i].fade_enabled = 1; | |
3713 | |
3714 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3715 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3716 | |
3717 counter++; | |
3718 } | |
3719 } /* End for loop */ | |
3720 } | |
3721 return counter; | |
3722 } | |
3723 | |
3724 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3725 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
|
3726 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3727 ALint channel; |
0 | 3728 if(0 == source) |
3729 { | |
3730 return Internal_FadeOutChannel(-1, ticks); | |
3731 } | |
3732 | |
3733 channel = Internal_GetChannel(source); | |
3734 if(-1 == channel) | |
3735 { | |
3736 ALmixer_SetError("Cannot FadeOut source: %s", ALmixer_GetError()); | |
3737 return -1; | |
3738 } | |
3739 return Internal_FadeOutChannel(channel, ticks); | |
3740 } | |
3741 | |
3742 | |
3743 /* Will fade currently playing channels. | |
3744 * It starts at the current volume level and go to target | |
3745 * Only affects channels that are playing | |
3746 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3747 static ALint Internal_FadeChannel(ALint channel, ALuint ticks, ALfloat volume) |
0 | 3748 { |
3749 ALfloat value; | |
3750 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3751 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3752 ALuint counter = 0; |
0 | 3753 |
3754 if(channel >= Number_of_Channels_global) | |
3755 { | |
3756 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); | |
3757 return -1; | |
3758 } | |
3759 | |
3760 if(channel >= 0) | |
3761 { | |
3762 if(volume < ALmixer_Channel_List[channel].min_volume) | |
3763 { | |
3764 volume = ALmixer_Channel_List[channel].min_volume; | |
3765 } | |
3766 else if(volume > ALmixer_Channel_List[channel].max_volume) | |
3767 { | |
3768 volume = ALmixer_Channel_List[channel].max_volume; | |
3769 } | |
3770 | |
3771 if(ALmixer_Channel_List[channel].channel_in_use) | |
3772 { | |
3773 if(ticks > 0) | |
3774 { | |
3775 /* Get the current volume */ | |
3776 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
|
3777 AL_GAIN, &value); |
0 | 3778 if((error = alGetError()) != AL_NO_ERROR) |
3779 { | |
3780 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
|
3781 alGetString(error)); |
0 | 3782 } |
3783 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3784 | |
3785 /* Set the target volume */ | |
3786 ALmixer_Channel_List[channel].fade_end_volume = volume; | |
3787 | |
3788 /* Set fade start time */ | |
3789 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3790 /* Set the fade expire ticks */ | |
3791 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3792 /* Enable fading effects via the flag */ | |
3793 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3794 | |
3795 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3796 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3797 } | |
3798 else | |
3799 { | |
3800 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
|
3801 AL_GAIN, volume); |
0 | 3802 if((error = alGetError()) != AL_NO_ERROR) |
3803 { | |
3804 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
|
3805 alGetString(error)); |
0 | 3806 } |
3807 } | |
3808 counter++; | |
3809 } | |
3810 } | |
3811 /* Else need to fade out all channels */ | |
3812 else | |
3813 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3814 ALint i; |
0 | 3815 for(i=0; i<Number_of_Channels_global; i++) |
3816 { | |
3817 if(volume < ALmixer_Channel_List[i].min_volume) | |
3818 { | |
3819 volume = ALmixer_Channel_List[i].min_volume; | |
3820 } | |
3821 else if(volume > ALmixer_Channel_List[i].max_volume) | |
3822 { | |
3823 volume = ALmixer_Channel_List[i].max_volume; | |
3824 } | |
3825 | |
3826 if(ALmixer_Channel_List[i].channel_in_use) | |
3827 { | |
3828 if(ticks > 0) | |
3829 { | |
3830 /* Get the current volume */ | |
3831 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
|
3832 AL_GAIN, &value); |
0 | 3833 if((error = alGetError()) != AL_NO_ERROR) |
3834 { | |
3835 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
|
3836 alGetString(error)); |
0 | 3837 } |
3838 ALmixer_Channel_List[i].fade_start_volume = value; | |
3839 | |
3840 /* Set target volume */ | |
3841 ALmixer_Channel_List[i].fade_end_volume = volume; | |
3842 | |
3843 /* Set fade start time */ | |
3844 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3845 /* Set the fade expire ticks */ | |
3846 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3847 /* Enable fading effects via the flag */ | |
3848 ALmixer_Channel_List[i].fade_enabled = 1; | |
3849 | |
3850 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3851 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3852 } | |
3853 else | |
3854 { | |
3855 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
|
3856 AL_GAIN, volume); |
0 | 3857 if((error = alGetError()) != AL_NO_ERROR) |
3858 { | |
3859 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
|
3860 alGetString(error)); |
0 | 3861 } |
3862 } | |
3863 counter++; | |
3864 } | |
3865 } /* End for loop */ | |
3866 } | |
3867 return counter; | |
3868 } | |
3869 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3870 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
|
3871 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3872 ALint channel; |
0 | 3873 if(0 == source) |
3874 { | |
3875 return Internal_FadeChannel(-1, ticks, volume); | |
3876 } | |
3877 | |
3878 channel = Internal_GetChannel(source); | |
3879 if(-1 == channel) | |
3880 { | |
3881 ALmixer_SetError("Cannot Fade source: %s", ALmixer_GetError()); | |
3882 return -1; | |
3883 } | |
3884 return Internal_FadeChannel(channel, ticks, volume); | |
3885 } | |
3886 | |
3887 | |
3888 | |
3889 | |
3890 /* Set a volume regardless if it's in use or not. | |
3891 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3892 static ALboolean Internal_SetVolumeChannel(ALint channel, ALfloat volume) |
0 | 3893 { |
3894 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3895 ALboolean retval = AL_TRUE; |
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 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3898 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3899 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
|
3900 return AL_FALSE; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3903 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3904 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3905 if(volume < 0.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3906 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3907 volume = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3908 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3909 else if(volume > 1.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3910 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3911 volume = 1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3912 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3913 alSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3914 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3915 if((error = alGetError()) != AL_NO_ERROR) |
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 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3918 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3919 retval = AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3920 } |
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 else |
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 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3925 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
|
3926 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3927 if(volume < 0.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3928 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3929 volume = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3930 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3931 else if(volume > 1.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3932 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3933 volume = 1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3934 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3935 alSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3936 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3937 if((error = alGetError()) != AL_NO_ERROR) |
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 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3940 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3941 retval = AL_FALSE; |
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 } |
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 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3946 } |
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 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
|
3949 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3950 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3951 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3952 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3953 return Internal_SetVolumeChannel(-1, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3954 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3955 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3956 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3957 if(-1 == channel) |
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 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
|
3960 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3961 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3962 return Internal_SetVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3963 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3964 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3965 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3966 static ALfloat Internal_GetVolumeChannel(ALint channel) |
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 ALfloat value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3969 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3970 ALfloat running_total = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3971 ALfloat retval = 0.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 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3974 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3975 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
|
3976 return -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3977 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3978 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3979 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3980 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3981 alGetSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3982 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3983 if((error = alGetError()) != AL_NO_ERROR) |
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 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3986 retval = -1.0f; |
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 retval = value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3991 } |
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3994 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3995 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3996 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
|
3997 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3998 alGetSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3999 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4000 if((error = alGetError()) != AL_NO_ERROR) |
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 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4003 retval = -1; |
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 else |
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 running_total += value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4008 } |
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 if(0 == Number_of_Channels_global) |
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 ALmixer_SetError("No channels are allocated"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4013 retval = -1.0f; |
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 else |
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 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
|
4018 } |
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 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4021 } |
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 static ALfloat Internal_GetVolumeSource(ALuint source) |
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 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4026 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4027 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4028 return Internal_GetVolumeChannel(-1); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4029 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4030 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4031 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4032 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4033 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4034 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
|
4035 return -1.0f; |
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 return Internal_GetVolumeChannel(channel); |
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 |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4043 /* 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
|
4044 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4045 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
|
4046 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4047 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4048 ALboolean retval = AL_TRUE; |
0 | 4049 |
4050 if(channel >= Number_of_Channels_global) | |
4051 { | |
4052 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
|
4053 return AL_FALSE; |
0 | 4054 } |
4055 | |
4056 if(channel >= 0) | |
4057 { | |
4058 if(volume < 0.0f) | |
4059 { | |
4060 volume = 0.0f; | |
4061 } | |
4062 else if(volume > 1.0f) | |
4063 { | |
4064 volume = 1.0f; | |
4065 } | |
4066 ALmixer_Channel_List[channel].max_volume = volume; | |
4067 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4068 AL_MAX_GAIN, volume); | |
4069 if((error = alGetError()) != AL_NO_ERROR) | |
4070 { | |
4071 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4072 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4073 retval = AL_FALSE; |
0 | 4074 } |
4075 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
4076 { | |
4077 ALmixer_Channel_List[channel].min_volume = volume; | |
4078 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4079 AL_MIN_GAIN, volume); | |
4080 if((error = alGetError()) != AL_NO_ERROR) | |
4081 { | |
4082 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4083 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4084 retval = AL_FALSE; |
0 | 4085 } |
4086 } | |
4087 } | |
4088 else | |
4089 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4090 ALint i; |
0 | 4091 for(i=0; i<Number_of_Channels_global; i++) |
4092 { | |
4093 if(volume < 0.0f) | |
4094 { | |
4095 volume = 0.0f; | |
4096 } | |
4097 else if(volume > 1.0f) | |
4098 { | |
4099 volume = 1.0f; | |
4100 } | |
4101 ALmixer_Channel_List[i].max_volume = volume; | |
4102 alSourcef(ALmixer_Channel_List[i].alsource, | |
4103 AL_MAX_GAIN, volume); | |
4104 if((error = alGetError()) != AL_NO_ERROR) | |
4105 { | |
4106 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4107 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4108 retval = AL_FALSE; |
0 | 4109 } |
4110 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
4111 { | |
4112 ALmixer_Channel_List[i].min_volume = volume; | |
4113 alSourcef(ALmixer_Channel_List[i].alsource, | |
4114 AL_MIN_GAIN, volume); | |
4115 if((error = alGetError()) != AL_NO_ERROR) | |
4116 { | |
4117 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4118 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4119 retval = AL_FALSE; |
0 | 4120 } |
4121 } | |
4122 } | |
4123 } | |
4124 return retval; | |
4125 } | |
4126 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4127 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
|
4128 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4129 ALint channel; |
0 | 4130 if(0 == source) |
4131 { | |
4132 return Internal_SetMaxVolumeChannel(-1, volume); | |
4133 } | |
4134 | |
4135 channel = Internal_GetChannel(source); | |
4136 if(-1 == channel) | |
4137 { | |
4138 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
|
4139 return AL_FALSE; |
0 | 4140 } |
4141 return Internal_SetMaxVolumeChannel(channel, volume); | |
4142 } | |
4143 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4144 static ALfloat Internal_GetMaxVolumeChannel(ALint channel) |
0 | 4145 { |
4146 /* | |
4147 ALfloat value; | |
4148 ALenum error; | |
4149 */ | |
4150 ALfloat running_total = 0.0f; | |
4151 ALfloat retval = 0.0f; | |
4152 | |
4153 if(channel >= Number_of_Channels_global) | |
4154 { | |
4155 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); | |
4156 return -1.0f; | |
4157 } | |
4158 | |
4159 if(channel >= 0) | |
4160 { | |
4161 /* | |
4162 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
4163 AL_GAIN, &value); | |
4164 if((error = alGetError()) != AL_NO_ERROR) | |
4165 { | |
4166 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4167 alGetString(error) ); |
0 | 4168 retval = -1.0f; |
4169 } | |
4170 else | |
4171 { | |
4172 retval = value; | |
4173 } | |
4174 */ | |
4175 retval = ALmixer_Channel_List[channel].max_volume; | |
4176 | |
4177 } | |
4178 else | |
4179 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4180 ALint i; |
0 | 4181 for(i=0; i<Number_of_Channels_global; i++) |
4182 { | |
4183 /* | |
4184 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
4185 AL_GAIN, &value); | |
4186 if((error = alGetError()) != AL_NO_ERROR) | |
4187 { | |
4188 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4189 alGetString(error) ); |
0 | 4190 retval = -1; |
4191 } | |
4192 else | |
4193 { | |
4194 running_total += value; | |
4195 } | |
4196 */ | |
4197 running_total += ALmixer_Channel_List[i].max_volume; | |
4198 } | |
4199 if(0 == Number_of_Channels_global) | |
4200 { | |
4201 ALmixer_SetError("No channels are allocated"); | |
4202 retval = -1.0f; | |
4203 } | |
4204 else | |
4205 { | |
4206 retval = running_total / Number_of_Channels_global; | |
4207 } | |
4208 } | |
4209 return retval; | |
4210 } | |
4211 | |
4212 static ALfloat Internal_GetMaxVolumeSource(ALuint source) | |
4213 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4214 ALint channel; |
0 | 4215 if(0 == source) |
4216 { | |
4217 return Internal_GetMaxVolumeChannel(-1); | |
4218 } | |
4219 | |
4220 channel = Internal_GetChannel(source); | |
4221 if(-1 == channel) | |
4222 { | |
4223 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
4224 return -1.0f; | |
4225 } | |
4226 | |
4227 return Internal_GetMaxVolumeChannel(channel); | |
4228 } | |
4229 | |
4230 | |
4231 /* Set a volume regardless if it's in use or not. | |
4232 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4233 static ALboolean Internal_SetMinVolumeChannel(ALint channel, ALfloat volume) |
0 | 4234 { |
4235 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4236 ALboolean retval = AL_TRUE; |
0 | 4237 |
4238 if(channel >= Number_of_Channels_global) | |
4239 { | |
4240 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
|
4241 return AL_FALSE; |
0 | 4242 } |
4243 | |
4244 if(channel >= 0) | |
4245 { | |
4246 if(volume < 0.0f) | |
4247 { | |
4248 volume = 0.0f; | |
4249 } | |
4250 else if(volume > 1.0f) | |
4251 { | |
4252 volume = 1.0f; | |
4253 } | |
4254 ALmixer_Channel_List[channel].min_volume = volume; | |
4255 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4256 AL_MIN_GAIN, volume); | |
4257 if((error = alGetError()) != AL_NO_ERROR) | |
4258 { | |
4259 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4260 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4261 retval = AL_FALSE; |
0 | 4262 } |
4263 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
4264 { | |
4265 ALmixer_Channel_List[channel].max_volume = volume; | |
4266 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4267 AL_MAX_GAIN, volume); | |
4268 if((error = alGetError()) != AL_NO_ERROR) | |
4269 { | |
4270 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4271 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4272 retval = AL_FALSE; |
0 | 4273 } |
4274 } | |
4275 } | |
4276 else | |
4277 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4278 ALint i; |
0 | 4279 for(i=0; i<Number_of_Channels_global; i++) |
4280 { | |
4281 if(volume < 0.0f) | |
4282 { | |
4283 volume = 0.0f; | |
4284 } | |
4285 else if(volume > 1.0f) | |
4286 { | |
4287 volume = 1.0f; | |
4288 } | |
4289 ALmixer_Channel_List[i].min_volume = volume; | |
4290 alSourcef(ALmixer_Channel_List[i].alsource, | |
4291 AL_MIN_GAIN, volume); | |
4292 if((error = alGetError()) != AL_NO_ERROR) | |
4293 { | |
4294 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4295 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4296 retval = AL_FALSE; |
0 | 4297 } |
4298 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
4299 { | |
4300 ALmixer_Channel_List[i].max_volume = volume; | |
4301 alSourcef(ALmixer_Channel_List[i].alsource, | |
4302 AL_MAX_GAIN, volume); | |
4303 if((error = alGetError()) != AL_NO_ERROR) | |
4304 { | |
4305 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4306 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4307 retval = AL_FALSE; |
0 | 4308 } |
4309 } | |
4310 } | |
4311 } | |
4312 return retval; | |
4313 } | |
4314 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4315 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
|
4316 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4317 ALint channel; |
0 | 4318 if(0 == source) |
4319 { | |
4320 return Internal_SetMinVolumeChannel(-1, volume); | |
4321 } | |
4322 | |
4323 channel = Internal_GetChannel(source); | |
4324 if(-1 == channel) | |
4325 { | |
4326 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
|
4327 return AL_FALSE; |
0 | 4328 } |
4329 return Internal_SetMinVolumeChannel(channel, volume); | |
4330 } | |
4331 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4332 static ALfloat Internal_GetMinVolumeChannel(ALint channel) |
0 | 4333 { |
4334 /* | |
4335 ALfloat value; | |
4336 ALenum error; | |
4337 */ | |
4338 ALfloat running_total = 0.0f; | |
4339 ALfloat retval = 0.0f; | |
4340 | |
4341 if(channel >= Number_of_Channels_global) | |
4342 { | |
4343 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); | |
4344 return -1.0f; | |
4345 } | |
4346 | |
4347 if(channel >= 0) | |
4348 { | |
4349 /* | |
4350 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
4351 AL_GAIN, &value); | |
4352 if((error = alGetError()) != AL_NO_ERROR) | |
4353 { | |
4354 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4355 alGetString(error) ); |
0 | 4356 retval = -1.0f; |
4357 } | |
4358 else | |
4359 { | |
4360 retval = value; | |
4361 } | |
4362 */ | |
4363 retval = ALmixer_Channel_List[channel].min_volume; | |
4364 | |
4365 } | |
4366 else | |
4367 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4368 ALint i; |
0 | 4369 for(i=0; i<Number_of_Channels_global; i++) |
4370 { | |
4371 /* | |
4372 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
4373 AL_GAIN, &value); | |
4374 if((error = alGetError()) != AL_NO_ERROR) | |
4375 { | |
4376 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4377 alGetString(error) ); |
0 | 4378 retval = -1; |
4379 } | |
4380 else | |
4381 { | |
4382 running_total += value; | |
4383 } | |
4384 */ | |
4385 running_total += ALmixer_Channel_List[i].min_volume; | |
4386 } | |
4387 if(0 == Number_of_Channels_global) | |
4388 { | |
4389 ALmixer_SetError("No channels are allocated"); | |
4390 retval = -1.0f; | |
4391 } | |
4392 else | |
4393 { | |
4394 retval = running_total / Number_of_Channels_global; | |
4395 } | |
4396 } | |
4397 return retval; | |
4398 } | |
4399 | |
4400 static ALfloat Internal_GetMinVolumeSource(ALuint source) | |
4401 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4402 ALint channel; |
0 | 4403 if(0 == source) |
4404 { | |
4405 return Internal_GetMinVolumeChannel(-1); | |
4406 } | |
4407 | |
4408 channel = Internal_GetChannel(source); | |
4409 if(-1 == channel) | |
4410 { | |
4411 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
4412 return -1.0f; | |
4413 } | |
4414 | |
4415 return Internal_GetMinVolumeChannel(channel); | |
4416 } | |
4417 | |
4418 | |
4419 /* Changes the listener volume */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4420 static ALboolean Internal_SetMasterVolume(ALfloat volume) |
0 | 4421 { |
4422 ALenum error; | |
4423 alListenerf(AL_GAIN, volume); | |
4424 if((error = alGetError()) != AL_NO_ERROR) | |
4425 { | |
4426 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4427 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4428 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4429 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4430 return AL_TRUE; |
0 | 4431 } |
4432 | |
4433 static ALfloat Internal_GetMasterVolume() | |
4434 { | |
4435 ALenum error; | |
4436 ALfloat volume; | |
4437 alGetListenerf(AL_GAIN, &volume); | |
4438 if((error = alGetError()) != AL_NO_ERROR) | |
4439 { | |
4440 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4441 alGetString(error) ); |
0 | 4442 return -1.0f; |
4443 } | |
4444 return volume; | |
4445 } | |
4446 | |
4447 | |
4448 | |
4449 | |
4450 /* Will fade out currently playing channels. | |
4451 * 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
|
4452 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
|
4453 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4454 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4455 ALuint counter = 0; |
0 | 4456 |
4457 /* We can't accept 0 as a value because of div-by-zero. | |
4458 * If zero, just call Halt at normal | |
4459 * volume | |
4460 */ | |
4461 if(0 == ticks) | |
4462 { | |
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
|
4463 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 4464 } |
4465 if(ticks < -1) | |
4466 { | |
4467 ticks = -1; | |
4468 } | |
4469 | |
4470 | |
4471 if(channel >= Number_of_Channels_global) | |
4472 { | |
4473 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); | |
4474 return -1; | |
4475 } | |
4476 | |
4477 if(channel >= 0) | |
4478 { | |
4479 if(ALmixer_Channel_List[channel].channel_in_use) | |
4480 { | |
4481 /* Set expire start time */ | |
4482 ALmixer_Channel_List[channel].start_time = current_time; | |
4483 /* Set the expire ticks */ | |
4484 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
4485 | |
4486 counter++; | |
4487 } | |
4488 } | |
4489 /* Else need to fade out all channels */ | |
4490 else | |
4491 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4492 ALint i; |
0 | 4493 for(i=0; i<Number_of_Channels_global; i++) |
4494 { | |
4495 if(ALmixer_Channel_List[i].channel_in_use) | |
4496 { | |
4497 /* Set expire start time */ | |
4498 ALmixer_Channel_List[i].start_time = current_time; | |
4499 /* Set the expire ticks */ | |
4500 ALmixer_Channel_List[i].expire_ticks = ticks; | |
4501 | |
4502 counter++; | |
4503 } | |
4504 } /* End for loop */ | |
4505 } | |
4506 return counter; | |
4507 } | |
4508 | |
4509 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4510 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
|
4511 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4512 ALint channel; |
0 | 4513 if(0 == source) |
4514 { | |
4515 return Internal_ExpireChannel(-1, ticks); | |
4516 } | |
4517 | |
4518 channel = Internal_GetChannel(source); | |
4519 if(-1 == channel) | |
4520 { | |
4521 ALmixer_SetError("Cannot Expire source: %s", ALmixer_GetError()); | |
4522 return -1; | |
4523 } | |
4524 return Internal_ExpireChannel(channel, ticks); | |
4525 } | |
4526 | |
4527 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4528 static ALint Internal_QueryChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4529 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4530 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4531 ALint counter = 0; |
0 | 4532 if(channel >= Number_of_Channels_global) |
4533 { | |
4534 ALmixer_SetError("Invalid channel: %d", channel); | |
4535 return -1; | |
4536 } | |
4537 | |
4538 if(channel >= 0) | |
4539 { | |
4540 return ALmixer_Channel_List[channel].channel_in_use; | |
4541 } | |
4542 | |
4543 /* Else, return the number of channels in use */ | |
4544 for(i=0; i<Number_of_Channels_global; i++) | |
4545 { | |
4546 if(ALmixer_Channel_List[i].channel_in_use) | |
4547 { | |
4548 counter++; | |
4549 } | |
4550 } | |
4551 return counter; | |
4552 } | |
4553 | |
4554 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4555 static ALint Internal_QuerySource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4556 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4557 ALint channel; |
0 | 4558 if(0 == source) |
4559 { | |
4560 return Internal_QueryChannel(-1); | |
4561 } | |
4562 | |
4563 channel = Internal_GetChannel(source); | |
4564 if(-1 == channel) | |
4565 { | |
4566 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4567 return -1; | |
4568 } | |
4569 | |
4570 return Internal_QueryChannel(channel); | |
4571 } | |
4572 | |
4573 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4574 static ALuint Internal_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4575 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4576 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4577 ALuint counter = 0; |
0 | 4578 |
4579 | |
4580 /* Else, return the number of channels in use */ | |
4581 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4582 { | |
4583 if(ALmixer_Channel_List[i].channel_in_use) | |
4584 { | |
4585 counter++; | |
4586 } | |
4587 } | |
4588 return counter; | |
4589 } | |
4590 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4591 static ALuint Internal_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4592 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4593 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4594 ALuint counter = 0; |
0 | 4595 |
4596 | |
4597 /* Else, return the number of channels in use */ | |
4598 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4599 { | |
4600 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4601 { | |
4602 counter++; | |
4603 } | |
4604 } | |
4605 return counter; | |
4606 } | |
4607 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4608 static ALuint Internal_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4609 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4610 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4611 ALuint counter = 0; |
0 | 4612 |
4613 | |
4614 /* Else, return the number of channels in use */ | |
4615 for(i=0; i<Number_of_Channels_global; i++) | |
4616 { | |
4617 if(ALmixer_Channel_List[i].channel_in_use) | |
4618 { | |
4619 counter++; | |
4620 } | |
4621 } | |
4622 return counter; | |
4623 } | |
4624 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4625 static ALuint Internal_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4626 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4627 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4628 ALuint counter = 0; |
0 | 4629 |
4630 | |
4631 /* Else, return the number of channels in use */ | |
4632 for(i=0; i<Number_of_Channels_global; i++) | |
4633 { | |
4634 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4635 { | |
4636 counter++; | |
4637 } | |
4638 } | |
4639 return counter; | |
4640 } | |
4641 | |
4642 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4643 static ALint Internal_PlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4644 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4645 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4646 ALint counter = 0; |
0 | 4647 ALint state; |
4648 | |
4649 if(channel >= Number_of_Channels_global) | |
4650 { | |
4651 ALmixer_SetError("Invalid channel: %d", channel); | |
4652 return -1; | |
4653 } | |
4654 | |
4655 if(channel >= 0) | |
4656 { | |
4657 if(ALmixer_Channel_List[channel].channel_in_use) | |
4658 { | |
4659 alGetSourcei( | |
4660 ALmixer_Channel_List[channel].alsource, | |
4661 AL_SOURCE_STATE, &state | |
4662 ); | |
4663 if(AL_PLAYING == state) | |
4664 { | |
4665 return 1; | |
4666 } | |
4667 } | |
4668 return 0; | |
4669 } | |
4670 | |
4671 /* Else, return the number of channels in use */ | |
4672 for(i=0; i<Number_of_Channels_global; i++) | |
4673 { | |
4674 if(ALmixer_Channel_List[i].channel_in_use) | |
4675 { | |
4676 alGetSourcei( | |
4677 ALmixer_Channel_List[i].alsource, | |
4678 AL_SOURCE_STATE, &state | |
4679 ); | |
4680 if(AL_PLAYING == state) | |
4681 { | |
4682 counter++; | |
4683 } | |
4684 } | |
4685 } | |
4686 return counter; | |
4687 } | |
4688 | |
4689 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4690 static ALint Internal_PlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4691 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4692 ALint channel; |
0 | 4693 if(0 == source) |
4694 { | |
4695 return Internal_PlayingChannel(-1); | |
4696 } | |
4697 | |
4698 channel = Internal_GetChannel(source); | |
4699 if(-1 == channel) | |
4700 { | |
4701 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4702 return -1; | |
4703 } | |
4704 | |
4705 return Internal_PlayingChannel(channel); | |
4706 } | |
4707 | |
4708 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4709 static ALint Internal_PausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4710 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4711 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4712 ALint counter = 0; |
0 | 4713 ALint state; |
4714 | |
4715 if(channel >= Number_of_Channels_global) | |
4716 { | |
4717 ALmixer_SetError("Invalid channel: %d", channel); | |
4718 return -1; | |
4719 } | |
4720 | |
4721 if(channel >= 0) | |
4722 { | |
4723 if(ALmixer_Channel_List[channel].channel_in_use) | |
4724 { | |
4725 alGetSourcei( | |
4726 ALmixer_Channel_List[channel].alsource, | |
4727 AL_SOURCE_STATE, &state | |
4728 ); | |
4729 if(AL_PAUSED == state) | |
4730 { | |
4731 return 1; | |
4732 } | |
4733 } | |
4734 return 0; | |
4735 } | |
4736 | |
4737 /* Else, return the number of channels in use */ | |
4738 for(i=0; i<Number_of_Channels_global; i++) | |
4739 { | |
4740 if(ALmixer_Channel_List[i].channel_in_use) | |
4741 { | |
4742 alGetSourcei( | |
4743 ALmixer_Channel_List[i].alsource, | |
4744 AL_SOURCE_STATE, &state | |
4745 ); | |
4746 if(AL_PAUSED == state) | |
4747 { | |
4748 counter++; | |
4749 } | |
4750 } | |
4751 } | |
4752 return counter; | |
4753 } | |
4754 | |
4755 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4756 static ALint Internal_PausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4757 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4758 ALint channel; |
0 | 4759 if(0 == source) |
4760 { | |
4761 return Internal_PausedChannel(-1); | |
4762 } | |
4763 | |
4764 channel = Internal_GetChannel(source); | |
4765 if(-1 == channel) | |
4766 { | |
4767 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4768 return -1; | |
4769 } | |
4770 | |
4771 return Internal_PausedChannel(channel); | |
4772 } | |
4773 | |
4774 | |
4775 | |
4776 | |
4777 | |
4778 | |
4779 /* Private function for Updating ALmixer. | |
4780 * This is a very big and ugly function. | |
4781 * It should return the number of buffers that were | |
4782 * queued during the call. The value might be | |
4783 * used to guage how long you might wait to | |
4784 * call the next update loop in case you are worried | |
4785 * about preserving CPU cycles. The idea is that | |
4786 * when a buffer is queued, there was probably some | |
4787 * CPU intensive looping which took awhile. | |
4788 * 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
|
4789 * Timing the call with ALmixer_GetTicks() would produce |
0 | 4790 * more accurate information. |
4791 * Returns a negative value if there was an error, | |
4792 * the value being the number of errors. | |
4793 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4794 static ALint Update_ALmixer(void* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4795 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4796 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4797 ALint error_flag = 0; |
0 | 4798 ALenum error; |
4799 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4800 ALint i=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4801 |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4804 #endif |
0 | 4805 if(0 == ALmixer_Initialized) |
4806 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4807 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4808 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4809 #endif |
0 | 4810 return 0; |
4811 } | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4812 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4813 /* Bypass if in interruption event */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4814 if(NULL == alcGetCurrentContext()) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4815 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4816 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4817 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4818 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4819 return 0; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4820 } |
0 | 4821 |
4822 /* Check the quick flag to see if anything needs updating */ | |
4823 /* If anything is playing, then we have to do work */ | |
4824 if( 0 == Is_Playing_global) | |
4825 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4826 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4827 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4828 #endif |
0 | 4829 return 0; |
4830 } | |
4831 /* Clear error */ | |
4832 if((error = alGetError()) != AL_NO_ERROR) | |
4833 { | |
4834 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
|
4835 alGetString(error)); |
0 | 4836 } |
4837 alGetError(); | |
4838 | |
4839 for(i=0; i<Number_of_Channels_global; i++) | |
4840 { | |
4841 if( ALmixer_Channel_List[i].channel_in_use ) | |
4842 { | |
4843 | |
4844 /* For simplicity, before we do anything else, | |
4845 * we can check the timeout and fading values | |
4846 * and do the appropriate things | |
4847 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4848 ALuint current_time = ALmixer_GetTicks(); |
0 | 4849 |
4850 /* Check to see if we need to halt due to Timed play */ | |
4851 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
4852 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4853 ALuint target_time = (ALuint)ALmixer_Channel_List[i].expire_ticks |
0 | 4854 + ALmixer_Channel_List[i].start_time; |
4855 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4856 AL_SOURCE_STATE, &state); | |
4857 if((error = alGetError()) != AL_NO_ERROR) | |
4858 { | |
4859 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
|
4860 alGetString(error)); |
0 | 4861 } |
4862 | |
4863 /* Check the time, and also make sure that it is not | |
4864 * paused (if paused, we don't want to make the | |
4865 * evaluation because when resumed, we will adjust | |
4866 * the times to compensate for the pause). | |
4867 */ | |
4868 if( (current_time >= target_time) | |
4869 && (state != AL_PAUSED) ) | |
4870 { | |
4871 /* 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
|
4872 Internal_HaltChannel(i, AL_FALSE); |
0 | 4873 if((error = alGetError()) != AL_NO_ERROR) |
4874 { | |
4875 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
|
4876 alGetString(error)); |
0 | 4877 } |
4878 | |
4879 /* Everything should be done so go on to the next loop */ | |
4880 continue; | |
4881 } | |
4882 } /* End if time expired check */ | |
4883 | |
4884 /* Check to see if we need to adjust the volume for fading */ | |
4885 if( ALmixer_Channel_List[i].fade_enabled ) | |
4886 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4887 ALuint target_time = ALmixer_Channel_List[i].fade_expire_ticks |
0 | 4888 + ALmixer_Channel_List[i].fade_start_time; |
4889 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4890 AL_SOURCE_STATE, &state); | |
4891 if((error = alGetError()) != AL_NO_ERROR) | |
4892 { | |
4893 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
|
4894 alGetString(error)); |
0 | 4895 } |
4896 | |
4897 /* Check the time, and also make sure that it is not | |
4898 * paused (if paused, we don't want to make the | |
4899 * evaluation because when resumed, we will adjust | |
4900 * the times to compensate for the pause). | |
4901 */ | |
4902 if(state != AL_PAUSED) | |
4903 { | |
4904 ALfloat t; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4905 ALuint delta_time; |
0 | 4906 ALfloat current_volume; |
4907 if(current_time >= target_time) | |
4908 { | |
4909 /* Need to constrain value to the end time | |
4910 * (can't go pass the value for calculations) | |
4911 */ | |
4912 current_time = target_time; | |
4913 /* We can disable the fade flag now */ | |
4914 ALmixer_Channel_List[i].fade_enabled = 0; | |
4915 } | |
4916 /* Use the linear interpolation formula: | |
4917 * X = (1-t)x0 + tx1 | |
4918 * where x0 would be the start value | |
4919 * and x1 is the final value | |
4920 * and t is delta_time*inv_time (adjusts 0 <= time <= 1) | |
4921 * delta_time = current_time-start_time | |
4922 * inv_time = 1/ (end_time-start_time) | |
4923 * so t = current_time-start_time / (end_time-start_time) | |
4924 * | |
4925 */ | |
4926 delta_time = current_time - ALmixer_Channel_List[i].fade_start_time; | |
4927 t = (ALfloat) delta_time * ALmixer_Channel_List[i].fade_inv_time; | |
4928 current_volume = (1.0f-t) * ALmixer_Channel_List[i].fade_start_volume | |
4929 + t * ALmixer_Channel_List[i].fade_end_volume; | |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
4930 /* |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
4931 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); |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
4932 */ |
0 | 4933 /* Set the volume */ |
4934 alSourcef(ALmixer_Channel_List[i].alsource, | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
4935 AL_GAIN, current_volume); |
0 | 4936 if((error = alGetError()) != AL_NO_ERROR) |
4937 { | |
4938 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
|
4939 alGetString(error)); |
0 | 4940 } |
4941 | |
4942 /* | |
4943 fprintf(stderr, "Current time =%d\n", current_time); | |
4944 fprintf(stderr, "Current vol=%f on channel %d\n", current_volume, i); | |
4945 */ | |
4946 } /* End if not PAUSED */ | |
4947 } /* End if fade_enabled */ | |
4948 | |
4949 | |
4950 /* Okay, now that the time expired and fading stuff | |
4951 * is done, do the rest of the hard stuff | |
4952 */ | |
4953 | |
4954 | |
4955 /* For predecoded, check to see if done */ | |
4956 if( ALmixer_Channel_List[i].almixer_data->decoded_all ) | |
4957 { | |
4958 | |
4959 #if 0 | |
4960 /********* Remove this **********/ | |
4961 ALint buffers_processed; | |
4962 ALint buffers_still_queued; | |
4963 fprintf(stderr, "For Predecoded\n"); | |
4964 | |
4965 alGetSourcei( | |
4966 ALmixer_Channel_List[i].alsource, | |
4967 AL_SOURCE_STATE, &state | |
4968 ); | |
4969 switch(state) { | |
4970 case AL_PLAYING: | |
4971 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
4972 break; | |
4973 case AL_PAUSED: | |
4974 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
4975 break; | |
4976 case AL_STOPPED: | |
4977 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
4978 break; | |
4979 case AL_INITIAL: | |
4980 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
4981 break; | |
4982 default: | |
4983 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
4984 break; | |
4985 } | |
4986 | |
4987 alGetSourcei( | |
4988 ALmixer_Channel_List[i].alsource, | |
4989 AL_BUFFERS_PROCESSED, &buffers_processed | |
4990 ); | |
4991 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
4992 | |
4993 alGetSourcei( | |
4994 ALmixer_Channel_List[i].alsource, | |
4995 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4996 ); | |
4997 | |
4998 /******** END REMOVE *******/ | |
4999 #endif | |
5000 /* FIXME: Ugh! Somewhere an alError is being thrown ("Invalid Enum Value"), but I can't | |
5001 * find it. It only seems to be thrown for OS X. I placed error messages after every al* | |
5002 * command I could find in the above loops, but the error doesn't seem to show | |
5003 * up until around here. I mistook it for a get queued buffers | |
5004 * error in OS X. I don't think there's an error down there. | |
5005 * For now, I'm clearing the error here. | |
5006 */ | |
5007 | |
5008 if((error = alGetError()) != AL_NO_ERROR) | |
5009 { | |
5010 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
|
5011 alGetString(error)); |
0 | 5012 } |
5013 | |
5014 | |
5015 alGetSourcei( | |
5016 ALmixer_Channel_List[i].alsource, | |
5017 AL_SOURCE_STATE, &state | |
5018 ); | |
5019 if((error = alGetError()) != AL_NO_ERROR) | |
5020 { | |
5021 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
|
5022 alGetString(error)); |
0 | 5023 } |
5024 | |
5025 | |
5026 if(AL_STOPPED == state) | |
5027 { | |
5028 /* Playback has ended. | |
5029 * Loop if necessary, or launch callback | |
5030 * and clear channel (or clear channel and | |
5031 * then launch callback?) | |
5032 */ | |
5033 | |
5034 | |
5035 /* Need to check for loops */ | |
5036 if(ALmixer_Channel_List[i].loops != 0) | |
5037 { | |
5038 /* Corner Case: If the buffer has | |
5039 * been modified using Seek, | |
5040 * the loop will start at the seek | |
5041 * position. | |
5042 */ | |
5043 if(ALmixer_Channel_List[i].loops != -1) | |
5044 { | |
5045 ALmixer_Channel_List[i].loops--; | |
5046 } | |
5047 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5048 if((error = alGetError()) != AL_NO_ERROR) | |
5049 { | |
5050 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
|
5051 alGetString(error)); |
0 | 5052 } |
5053 continue; | |
5054 } | |
5055 /* No loops. End play. */ | |
5056 else | |
5057 { | |
5058 /* Problem: It seems that when mixing | |
5059 * streamed and predecoded sources, | |
5060 * the previous instance lingers, | |
5061 * so we need to force remove | |
5062 * the data from the source. | |
5063 * The sharing problem | |
5064 * occurs when a previous predecoded buffer is played on | |
5065 * a source, and then a streamed source is played later | |
5066 * on that same source. OpenAL isn't consistently | |
5067 * removing the previous buffer so both get played. | |
5068 * (Different dists seem to have different quirks. | |
5069 * The problem might lead to crashes in the worst case.) | |
5070 */ | |
5071 /* Additional problem: There is another | |
5072 * inconsistency among OpenAL distributions. | |
5073 * Both Loki and Creative Windows seem to keep | |
5074 * the buffer queued which requires removing. | |
5075 * But the Creative Macintosh version does | |
5076 * not have any buffer queued after play | |
5077 * and it returns the error: Invalid Enum Value | |
5078 * if I try to unqueue it. | |
5079 * So I'm going to put in a check to see if I | |
5080 * can detect any buffers queued first | |
5081 * and then unqueue them if I can see them. | |
5082 * Additional note: The new CoreAudio based | |
5083 * implementation leaves it's buffer queued | |
5084 * like Loki and Creative Windows. But | |
5085 * considering all the problems I'm having | |
5086 * with the different distributions, this | |
5087 * check seems reasonable. | |
5088 */ | |
5089 ALint buffers_still_queued; | |
5090 if((error = alGetError()) != AL_NO_ERROR) | |
5091 { | |
5092 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
|
5093 alGetString(error)); |
0 | 5094 } |
5095 | |
5096 alGetSourcei( | |
5097 ALmixer_Channel_List[i].alsource, | |
5098 AL_BUFFERS_QUEUED, &buffers_still_queued | |
5099 ); | |
5100 if((error = alGetError()) != AL_NO_ERROR) | |
5101 { | |
5102 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
|
5103 alGetString(error)); |
0 | 5104 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
|
5105 alGetString(error) ); |
0 | 5106 error_flag--; |
5107 } | |
5108 if(buffers_still_queued > 0) | |
5109 { | |
1 | 5110 |
5111 #if 0 /* This triggers an error in OS X Core Audio. */ | |
5112 alSourceUnqueueBuffers( | |
5113 ALmixer_Channel_List[i].alsource, | |
5114 1, | |
5115 ALmixer_Channel_List[i].almixer_data->buffer | |
5116 ); | |
5117 #else | |
5118 /* fprintf(stderr, "In the Bob Aron section...about to clear source\n"); | |
0 | 5119 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 5120 */ |
0 | 5121 /* Rather than force unqueuing the buffer, let's see if |
5122 * setting the buffer to none works (the OpenAL 1.0 | |
5123 * Reference Annotation suggests this should work). | |
5124 */ | |
5125 alSourcei(ALmixer_Channel_List[i].alsource, | |
5126 AL_BUFFER, AL_NONE); | |
5127 /* | |
5128 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5129 */ | |
1 | 5130 #endif |
0 | 5131 if((error = alGetError()) != AL_NO_ERROR) |
5132 { | |
5133 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
|
5134 alGetString(error)); |
0 | 5135 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
|
5136 alGetString(error) ); |
0 | 5137 error_flag--; |
5138 } | |
5139 | |
5140 } | |
5141 | |
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
|
5142 /* 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
|
5143 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
|
5144 |
0 | 5145 Clean_Channel(i); |
5146 /* Subtract counter */ | |
5147 Is_Playing_global--; | |
5148 | |
5149 | |
5150 /* We're done for this loop. | |
5151 * Go to next channel | |
5152 */ | |
5153 continue; | |
5154 } | |
5155 continue; | |
5156 } | |
5157 } /* End if decoded_all */ | |
5158 /* For streamed */ | |
5159 else | |
5160 { | |
5161 ALint buffers_processed; | |
5162 ALint buffers_still_queued; | |
5163 ALint current_buffer_id; | |
5164 | |
5165 ALuint unqueued_buffer_id; | |
28
60500a33735a
Initial backend changes to decouple assumption of 1 buffer queued per channel / per pass. API will eventually be changed/broken to support this.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
27
diff
changeset
|
5166 ALuint number_of_buffers_to_queue_this_pass = ALmixer_Channel_List[i].almixer_data->num_target_buffers_per_pass; |
60500a33735a
Initial backend changes to decouple assumption of 1 buffer queued per channel / per pass. API will eventually be changed/broken to support this.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
27
diff
changeset
|
5167 ALuint current_count_of_buffer_queue_passes = 0; |
60500a33735a
Initial backend changes to decouple assumption of 1 buffer queued per channel / per pass. API will eventually be changed/broken to support this.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
27
diff
changeset
|
5168 |
0 | 5169 #if 0 |
5170 /********* Remove this **********/ | |
5171 fprintf(stderr, "For Streamed\n"); | |
5172 | |
5173 alGetSourcei( | |
5174 ALmixer_Channel_List[i].alsource, | |
5175 AL_SOURCE_STATE, &state | |
5176 ); | |
5177 switch(state) { | |
5178 case AL_PLAYING: | |
5179 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
5180 break; | |
5181 case AL_PAUSED: | |
5182 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
5183 break; | |
5184 case AL_STOPPED: | |
5185 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
5186 break; | |
5187 case AL_INITIAL: | |
5188 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
5189 break; | |
5190 default: | |
5191 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
5192 break; | |
5193 } | |
5194 /******** END REMOVE *******/ | |
5195 #endif | |
5196 /* Get the number of buffers still queued */ | |
5197 alGetSourcei( | |
5198 ALmixer_Channel_List[i].alsource, | |
5199 AL_BUFFERS_QUEUED, &buffers_still_queued | |
5200 ); | |
5201 if((error = alGetError()) != AL_NO_ERROR) | |
5202 { | |
5203 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
|
5204 alGetString(error)); |
0 | 5205 } |
5206 /* Get the number of buffers processed | |
5207 * so we know if we need to refill | |
5208 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5209 /* 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
|
5210 * 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
|
5211 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5212 // fprintf(stderr, "calling AL_BUFFERS_PROCESSED on source:%d", ALmixer_Channel_List[i].alsource); |
0 | 5213 alGetSourcei( |
5214 ALmixer_Channel_List[i].alsource, | |
5215 AL_BUFFERS_PROCESSED, &buffers_processed | |
5216 ); | |
5217 if((error = alGetError()) != AL_NO_ERROR) | |
5218 { | |
5219 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
|
5220 alGetString(error)); |
0 | 5221 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5222 // fprintf(stderr, "finished AL_BUFFERS_PROCESSED, buffers_processed=%d", buffers_processed); |
0 | 5223 |
5224 /* WTF!!! The Nvidia distribution is failing on the alGetSourcei(source, AL_BUFFER, buf_id) call. | |
5225 * I need this call to figure out which buffer OpenAL is currently playing. | |
5226 * It keeps returning an "Invalid Enum" error. | |
5227 * This is totally inane! It's a basic query. | |
5228 * By the spec, this functionality is not explicitly defined so Nvidia refuses to | |
5229 * fix this behavior, even though all other distributions work fine with this. | |
5230 * The only workaround for this is for | |
5231 * a significant rewrite of my code which requires me to | |
5232 * duplicate the OpenAL queued buffers state with my own | |
5233 * code and try to derive what the current playing buffer is by indirect observation of | |
5234 * looking at buffers_processed. But of course this has a ton of downsides since my | |
5235 * queries do not give me perfect timing of what OpenAL is actually doing and | |
5236 * the fact that some of the distributions seem to have buffer queuing problems | |
5237 * with their query results (CoreAudio). This also means a ton of extra code | |
5238 * on my side. The lack of support of a 1 line call has required me to | |
5239 * implement yet another entire state machine. <sigh> | |
5240 */ | |
5241 #if 0 /* This code will not work until possibly OpenAL 1.1 because of Nvidia */ | |
5242 /* Get the id to the current buffer playing */ | |
5243 alGetSourcei( | |
5244 ALmixer_Channel_List[i].alsource, | |
5245 AL_BUFFER, ¤t_buffer_id | |
5246 ); | |
5247 if((error = alGetError()) != AL_NO_ERROR) | |
5248 { | |
5249 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
|
5250 alGetString(error)); |
0 | 5251 } |
5252 | |
5253 /* Before the hard stuff, check to see if the | |
5254 * current queued AL buffer has changed. | |
5255 * If it has, we should launch a data callback if | |
5256 * necessary | |
5257 */ | |
5258 if( ((ALuint)current_buffer_id) != | |
5259 ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5260 { | |
5261 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5262 = (ALuint)current_buffer_id; | |
5263 | |
5264 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5265 } | |
5266 #else | |
5267 /* Only do this if "access_data" was requested (i.e. the circular_buffer!=NULL) | |
5268 * And if one of the two are true: | |
5269 * Either buffers_processed > 0 (because the current_buffer might have changed) | |
5270 * or if the current_buffer==0 (because we are in an initial state or recovering from | |
5271 * a buffer underrun) | |
5272 */ | |
5273 if((ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5274 && ( | |
5275 (buffers_processed > 0) || (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5276 ) | |
5277 ) | |
5278 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5279 ALint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5280 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5281 ALubyte is_out_of_sync = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5282 ALuint my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
1 | 5283 /* Ugh, I have to deal with signed/unsigned mismatch here. */ |
5284 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
|
5285 ALuint unplayed_buffers; |
1 | 5286 if(buffers_unplayed_int < 0) |
5287 { | |
5288 unplayed_buffers = 0; | |
5289 } | |
5290 else | |
5291 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5292 unplayed_buffers = (ALuint)buffers_unplayed_int; |
1 | 5293 } |
0 | 5294 /* |
5295 fprintf(stderr, "Queue in processed check, before pop, buffers_processed=%d\n", buffers_processed); | |
5296 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5297 */ | |
5298 /* We can't make any determinations solely based on the number of buffers_processed | |
5299 * because currently, we only unqueue 1 buffer per loop. That means if 2 or more | |
5300 * buffers became processed in one loop, the following loop, we would have | |
5301 * at least that_many-1 buffers_processed (plus possible new processed). | |
5302 * If we tried to just remove 1 buffer from our queue, we would be incorrect | |
5303 * because we would not actually reflect the current playing buffer. | |
5304 * So the solution seems to be to make sure our queue is the same size | |
5305 * as the number of buffers_queued-buffers_processed, and return the head of our queue | |
5306 * as the current playing buffer. | |
5307 */ | |
5308 /* Also, we have a corner case. When we first start playing or if we have | |
5309 * a buffer underrun, we have not done a data callback. | |
5310 * In this case, we need to see if there is any new data in our queue | |
5311 * and if so, launch that data callback. | |
5312 */ | |
5313 /* Warning, this code risks the possibility of no data callback being fired if | |
5314 * the system is really late (or skipped buffers). | |
5315 */ | |
5316 | |
5317 /* First, let's syncronize our queue with the OpenAL queue */ | |
5318 #if 0 | |
5319 fprintf(stderr, "inside, Buffers processed=%d, Buffers queued=%d, my queue=%d\n", | |
5320 buffers_processed, buffers_still_queued, my_queue_size); | |
1 | 5321 #endif |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5322 is_out_of_sync = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5323 for(k=0; k<buffers_processed; k++) |
0 | 5324 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5325 queue_ret_flag = CircularQueueUnsignedInt_PopFront( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5326 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
|
5327 if(0 == queue_ret_flag) |
0 | 5328 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5329 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
|
5330 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5331 } |
0 | 5332 my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
5333 /* We have several possibilities we need to handle: | |
5334 * 1) We are in an initial state or underrun and need to do a data callback on the head. | |
5335 * 2) We were out of sync and need to do a new data callback on the new head. | |
5336 * 3) We were not out of sync but just had left over processed buffers which caused us to | |
5337 * fall in this block of code. (Don't do anything.) | |
5338 */ | |
5339 if( (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) || (1 == is_out_of_sync) ) | |
5340 { | |
5341 if(my_queue_size > 0) | |
5342 { | |
5343 current_buffer_id = CircularQueueUnsignedInt_Front( | |
5344 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5345 if(0 == current_buffer_id) | |
5346 { | |
5347 fprintf(stderr, "53a Internal Error, current_buffer_id=0 when it shouldn't be 0\n"); | |
5348 } | |
5349 /* | |
5350 else | |
5351 { | |
5352 fprintf(stderr, "Queue in processed check, after pop\n"); | |
5353 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5354 } | |
5355 */ | |
5356 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5357 = (ALuint)current_buffer_id; | |
5358 | |
5359 #if 0 | |
5360 /* Remove me...only for checking...doesn't work on Nvidia */ | |
5361 { | |
5362 ALuint real_id; | |
5363 alGetSourcei( | |
5364 ALmixer_Channel_List[i].alsource, | |
5365 AL_BUFFER, &real_id | |
5366 ); | |
5367 alGetError(); | |
5368 fprintf(stderr, "Callback fired on data buffer=%d, real_id shoud be=%d\n", current_buffer_id, real_id); | |
5369 } | |
5370 #endif | |
5371 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5372 } | |
5373 else | |
5374 { | |
1 | 5375 /* |
0 | 5376 fprintf(stderr, "53b, Notice/Warning:, OpenAL queue has been depleted.\n"); |
1 | 5377 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
5378 */ | |
0 | 5379 /* In this case, we might either be in an underrun or finished with playback */ |
5380 ALmixer_Channel_List[i].almixer_data->current_buffer = 0; | |
5381 } | |
5382 } | |
5383 } | |
5384 #endif | |
5385 | |
5386 | |
5387 | |
5388 /* Just a test - remove | |
5389 if( ALmixer_Channel_List[i].loops > 0) | |
5390 { | |
5391 fprintf(stderr, ">>>>>>>>>>>>>>>Loops = %d\n", | |
5392 ALmixer_Channel_List[i].loops); | |
5393 } | |
5394 */ | |
5395 #if 0 | |
5396 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
5397 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5398 #endif | |
5399 /* We've used up a buffer so we need to unqueue and replace */ | |
5400 /* Okay, it gets more complicated here: | |
5401 * We need to Queue more data | |
5402 * if buffers_processed > 0 or | |
5403 * if num_of_buffers_in_use < NUMBER_OF_QUEUE_BUFFERS | |
5404 * but we don't do this if at EOF, | |
5405 * except when there is looping | |
5406 */ | |
28
60500a33735a
Initial backend changes to decouple assumption of 1 buffer queued per channel / per pass. API will eventually be changed/broken to support this.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
27
diff
changeset
|
5407 |
60500a33735a
Initial backend changes to decouple assumption of 1 buffer queued per channel / per pass. API will eventually be changed/broken to support this.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
27
diff
changeset
|
5408 /* NEW FEATURE: Try to queue up more buffers per pass, allowing the size of the buffer to be decoupled. */ |
60500a33735a
Initial backend changes to decouple assumption of 1 buffer queued per channel / per pass. API will eventually be changed/broken to support this.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
27
diff
changeset
|
5409 /* TODO: Optimization: If number of available buffers (max_buffers-buffers_in_use), adjust the number of buffers to queue for this pass. */ |
60500a33735a
Initial backend changes to decouple assumption of 1 buffer queued per channel / per pass. API will eventually be changed/broken to support this.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
27
diff
changeset
|
5410 for(current_count_of_buffer_queue_passes=0; current_count_of_buffer_queue_passes<number_of_buffers_to_queue_this_pass; current_count_of_buffer_queue_passes++) |
60500a33735a
Initial backend changes to decouple assumption of 1 buffer queued per channel / per pass. API will eventually be changed/broken to support this.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
27
diff
changeset
|
5411 { |
60500a33735a
Initial backend changes to decouple assumption of 1 buffer queued per channel / per pass. API will eventually be changed/broken to support this.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
27
diff
changeset
|
5412 |
0 | 5413 /* For this to work, we must rely on EVERYTHING |
5414 * else to unset the EOF if there is looping. | |
5415 * Remember, even Play() must do this | |
5416 */ | |
5417 | |
5418 /* If not EOF, then we are still playing. | |
5419 * Inside, we might find num_of_buffers < NUM...QUEUE_BUF.. | |
5420 * or buffers_process > 0 | |
5421 * in which case we queue up. | |
5422 * We also might find no buffers we need to fill, | |
5423 * in which case we just keep going | |
5424 */ | |
5425 if( ! ALmixer_Channel_List[i].almixer_data->eof) | |
5426 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5427 ALuint bytes_returned; |
0 | 5428 /* We have a priority. We first must assign |
5429 * unused buffers in reserve. If there is nothing | |
5430 * left, then we may unqueue buffers. We can't | |
5431 * do it the other way around because we will | |
5432 * lose the pointer to the unqueued buffer | |
5433 */ | |
5434 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5435 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5436 { | |
1 | 5437 #if 0 |
0 | 5438 fprintf(stderr, "Getting more data in NOT_EOF and num_buffers_in_use (%d) < max_queue (%d)\n", |
5439 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5440 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5441 #endif |
0 | 5442 /* Going to add an unused packet. |
5443 * Grab next packet */ | |
5444 bytes_returned = GetMoreData( | |
5445 ALmixer_Channel_List[i].almixer_data, | |
5446 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5447 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5448 ); | |
5449 } | |
5450 /* For processed > 0 */ | |
5451 else if(buffers_processed > 0) | |
5452 { | |
5453 /* Unqueue only 1 buffer for now. | |
5454 * If there are more than one, | |
5455 * let the next Update pass deal with it | |
5456 * so we don't stall the program for too long. | |
5457 */ | |
5458 #if 0 | |
5459 fprintf(stderr, "About to Unqueue, Buffers processed = %d\n", buffers_processed); | |
5460 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5461 fprintf(stderr, "Unqueuing a buffer\n"); | |
5462 #endif | |
5463 alSourceUnqueueBuffers( | |
5464 ALmixer_Channel_List[i].alsource, | |
5465 1, &unqueued_buffer_id | |
5466 ); | |
5467 if((error = alGetError()) != AL_NO_ERROR) | |
5468 { | |
5469 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
|
5470 alGetString(error)); |
0 | 5471 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
|
5472 alGetString(error) ); |
0 | 5473 error_flag--; |
5474 } | |
5475 /* | |
5476 fprintf(stderr, "Right after unqueue..."); | |
5477 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5478 fprintf(stderr, "Getting more data for NOT_EOF, max_buffers filled\n"); | |
5479 */ | |
5480 /* Grab unqueued packet */ | |
5481 bytes_returned = GetMoreData( | |
5482 ALmixer_Channel_List[i].almixer_data, | |
5483 unqueued_buffer_id); | |
5484 } | |
5485 /* We are still streaming, but currently | |
5486 * don't need to fill any buffers */ | |
5487 else | |
5488 { | |
5489 /* Might want to check state */ | |
5490 /* In case the playback stopped, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5491 * we need to resume |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5492 * a.k.a. buffer underrun |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5493 */ |
1 | 5494 #if 1 |
5495 /* Try not refetching the state here because I'm getting a duplicate | |
5496 buffer playback (hiccup) */ | |
0 | 5497 alGetSourcei( |
5498 ALmixer_Channel_List[i].alsource, | |
5499 AL_SOURCE_STATE, &state | |
5500 ); | |
1 | 5501 if((error = alGetError()) != AL_NO_ERROR) |
5502 { | |
5503 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
|
5504 alGetString(error)); |
1 | 5505 } |
5506 /* Get the number of buffers processed | |
5507 */ | |
5508 alGetSourcei( | |
5509 ALmixer_Channel_List[i].alsource, | |
5510 AL_BUFFERS_PROCESSED, | |
5511 &buffers_processed | |
5512 ); | |
5513 if((error = alGetError()) != AL_NO_ERROR) | |
5514 { | |
5515 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
|
5516 alGetString(error)); |
1 | 5517 } |
5518 #endif | |
0 | 5519 if(AL_STOPPED == state) |
5520 { | |
5521 /* Resuming in not eof, but nothing to buffer */ | |
1 | 5522 |
5523 /* Okay, here's another lately discovered problem: | |
5524 * I can't find it in the spec, but for at least some of the | |
5525 * implementations, if I call play on a stopped source that | |
5526 * has processed buffers, all those buffers get marked as unprocessed | |
5527 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5528 * processed, on resume, the earlier 24 buffers will get replayed, | |
5529 * causing a "hiccup" like sound in the playback. | |
5530 * To avoid this, I must unqueue all processed buffers before | |
5531 * calling play. But to complicate things, I need to worry about resyncing | |
5532 * the circular queue with this since I designed this thing | |
5533 * with some correlation between the two. However, I might | |
5534 * have already handled this, so I will try writing this code without | |
5535 * syncing for now. | |
5536 * There is currently an assumption that a buffer | |
5537 * was queued above so I actually have something | |
5538 * to play. | |
5539 */ | |
5540 ALint temp_count; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5541 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5542 fprintf(stderr, "STOPPED1, need to clear processed=%d, status is:\n", buffers_processed); |
1 | 5543 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
|
5544 #endif |
1 | 5545 for(temp_count=0; temp_count<buffers_processed; temp_count++) |
5546 { | |
5547 alSourceUnqueueBuffers( | |
5548 ALmixer_Channel_List[i].alsource, | |
5549 1, &unqueued_buffer_id | |
5550 ); | |
5551 if((error = alGetError()) != AL_NO_ERROR) | |
5552 { | |
5553 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
|
5554 alGetString(error)); |
1 | 5555 error_flag--; |
5556 } | |
5557 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5558 #if 0 |
1 | 5559 fprintf(stderr, "After unqueue clear...:\n"); |
5560 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
|
5561 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5562 /* 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
|
5563 * 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
|
5564 * 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
|
5565 * 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
|
5566 * no buffers in queue. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5567 * 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
|
5568 * Then we need to resume playing. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5569 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5570 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5571 int buffers_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5572 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5573 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5574 AL_BUFFERS_QUEUED, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5575 &buffers_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5576 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5577 |
1 | 5578 if((error = alGetError()) != AL_NO_ERROR) |
5579 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5580 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
|
5581 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5582 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5583 assert(buffers_queued == 0); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5584 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
|
5585 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5586 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5587 /* 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
|
5588 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
|
5589 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5590 /* 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
|
5591 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5592 ALmixer_Channel_List[i].almixer_data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5593 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
|
5594 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5595 /* 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
|
5596 * 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
|
5597 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5598 if(bytes_returned > 0) |
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 /* Queue up the new data */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5601 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5602 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5603 1, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5604 &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
|
5605 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5606 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5607 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5608 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
|
5609 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5610 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5611 /* 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
|
5612 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
|
5613 |
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 /* 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
|
5616 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
|
5617 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5618 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5619 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
|
5620 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5621 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
|
5622 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
|
5623 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5624 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5625 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5626 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
|
5627 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
|
5628 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5629 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5630 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5631 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5632 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5633 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5634 /* Resume playback from underrun */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5635 alSourcePlay(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5636 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5637 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5638 fprintf(stderr, "55Tbesting error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5639 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5640 } |
1 | 5641 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5642 |
0 | 5643 } |
5644 /* Let's escape to the next loop. | |
5645 * All code below this point is for queuing up | |
5646 */ | |
5647 /* | |
1 | 5648 fprintf(stderr, "Entry: Nothing to do...continue\n\n"); |
5649 */ | |
0 | 5650 continue; |
5651 } | |
5652 /* We now know we have to fill an available | |
5653 * buffer. | |
5654 */ | |
5655 | |
5656 /* In the previous branch, we just grabbed more data. | |
5657 * Let's check it to make sure it's okay, | |
5658 * and then queue it up | |
5659 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5660 /* This check doesn't work anymore because it is now ALuint */ |
0 | 5661 #if 0 |
5662 if(-1 == bytes_returned) | |
5663 { | |
5664 /* Problem occurred...not sure what to do */ | |
5665 /* Go to next loop? */ | |
5666 error_flag--; | |
5667 /* Set the eof flag to force a quit so | |
5668 * we don't get stuck in an infinite loop | |
5669 */ | |
5670 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5671 continue; | |
5672 } | |
5673 #endif | |
5674 /* This is a special case where we've run | |
5675 * out of data. We should check for loops | |
5676 * and get more data. If there is no loop, | |
5677 * then do nothing and wait for future | |
5678 * update passes to handle the EOF. | |
5679 * The advantage of handling the loop here | |
5680 * instead of waiting for play to stop is | |
5681 * that we should be able to keep the buffer | |
5682 * filled. | |
5683 */ | |
5684 #if 0 | |
5685 else if(0 == bytes_returned) | |
5686 #endif | |
5687 if(0 == bytes_returned) | |
5688 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5689 /* |
0 | 5690 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
|
5691 */ |
0 | 5692 /* Check for loops */ |
5693 if( ALmixer_Channel_List[i].loops != 0 ) | |
5694 { | |
5695 /* We have to loop, so rewind | |
5696 * and fetch more data | |
5697 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5698 /* |
0 | 5699 fprintf(stderr, "Rewinding data\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5700 */ |
0 | 5701 if(0 == Sound_Rewind( |
5702 ALmixer_Channel_List[i].almixer_data->sample)) | |
5703 { | |
5704 fprintf(stderr, "Rewinding failed\n"); | |
5705 ALmixer_SetError( Sound_GetError() ); | |
5706 ALmixer_Channel_List[i].loops = 0; | |
5707 error_flag--; | |
5708 /* We'll continue on because we do have some valid data */ | |
5709 continue; | |
5710 } | |
5711 /* Remember to reset the data->eof flag */ | |
5712 ALmixer_Channel_List[i].almixer_data->eof = 0; | |
5713 if(ALmixer_Channel_List[i].loops > 0) | |
5714 { | |
5715 ALmixer_Channel_List[i].loops--; | |
5716 } | |
5717 /* Try grabbing another packet now. | |
5718 * Since we may have already unqueued a | |
5719 * buffer, we don't want to lose it. | |
5720 */ | |
5721 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5722 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5723 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5724 /* |
0 | 5725 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
|
5726 */ |
0 | 5727 /* Grab next packet */ |
5728 bytes_returned = GetMoreData( | |
5729 ALmixer_Channel_List[i].almixer_data, | |
5730 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5731 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5732 ); | |
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 unused 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 /* Refilling unqueued packet */ | |
5738 else | |
5739 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5740 /* |
0 | 5741 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
|
5742 */ |
0 | 5743 /* Grab next packet */ |
5744 bytes_returned = GetMoreData( | |
5745 ALmixer_Channel_List[i].almixer_data, | |
5746 unqueued_buffer_id); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5747 /* |
0 | 5748 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
|
5749 */ |
0 | 5750 } |
5751 /* Another error check */ | |
5752 /* | |
5753 if(bytes_returned <= 0) | |
5754 */ | |
5755 if(0 == bytes_returned) | |
5756 { | |
5757 fprintf(stderr, "??????????ERROR\n"); | |
5758 ALmixer_SetError("Could not loop because after rewind, no data could be retrieved"); | |
5759 /* Problem occurred...not sure what to do */ | |
5760 /* Go to next loop? */ | |
5761 error_flag--; | |
5762 /* Set the eof flag to force a quit so | |
5763 * we don't get stuck in an infinite loop | |
5764 */ | |
5765 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5766 continue; | |
5767 } | |
5768 /* We made it to the end. We still need | |
5769 * to BufferData, so let this branch | |
5770 * fall into the next piece of | |
5771 * code below which will handle that | |
5772 */ | |
5773 | |
5774 | |
5775 } /* END loop check */ | |
5776 else | |
5777 { | |
5778 /* No more loops to do. | |
5779 * EOF flag should be set. | |
5780 * Just go to next loop and | |
5781 * let things be handled correctly | |
5782 * in future update calls | |
5783 */ | |
1 | 5784 /* |
0 | 5785 fprintf(stderr, "SHOULD BE EOF\n"); |
5786 | |
5787 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
1 | 5788 */ |
0 | 5789 continue; |
5790 } | |
5791 } /* END if bytes_returned == 0 */ | |
5792 /********* Possible trouble point. I might be queueing empty buffers on the mac. | |
5793 * This check doesn't say if the buffer is valid. Only the EOF assumption is a clue at this point | |
5794 */ | |
5795 /* Fall here */ | |
5796 /* Everything is normal. We aren't | |
5797 * at an EOF, but need to simply | |
5798 * queue more data. The data is already checked for good, | |
5799 * so queue it up */ | |
5800 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5801 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5802 { | |
5803 /* Keep count of how many buffers we have | |
5804 * to queue so we can return the value | |
5805 */ | |
5806 retval++; | |
1 | 5807 /* |
0 | 5808 fprintf(stderr, "NOT_EOF???, about to Queue more data for num_buffers (%d) < max_queue (%d)\n", |
5809 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5810 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5811 */ |
0 | 5812 alSourceQueueBuffers( |
5813 ALmixer_Channel_List[i].alsource, | |
5814 1, | |
5815 &ALmixer_Channel_List[i].almixer_data->buffer[ | |
5816 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5817 ); | |
5818 if((error = alGetError()) != AL_NO_ERROR) | |
5819 { | |
5820 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
|
5821 alGetString(error)); |
0 | 5822 } |
5823 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5824 * which buffer to show during callbacks (for things like | |
5825 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5826 * data structure. This code will be called only if | |
5827 * "access_data" was set, indicated by whether the queue is NULL. | |
5828 */ | |
5829 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5830 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5831 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5832 // fprintf(stderr, "56d: CircularQueue_PushBack.\n"); |
0 | 5833 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5834 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5835 ALmixer_Channel_List[i].almixer_data->buffer[ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5836 ); | |
5837 if(0 == queue_ret_flag) | |
5838 { | |
5839 fprintf(stderr, "56aSerious internal error: CircularQueue could not push into queue.\n"); | |
5840 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5841 } | |
5842 /* | |
5843 else | |
5844 { | |
5845 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5846 } | |
5847 */ | |
5848 } | |
5849 } | |
5850 /* for processed > 0 */ | |
5851 else | |
5852 { | |
5853 /* Keep count of how many buffers we have | |
5854 * to queue so we can return the value | |
5855 */ | |
5856 retval++; | |
5857 /* | |
5858 fprintf(stderr, "NOT_EOF, about to Queue more data for filled max_queue (%d)\n", | |
5859 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
5860 */ | |
5861 alSourceQueueBuffers( | |
5862 ALmixer_Channel_List[i].alsource, | |
5863 1, &unqueued_buffer_id); | |
5864 if((error = alGetError()) != AL_NO_ERROR) | |
5865 { | |
5866 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
|
5867 alGetString(error) ); |
0 | 5868 error_flag--; |
5869 continue; | |
5870 } | |
5871 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5872 * which buffer to show during callbacks (for things like | |
5873 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5874 * data structure. This code will be called only if | |
5875 * "access_data" was set, indicated by whether the queue is NULL. | |
5876 */ | |
5877 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5878 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5879 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5880 // fprintf(stderr, "56e: CircularQueue_PushBack.\n"); |
0 | 5881 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5882 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5883 unqueued_buffer_id | |
5884 ); | |
5885 if(0 == queue_ret_flag) | |
5886 { | |
5887 fprintf(stderr, "56bSerious internal error: CircularQueue could not push into queue.\n"); | |
5888 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5889 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5890 #if 0 |
0 | 5891 else |
5892 { | |
5893 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5894 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5895 #endif |
0 | 5896 } |
5897 } | |
5898 /* If we used an available buffer queue, | |
5899 * then we need to update the number of them in use | |
5900 */ | |
5901 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5902 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5903 { | |
5904 /* Increment the number of buffers in use */ | |
5905 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use++; | |
5906 } | |
5907 /* Might want to check state */ | |
5908 /* In case the playback stopped, | |
5909 * we need to resume */ | |
1 | 5910 #if 1 |
5911 /* Try not refetching the state here because I'm getting a duplicate | |
5912 buffer playback (hiccup) */ | |
0 | 5913 alGetSourcei( |
5914 ALmixer_Channel_List[i].alsource, | |
5915 AL_SOURCE_STATE, &state | |
5916 ); | |
1 | 5917 if((error = alGetError()) != AL_NO_ERROR) |
5918 { | |
5919 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
|
5920 alGetString(error)); |
1 | 5921 } |
5922 /* Get the number of buffers processed | |
5923 */ | |
5924 alGetSourcei( | |
5925 ALmixer_Channel_List[i].alsource, | |
5926 AL_BUFFERS_PROCESSED, | |
5927 &buffers_processed | |
5928 ); | |
5929 if((error = alGetError()) != AL_NO_ERROR) | |
5930 { | |
5931 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
|
5932 alGetString(error)); |
1 | 5933 } |
5934 #endif | |
0 | 5935 if(AL_STOPPED == state) |
5936 { | |
1 | 5937 /* |
0 | 5938 fprintf(stderr, "Resuming in not eof\n"); |
1 | 5939 */ |
5940 /* Okay, here's another lately discovered problem: | |
5941 * I can't find it in the spec, but for at least some of the | |
5942 * implementations, if I call play on a stopped source that | |
5943 * has processed buffers, all those buffers get marked as unprocessed | |
5944 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5945 * processed, on resume, the earlier 24 buffers will get replayed, | |
5946 * causing a "hiccup" like sound in the playback. | |
5947 * To avoid this, I must unqueue all processed buffers before | |
5948 * calling play. But to complicate things, I need to worry about resyncing | |
5949 * the circular queue with this since I designed this thing | |
5950 * with some correlation between the two. However, I might | |
5951 * have already handled this, so I will try writing this code without | |
5952 * syncing for now. | |
5953 * There is currently an assumption that a buffer | |
5954 * was queued above so I actually have something | |
5955 * to play. | |
5956 */ | |
5957 ALint temp_count; | |
5958 /* | |
5959 fprintf(stderr, "STOPPED2, need to clear processed, status is:\n"); | |
5960 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5961 */ | |
5962 | |
5963 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5964 { | |
5965 alSourceUnqueueBuffers( | |
5966 ALmixer_Channel_List[i].alsource, | |
5967 1, &unqueued_buffer_id | |
5968 ); | |
5969 if((error = alGetError()) != AL_NO_ERROR) | |
5970 { | |
5971 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
|
5972 alGetString(error)); |
1 | 5973 error_flag--; |
5974 } | |
5975 } | |
5976 /* | |
5977 fprintf(stderr, "After unqueue clear...:\n"); | |
5978 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5979 */ | |
5980 | |
5981 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5982 if((error = alGetError()) != AL_NO_ERROR) | |
5983 { | |
5984 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
|
5985 alGetString(error)); |
1 | 5986 } |
0 | 5987 } |
5988 continue; | |
5989 } /* END if( ! eof) */ | |
5990 /* We have hit EOF in the SDL_Sound sample and there | |
5991 * are no more loops. However, there may still be | |
5992 * buffers in the OpenAL queue which still need to | |
5993 * be played out. The following body of code will | |
5994 * determine if play is still happening or | |
5995 * initiate the stop/cleanup sequenece. | |
5996 */ | |
5997 else | |
5998 { | |
5999 /* Let's continue to remove the used up | |
6000 * buffers as they come in. */ | |
6001 if(buffers_processed > 0) | |
6002 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6003 ALint temp_count; |
0 | 6004 /* Do as a for-loop because I don't want |
6005 * to have to create an array for the | |
6006 * unqueued_buffer_id's | |
6007 */ | |
6008 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
6009 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6010 /* |
0 | 6011 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
|
6012 */ |
0 | 6013 alSourceUnqueueBuffers( |
6014 ALmixer_Channel_List[i].alsource, | |
6015 1, &unqueued_buffer_id | |
6016 ); | |
6017 if((error = alGetError()) != AL_NO_ERROR) | |
6018 { | |
6019 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
|
6020 alGetString(error)); |
0 | 6021 } |
6022 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6023 /* |
0 | 6024 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
|
6025 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6026 |
0 | 6027 /* Need to update counts since we removed everything. |
6028 * If we don't update the counts here, we end up in the | |
6029 * "Shouldn't be here section, but maybe it's okay due to race conditions" | |
6030 */ | |
6031 alGetSourcei( | |
6032 ALmixer_Channel_List[i].alsource, | |
6033 AL_BUFFERS_QUEUED, &buffers_still_queued | |
6034 ); | |
6035 if((error = alGetError()) != AL_NO_ERROR) | |
6036 { | |
6037 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
|
6038 alGetString(error)); |
0 | 6039 } |
6040 /* Get the number of buffers processed | |
6041 * so we know if we need to refill | |
6042 */ | |
6043 alGetSourcei( | |
6044 ALmixer_Channel_List[i].alsource, | |
6045 AL_BUFFERS_PROCESSED, &buffers_processed | |
6046 ); | |
6047 if((error = alGetError()) != AL_NO_ERROR) | |
6048 { | |
6049 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
|
6050 alGetString(error)); |
0 | 6051 } |
6052 } | |
6053 | |
6054 | |
6055 /* Else if buffers_processed == 0 | |
6056 * and buffers_still_queued == 0. | |
6057 * then we check to see if the source | |
6058 * is still playing. Quit if stopped | |
6059 * We shouldn't need to worry about | |
6060 * looping because that should have | |
6061 * been handled above. | |
6062 */ | |
6063 if(0 == buffers_still_queued) | |
6064 { | |
6065 /* Make sure playback has stopped before | |
6066 * we shutdown. | |
6067 */ | |
6068 alGetSourcei( | |
6069 ALmixer_Channel_List[i].alsource, | |
6070 AL_SOURCE_STATE, &state | |
6071 ); | |
6072 if((error = alGetError()) != AL_NO_ERROR) | |
6073 { | |
6074 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
|
6075 alGetString(error)); |
0 | 6076 } |
6077 if(AL_STOPPED == state) | |
6078 { | |
6079 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use = 0; | |
6080 /* Playback has ended. | |
6081 * Loop if necessary, or launch callback | |
6082 * and clear channel (or clear channel and | |
6083 * 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
|
6084 * Update: Need to do callback first because I reference the mixer_data and source |
0 | 6085 */ |
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
|
6086 |
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
|
6087 /* 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
|
6088 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
|
6089 |
0 | 6090 Clean_Channel(i); |
6091 /* Subtract counter */ | |
6092 Is_Playing_global--; | |
6093 | |
6094 | |
6095 /* We're done for this loop. | |
6096 * Go to next channel | |
6097 */ | |
6098 continue; | |
6099 } | |
6100 } /* End end-playback */ | |
6101 else | |
6102 { | |
6103 /* Need to run out buffer */ | |
6104 #if 1 | |
6105 /* Might want to check state */ | |
6106 /* In case the playback stopped, | |
6107 * we need to resume */ | |
6108 alGetSourcei( | |
6109 ALmixer_Channel_List[i].alsource, | |
6110 AL_SOURCE_STATE, &state | |
6111 ); | |
6112 if((error = alGetError()) != AL_NO_ERROR) | |
6113 { | |
6114 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
|
6115 alGetString(error)); |
0 | 6116 } |
6117 if(AL_STOPPED == state) | |
6118 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6119 /* |
0 | 6120 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
|
6121 */ |
1 | 6122 /* |
0 | 6123 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 6124 */ |
0 | 6125 /* Rather than force unqueuing the buffer, let's see if |
6126 * setting the buffer to none works (the OpenAL 1.0 | |
6127 * Reference Annotation suggests this should work). | |
6128 */ | |
6129 alSourcei(ALmixer_Channel_List[i].alsource, | |
6130 AL_BUFFER, AL_NONE); | |
6131 /* | |
6132 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
6133 */ | |
6134 /* This doesn't work because in some cases, I think | |
6135 * it causes the sound to be replayed | |
6136 */ | |
6137 /* | |
6138 fprintf(stderr, "Resuming in eof (trying to run out buffers\n"); | |
6139 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
6140 */ | |
6141 } | |
6142 #endif | |
6143 } /* End trap section */ | |
6144 } /* End POST-EOF use-up buffer section */ | |
28
60500a33735a
Initial backend changes to decouple assumption of 1 buffer queued per channel / per pass. API will eventually be changed/broken to support this.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
27
diff
changeset
|
6145 |
60500a33735a
Initial backend changes to decouple assumption of 1 buffer queued per channel / per pass. API will eventually be changed/broken to support this.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
27
diff
changeset
|
6146 } /* END NEW number of queue buffers per pass */ |
60500a33735a
Initial backend changes to decouple assumption of 1 buffer queued per channel / per pass. API will eventually be changed/broken to support this.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
27
diff
changeset
|
6147 |
0 | 6148 } /* END Streamed section */ |
6149 } /* END channel in use */ | |
6150 } /* END for-loop for each channel */ | |
6151 | |
6152 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6153 alcProcessContext(alcGetCurrentContext()); | |
6154 if((error = alGetError()) != AL_NO_ERROR) | |
6155 { | |
6156 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
|
6157 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6158 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6159 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6160 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6161 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6162 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6163 #endif |
0 | 6164 /* Return the number of errors */ |
6165 if(error_flag < 0) | |
6166 { | |
6167 return error_flag; | |
6168 } | |
6169 /* Return the number of buffers that were queued */ | |
6170 return retval; | |
6171 } | |
6172 | |
6173 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6174 /* 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
|
6175 static void my_dummy_audio_callback(void* userdata, ALbyte* stream, int len) |
0 | 6176 { |
6177 } | |
6178 #endif | |
6179 | |
6180 | |
6181 | |
6182 | |
6183 #ifdef ENABLE_ALMIXER_THREADS | |
6184 /* We might need threads. We | |
6185 * must constantly poll OpenAL to find out | |
6186 * if sound is being streamed, if play has | |
6187 * ended, etc. Without threads, this must | |
6188 * be explicitly done by the user. | |
6189 * We could try to do it for them if we | |
6190 * finish the threads. | |
6191 */ | |
6192 | |
6193 static int Stream_Data_Thread_Callback(void* data) | |
6194 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6195 ALint retval; |
0 | 6196 |
29
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
6197 while(g_StreamThreadEnabled) |
0 | 6198 { |
6199 retval = Update_ALmixer(data); | |
6200 /* 0 means that nothing needed updating and | |
6201 * the function returned quickly | |
6202 */ | |
6203 if(0 == retval) | |
6204 { | |
6205 /* Let's be nice and make the thread sleep since | |
6206 * little work was done in update | |
6207 */ | |
6208 /* Make sure times are multiples of 10 | |
6209 * for optimal performance and accuracy in Linux | |
6210 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6211 ALmixer_Delay(10); |
0 | 6212 } |
6213 else | |
6214 { | |
6215 /* 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
|
6216 ALmixer_Delay(0); |
0 | 6217 } |
6218 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6219 /* |
0 | 6220 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
|
6221 */ |
0 | 6222 return 0; |
6223 } | |
6224 #endif /* End of ENABLE_ALMIXER_THREADS */ | |
6225 | |
6226 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6227 /* 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
|
6228 * 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
|
6229 * so SDL_mixer porting people beware. |
0 | 6230 * Warning: SDL_QuitSubSystem(SDL_INIT_AUDIO) is called which |
6231 * means the SDL audio system will be disabled. It will not | |
6232 * be restored (in case SDL is not actually being used) so | |
6233 * the user will need to restart it if they need it after | |
6234 * OpenAL shuts down. | |
6235 */ | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6236 ALboolean ALmixer_Init(ALuint frequency, ALuint num_sources, ALuint refresh) |
0 | 6237 { |
6238 ALCdevice* dev; | |
6239 ALCcontext* context; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6240 ALint i; |
0 | 6241 ALenum error; |
6242 ALuint* source; | |
6243 | |
6244 #ifdef USING_LOKI_AL_DIST | |
6245 /* The Loki dist requires that I set both the | |
6246 * device and context frequency values separately | |
6247 */ | |
6248 /* Hope this won't overflow */ | |
6249 char device_string[256]; | |
6250 #endif | |
6251 | |
6252 /* (Venting frustration) Damn it! Nobody bothered | |
6253 * documenting how you're supposed to use an attribute | |
6254 * list. In fact, the not even the Loki test program | |
6255 * writers seem to know because they use it inconsistently. | |
6256 * For example, how do you terminate that attribute list? | |
6257 * The Loki test code does it 3 different ways. They | |
6258 * set the last value to 0, or they set it to ALC_INVALID, | |
6259 * or they set two final values: ALC_INVALID, 0 | |
6260 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6261 * but with Creative Labs ALC_INVALID is -1. | |
6262 * So something's going to break. Loki's source | |
6263 * code says to terminate with ALC_INVALID. But I | |
6264 * don't know if that's really true, or it happens | |
6265 * to be a coinicidence because it's defined to 0. | |
6266 * Creative provides no source code, so I can't look at how | |
6267 * they terminate it. | |
6268 * So this is really, really ticking me off... | |
6269 * For now, I'm going to use ALC_INVALID. | |
6270 * (Update...after further review of the API spec, | |
6271 * it seems that a NULL terminated string is the correct | |
6272 * termination value to use, so 0 it is.) | |
6273 */ | |
6274 #if 0 | |
6275 ALint attrlist[] = { | |
6276 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6277 /* Don't know anything about these values. | |
6278 * Trust defaults? */ | |
6279 /* Supposed to be the refresh rate in Hz. | |
6280 * I think 15-120 are supposed to be good | |
6281 * values. Though I haven't gotten any effect except | |
6282 * for one strange instance on a Mac. But it was | |
6283 * unrepeatable. | |
6284 */ | |
6285 #if 0 | |
6286 ALC_REFRESH, 15, | |
6287 #endif | |
6288 /* Sync requires a alcProcessContext() call | |
6289 * for every cycle. By default, this is | |
6290 * not used and the value is AL_FALSE | |
6291 * because it will probably perform | |
6292 * pretty badly for me. | |
6293 */ | |
6294 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6295 ALC_SYNC, AL_TRUE, | |
6296 #else | |
6297 ALC_SYNC, AL_FALSE, | |
6298 #endif | |
6299 /* Looking at the API spec, it implies | |
6300 * that the list be a NULL terminated string | |
6301 * so it's probably not safe to use ALC_INVALID | |
6302 */ | |
6303 /* | |
6304 ALC_INVALID }; | |
6305 */ | |
6306 '\0'}; | |
6307 #endif | |
6308 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6309 * However, if no value is specified, I don't | |
6310 * want it in the list so I can get the OpenAL defaults | |
6311 */ | |
6312 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6313 ALsizei current_attrlist_index = 0; |
0 | 6314 |
6315 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6316 /* More problems: I'm getting bit by endian/signedness issues on | |
6317 * different platforms. I can find the endianess easily enough, | |
6318 * but I don't know how to determine what the correct signedness | |
6319 * is (if such a thing exists). I do know that if I try using | |
6320 * unsigned on OSX with an originally signed sample, I get | |
6321 * distortion. However, I don't have any native unsigned samples | |
6322 * to test. But I'm assuming that the platform must be in the | |
6323 * correct signedness no matter what. | |
6324 * I can either assume everybody is signed, or I can try to | |
6325 * determine the value. If I try to determine the values, | |
6326 * I think my only ability to figure it out will be to open | |
6327 * SDL_Audio, and read what the obtained settings were. | |
6328 * Then shutdown everything. However, I don't even know how | |
6329 * reliable this is. | |
6330 * Update: I think I resolved the issues...forgot to update | |
6331 * these comments when it happened. I should check the revision control | |
6332 * log... Anyway, I think the issue was partly related to me not | |
6333 * doing something correctly with the AudioInfo or some kind | |
6334 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6335 * revision control, I think I might have assumed that SDL_Sound would | |
6336 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6337 * and had to fill one out myself. | |
6338 */ | |
6339 SDL_AudioSpec desired; | |
6340 SDL_AudioSpec obtained; | |
6341 #endif | |
6342 | |
6343 | |
6344 /* Make sure ALmixer isn't already initialized */ | |
6345 if(ALmixer_Initialized) | |
6346 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6347 return AL_FALSE; |
0 | 6348 } |
6349 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6350 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6351 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6352 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6353 /* 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
|
6354 /* 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
|
6355 * 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
|
6356 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6357 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6358 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6359 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6360 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6361 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6362 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6363 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6364 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6365 } |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6366 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6367 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6368 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6369 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
|
6370 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
|
6371 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6372 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6373 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6374 |
0 | 6375 /* Set the defaults */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6376 /* |
0 | 6377 attrlist[0] = ALC_FREQUENCY; |
6378 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6379 attrlist[2] = ALC_SYNC; | |
6380 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6381 attrlist[3] = ALC_TRUE; | |
6382 #else | |
6383 attrlist[3] = ALC_FALSE; | |
6384 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6385 */ |
0 | 6386 /* Set frequency value if it is not 0 */ |
6387 if(0 != frequency) | |
6388 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6389 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6390 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6391 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6392 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6393 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6394 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6395 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6396 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6397 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6398 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6399 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6400 #endif |
0 | 6401 |
6402 /* If the user specifies a refresh value, | |
6403 * make room for it | |
6404 */ | |
6405 if(0 != refresh) | |
6406 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6407 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
|
6408 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6409 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6410 current_attrlist_index++; |
0 | 6411 } |
6412 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6413 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6414 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6415 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6416 |
0 | 6417 /* Initialize SDL_Sound */ |
6418 if(! Sound_Init() ) | |
6419 { | |
6420 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6421 return AL_FALSE; |
0 | 6422 } |
6423 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6424 /* Here is the paranoid check that opens | |
6425 * SDL audio in an attempt to find the correct | |
6426 * system values. | |
6427 */ | |
6428 /* Doesn't have to be the actual value I think | |
6429 * (as long as it doesn't influence format, in | |
6430 * which case I'm probably screwed anyway because OpenAL | |
6431 * may easily choose to do something else). | |
6432 */ | |
6433 desired.freq = 44100; | |
6434 desired.channels = 2; | |
6435 desired.format = AUDIO_S16SYS; | |
6436 desired.callback = my_dummy_audio_callback; | |
6437 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6438 { | |
6439 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6440 /* Now to get really paranoid, we should probably | |
6441 * also assume that the 8bit format is also the | |
6442 * same sign type and set that value | |
6443 */ | |
6444 if(AUDIO_S16SYS == obtained.format) | |
6445 { | |
6446 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6447 } | |
6448 /* Should be AUDIO_U16SYS */ | |
6449 else | |
6450 { | |
6451 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6452 } | |
6453 SDL_CloseAudio(); | |
6454 } | |
6455 else | |
6456 { | |
6457 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6458 */ | |
6459 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6460 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6461 } | |
6462 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6463 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6464 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6465 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
6466 * causes OpenAL and SMPEG to conflict. For some reason | |
6467 * if SDL_Init on audio is active, then all the SMPEG | |
6468 * decoded sound comes out silent. Unfortunately, | |
6469 * Sound_Init() invokes SDL_Init on audio. I'm | |
6470 * not sure why it actually needs it... | |
6471 * But we'll attempt to disable it here after the | |
6472 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
6473 */ | |
6474 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6475 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6476 |
0 | 6477 /* I'm told NULL will call the default string |
6478 * and hopefully do the right thing for each platform | |
6479 */ | |
6480 /* | |
6481 dev = alcOpenDevice( NULL ); | |
6482 */ | |
6483 /* Now I'm told I need to set both the device and context | |
6484 * to have the same sampling rate, so I must pass a string | |
6485 * to OpenDevice(). I don't know how portable these strings are. | |
6486 * I don't even know if the format for strings is | |
6487 * compatible | |
6488 * From the testattrib.c in the Loki test section | |
6489 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
6490 */ | |
6491 | |
6492 #ifdef USING_LOKI_AL_DIST | |
6493 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
6494 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
6495 #else | |
6496 dev = alcOpenDevice( NULL ); | |
6497 #endif | |
6498 if(NULL == dev) | |
6499 { | |
6500 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
|
6501 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6502 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6503 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6504 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6505 /* 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
|
6506 /* 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
|
6507 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6508 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6509 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6510 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6511 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
|
6512 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6513 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
|
6514 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6515 #endif |
0 | 6516 |
6517 context = alcCreateContext(dev, attrlist); | |
6518 if(NULL == context) | |
6519 { | |
6520 ALmixer_SetError("Cannot create a context OpenAL"); | |
6521 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6522 return AL_FALSE; |
0 | 6523 } |
6524 | |
6525 | |
6526 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6527 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6528 * According to Garin Hiebert, this is actually an inconsistency | |
6529 * in the Loki version. The function should return a boolean. | |
6530 * instead of ALC_NO_ERROR. Garin suggested I check via | |
6531 * alcGetError(). | |
6532 */ | |
6533 /* clear the error */ | |
6534 alcGetError(dev); | |
6535 alcMakeContextCurrent(context); | |
6536 | |
6537 error = alcGetError(dev); | |
6538 if( (ALC_NO_ERROR != error) ) | |
6539 { | |
6540 ALmixer_SetError("Could not MakeContextCurrent"); | |
6541 alcDestroyContext(context); | |
6542 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6543 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6544 } |
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 /* 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
|
6547 * 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
|
6548 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6549 * 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
|
6550 * 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
|
6551 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6552 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6553 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6554 ALmixer_Frequency_global = frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6555 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6556 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6557 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
|
6558 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6559 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
|
6560 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6561 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6562 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6563 |
0 | 6564 #if 0 |
6565 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
6566 if(alcGetCurrentContext() != context) | |
6567 { | |
6568 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6569 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6570 * I think this is a bug in the OpenAL implementation. | |
6571 */ | |
6572 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
6573 | |
6574 fprintf(stderr, "Making context current\n"); | |
6575 #ifndef __APPLE__ | |
6576 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
6577 #else | |
6578 if(!alcMakeContextCurrent(context)) | |
6579 #endif | |
6580 { | |
6581 ALmixer_SetError("Could not MakeContextCurrent"); | |
6582 alcDestroyContext(context); | |
6583 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6584 return AL_FALSE; |
0 | 6585 } |
6586 } | |
6587 #endif | |
6588 | |
6589 | |
6590 /* #endif */ | |
6591 /* Saw this in the README with the OS X OpenAL distribution. | |
6592 * It looked interesting and simple, so I thought I might | |
6593 * try it out. | |
6594 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
6595 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
6596 * Audio format, the audio data passed to the | |
6597 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
6598 * usage by removing an audio data conversion | |
6599 * (per source) at render timem at the expense of a larger memory footprint. | |
6600 * | |
6601 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
6602 * setting will be applied to all subsequent | |
6603 * calls to alBufferData(). | |
22
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 * 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
|
6606 * Rather than deal with it right now, I think I am going to make it an opt-in thing. |
0 | 6607 */ |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6608 #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
|
6609 /* |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6610 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
|
6611 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6612 #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
|
6613 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6614 #else |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6615 /* 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
|
6616 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
|
6617 /* |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6618 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
|
6619 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6620 if(0 != convert_data_enum) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6621 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6622 alEnable(convert_data_enum); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6623 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6624 if( (AL_NO_ERROR != alGetError()) ) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6625 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6626 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
|
6627 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
|
6628 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6629 #endif |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6630 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6631 #endif /* __APPLE__ */ |
0 | 6632 |
6633 | |
6634 | |
6635 | |
6636 ALmixer_Initialized = 1; | |
6637 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6638 if(num_sources == 0) |
0 | 6639 { |
6640 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
6641 } | |
6642 else | |
6643 { | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6644 /* 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
|
6645 Number_of_Channels_global = (ALint)num_sources; |
0 | 6646 } |
6647 Number_of_Reserve_Channels_global = 0; | |
6648 Is_Playing_global = 0; | |
6649 /* Set to Null in case system quit and was reinitialized */ | |
6650 Channel_Done_Callback = NULL; | |
6651 Channel_Done_Callback_Userdata = NULL; | |
6652 Channel_Data_Callback = NULL; | |
1 | 6653 Channel_Data_Callback_Userdata = NULL; |
0 | 6654 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6655 /* Allocate memory for linked list of ALmixerData. */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6656 s_listOfALmixerData = LinkedList_Create(); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6657 if(NULL == s_listOfALmixerData) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6658 { |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6659 ALmixer_SetError("Couldn't create linked list"); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6660 alcDestroyContext(context); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6661 alcCloseDevice(dev); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6662 ALmixer_Initialized = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6663 Number_of_Channels_global = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6664 return AL_FALSE; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6665 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6666 |
0 | 6667 /* Allocate memory for the list of channels */ |
6668 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
6669 if(NULL == ALmixer_Channel_List) | |
6670 { | |
6671 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
|
6672 LinkedList_Free(s_listOfALmixerData); |
0 | 6673 alcDestroyContext(context); |
6674 alcCloseDevice(dev); | |
6675 ALmixer_Initialized = 0; | |
6676 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6677 return AL_FALSE; |
0 | 6678 } |
6679 | |
6680 /* Allocate memory for the list of sources that map to the channels */ | |
6681 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
6682 if(NULL == Source_Map_List) | |
6683 { | |
6684 ALmixer_SetError("Out of Memory for Source Map List"); | |
6685 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6686 LinkedList_Free(s_listOfALmixerData); |
0 | 6687 alcDestroyContext(context); |
6688 alcCloseDevice(dev); | |
6689 ALmixer_Initialized = 0; | |
6690 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6691 return AL_FALSE; |
0 | 6692 } |
6693 | |
6694 /* Create array that will hold the sources */ | |
6695 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
6696 if(NULL == source) | |
6697 { | |
6698 ALmixer_SetError("Out of Memory for sources"); | |
6699 free(Source_Map_List); | |
6700 free(ALmixer_Channel_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 /* Clear the error state */ | |
6710 alGetError(); | |
6711 /* Generate the OpenAL sources */ | |
6712 alGenSources(Number_of_Channels_global, source); | |
6713 if( (error=alGetError()) != AL_NO_ERROR) | |
6714 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6715 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 6716 free(ALmixer_Channel_List); |
6717 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6718 LinkedList_Free(s_listOfALmixerData); |
0 | 6719 alcDestroyContext(context); |
6720 alcCloseDevice(dev); | |
6721 ALmixer_Initialized = 0; | |
6722 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6723 return AL_FALSE; |
0 | 6724 } |
6725 | |
6726 /* Initialize each channel and associate one source to one channel */ | |
6727 for(i=0; i<Number_of_Channels_global; i++) | |
6728 { | |
6729 if(0 == source[i]) | |
6730 { | |
6731 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"); | |
6732 } | |
6733 | |
6734 Init_Channel(i); | |
6735 /* Keeping the source allocation out of the Init function | |
6736 * in case I want to reuse the Init | |
6737 * function for resetting data | |
6738 */ | |
6739 ALmixer_Channel_List[i].alsource = source[i]; | |
6740 /* Now also keep a copy of the source to channel mapping | |
6741 * in case we need to look up a channel from the source | |
6742 * instead of a source from a channel | |
6743 */ | |
6744 Source_Map_List[i].source = source[i]; | |
6745 Source_Map_List[i].channel = i; | |
6746 /* Clean the channel because there are some things that need to | |
6747 * be done that can't happen until the source is set | |
6748 */ | |
6749 Clean_Channel(i); | |
6750 } | |
6751 | |
6752 /* The Source_Map_List must be sorted by source for binary searches | |
6753 */ | |
6754 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
6755 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6756 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6757 ALmixer_OutputDecoders(); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6758 */ |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6759 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6760 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6761 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6762 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6763 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6764 if(NULL == s_simpleLock) |
0 | 6765 { |
6766 /* SDL sets the error message already? */ | |
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 } |
6777 | |
29
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
6778 g_StreamThreadEnabled = 1; |
0 | 6779 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); |
6780 if(NULL == Stream_Thread_global) | |
6781 { | |
6782 /* 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
|
6783 SDL_DestroyMutex(s_simpleLock); |
0 | 6784 free(source); |
6785 free(ALmixer_Channel_List); | |
6786 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6787 LinkedList_Free(s_listOfALmixerData); |
0 | 6788 alcDestroyContext(context); |
6789 alcCloseDevice(dev); | |
6790 ALmixer_Initialized = 0; | |
6791 Number_of_Channels_global = 0; | |
29
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
6792 g_StreamThreadEnabled = 0; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6793 return AL_FALSE; |
0 | 6794 } |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
6795 |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
6796 /* 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
|
6797 Internal_LowerThreadPriority(Stream_Thread_global); |
0 | 6798 |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6799 /* |
0 | 6800 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6801 */ |
0 | 6802 #endif /* End of ENABLE_ALMIXER_THREADS */ |
6803 | |
6804 /* We don't need this array any more because all the sources | |
6805 * are connected to channels | |
6806 */ | |
6807 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6808 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6809 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6810 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6811 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6812 ALboolean ALmixer_InitContext(ALuint frequency, ALuint refresh) |
0 | 6813 { |
6814 ALCdevice* dev; | |
6815 ALCcontext* context; | |
6816 ALCenum error; | |
6817 | |
6818 #ifdef USING_LOKI_AL_DIST | |
6819 /* The Loki dist requires that I set both the | |
6820 * device and context frequency values separately | |
6821 */ | |
6822 /* Hope this won't overflow */ | |
6823 char device_string[256]; | |
6824 #endif | |
6825 | |
6826 /* (Venting frustration) Damn it! Nobody bothered | |
6827 * documenting how you're supposed to use an attribute | |
6828 * list. In fact, the not even the Loki test program | |
6829 * writers seem to know because they use it inconsistently. | |
6830 * For example, how do you terminate that attribute list? | |
6831 * The Loki test code does it 3 different ways. They | |
6832 * set the last value to 0, or they set it to ALC_INVALID, | |
6833 * or they set two final values: ALC_INVALID, 0 | |
6834 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6835 * but with Creative Labs ALC_INVALID is -1. | |
6836 * So something's going to break. Loki's source | |
6837 * code says to terminate with ALC_INVALID. But I | |
6838 * don't know if that's really true, or it happens | |
6839 * to be a coinicidence because it's defined to 0. | |
6840 * Creative provides no source code, so I can't look at how | |
6841 * they terminate it. | |
6842 * So this is really, really ticking me off... | |
6843 * For now, I'm going to use ALC_INVALID. | |
6844 * (Update...after further review of the API spec, | |
6845 * it seems that a NULL terminated string is the correct | |
6846 * termination value to use, so 0 it is.) | |
6847 */ | |
6848 #if 0 | |
6849 ALint attrlist[] = { | |
6850 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6851 /* Don't know anything about these values. | |
6852 * Trust defaults? */ | |
6853 /* Supposed to be the refresh rate in Hz. | |
6854 * I think 15-120 are supposed to be good | |
6855 * values. Though I haven't gotten any effect except | |
6856 * for one strange instance on a Mac. But it was | |
6857 * unrepeatable. | |
6858 */ | |
6859 #if 0 | |
6860 ALC_REFRESH, 15, | |
6861 #endif | |
6862 /* Sync requires a alcProcessContext() call | |
6863 * for every cycle. By default, this is | |
6864 * not used and the value is AL_FALSE | |
6865 * because it will probably perform | |
6866 * pretty badly for me. | |
6867 */ | |
6868 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6869 ALC_SYNC, AL_TRUE, | |
6870 #else | |
6871 ALC_SYNC, AL_FALSE, | |
6872 #endif | |
6873 /* Looking at the API spec, it implies | |
6874 * that the list be a NULL terminated string | |
6875 * so it's probably not safe to use ALC_INVALID | |
6876 */ | |
6877 /* | |
6878 ALC_INVALID }; | |
6879 */ | |
6880 '\0'}; | |
6881 #endif | |
6882 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6883 * However, if no value is specified, I don't | |
6884 * want it in the list so I can get the OpenAL defaults | |
6885 */ | |
6886 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6887 ALsizei current_attrlist_index = 0; |
0 | 6888 |
6889 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6890 /* More problems: I'm getting bit by endian/signedness issues on | |
6891 * different platforms. I can find the endianess easily enough, | |
6892 * but I don't know how to determine what the correct signedness | |
6893 * is (if such a thing exists). I do know that if I try using | |
6894 * unsigned on OSX with an originally signed sample, I get | |
6895 * distortion. However, I don't have any native unsigned samples | |
6896 * to test. But I'm assuming that the platform must be in the | |
6897 * correct signedness no matter what. | |
6898 * I can either assume everybody is signed, or I can try to | |
6899 * determine the value. If I try to determine the values, | |
6900 * I think my only ability to figure it out will be to open | |
6901 * SDL_Audio, and read what the obtained settings were. | |
6902 * Then shutdown everything. However, I don't even know how | |
6903 * reliable this is. | |
6904 * Update: I think I resolved the issues...forgot to update | |
6905 * these comments when it happened. I should check the revision control | |
6906 * log... Anyway, I think the issue was partly related to me not | |
6907 * doing something correctly with the AudioInfo or some kind | |
6908 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6909 * revision control, I think I might have assumed that SDL_Sound would | |
6910 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6911 * and had to fill one out myself. | |
6912 */ | |
6913 SDL_AudioSpec desired; | |
6914 SDL_AudioSpec obtained; | |
6915 #endif | |
6916 | |
6917 | |
6918 | |
6919 | |
6920 /* Make sure ALmixer isn't already initialized */ | |
6921 if(ALmixer_Initialized) | |
6922 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6923 return AL_FALSE; |
0 | 6924 } |
6925 | |
6926 /* Set the defaults */ | |
6927 attrlist[0] = ALC_FREQUENCY; | |
6928 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6929 attrlist[2] = ALC_SYNC; | |
6930 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6931 attrlist[3] = ALC_TRUE; | |
6932 #else | |
6933 attrlist[3] = ALC_FALSE; | |
6934 #endif | |
6935 /* Set frequency value if it is not 0 */ | |
6936 if(0 != frequency) | |
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] = ALC_FREQUENCY; |
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] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6941 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6942 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6943 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6944 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6945 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6946 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6947 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6948 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6949 #endif |
0 | 6950 |
6951 /* If the user specifies a refresh value, | |
6952 * make room for it | |
6953 */ | |
6954 if(0 != refresh) | |
6955 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6956 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
|
6957 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6958 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6959 current_attrlist_index++; |
0 | 6960 } |
6961 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6962 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6963 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6964 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6965 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6966 |
0 | 6967 /* Initialize SDL_Sound */ |
6968 if(! Sound_Init() ) | |
6969 { | |
6970 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6971 return AL_FALSE; |
0 | 6972 } |
6973 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6974 /* Here is the paranoid check that opens | |
6975 * SDL audio in an attempt to find the correct | |
6976 * system values. | |
6977 */ | |
6978 /* Doesn't have to be the actual value I think | |
6979 * (as long as it doesn't influence format, in | |
6980 * which case I'm probably screwed anyway because OpenAL | |
6981 * may easily choose to do something else). | |
6982 */ | |
6983 desired.freq = 44100; | |
6984 desired.channels = 2; | |
6985 desired.format = AUDIO_S16SYS; | |
6986 desired.callback = my_dummy_audio_callback; | |
6987 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6988 { | |
6989 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6990 /* Now to get really paranoid, we should probably | |
6991 * also assume that the 8bit format is also the | |
6992 * same sign type and set that value | |
6993 */ | |
6994 if(AUDIO_S16SYS == obtained.format) | |
6995 { | |
6996 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6997 } | |
6998 /* Should be AUDIO_U16SYS */ | |
6999 else | |
7000 { | |
7001 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
7002 } | |
7003 SDL_CloseAudio(); | |
7004 } | |
7005 else | |
7006 { | |
7007 /* Well, I guess I'm in trouble. I guess it's my best guess | |
7008 */ | |
7009 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
7010 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
7011 } | |
7012 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7013 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7014 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 7015 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
7016 * causes OpenAL and SMPEG to conflict. For some reason | |
7017 * if SDL_Init on audio is active, then all the SMPEG | |
7018 * decoded sound comes out silent. Unfortunately, | |
7019 * Sound_Init() invokes SDL_Init on audio. I'm | |
7020 * not sure why it actually needs it... | |
7021 * But we'll attempt to disable it here after the | |
7022 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
7023 */ | |
7024 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7025 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7026 |
0 | 7027 /* I'm told NULL will call the default string |
7028 * and hopefully do the right thing for each platform | |
7029 */ | |
7030 /* | |
7031 dev = alcOpenDevice( NULL ); | |
7032 */ | |
7033 /* Now I'm told I need to set both the device and context | |
7034 * to have the same sampling rate, so I must pass a string | |
7035 * to OpenDevice(). I don't know how portable these strings are. | |
7036 * I don't even know if the format for strings is | |
7037 * compatible | |
7038 * From the testattrib.c in the Loki test section | |
7039 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
7040 */ | |
7041 | |
7042 #ifdef USING_LOKI_AL_DIST | |
7043 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
7044 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
7045 #else | |
7046 dev = alcOpenDevice( NULL ); | |
7047 #endif | |
7048 if(NULL == dev) | |
7049 { | |
7050 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
|
7051 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7052 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7053 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7054 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7055 /* 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
|
7056 /* 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
|
7057 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7058 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7059 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7060 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7061 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
|
7062 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7063 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
|
7064 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7065 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7066 |
0 | 7067 |
7068 context = alcCreateContext(dev, attrlist); | |
7069 if(NULL == context) | |
7070 { | |
7071 ALmixer_SetError("Cannot create a context OpenAL"); | |
7072 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7073 return AL_FALSE; |
0 | 7074 } |
7075 | |
7076 | |
7077 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
7078 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
7079 * According to Garin Hiebert, this is actually an inconsistency | |
7080 * in the Loki version. The function should return a boolean. | |
7081 * instead of ALC_NO_ERROR. Garin suggested I check via | |
7082 * alcGetError(). | |
7083 */ | |
7084 /* clear the error */ | |
7085 alcGetError(dev); | |
7086 alcMakeContextCurrent(context); | |
7087 | |
7088 error = alcGetError(dev); | |
7089 if( (ALC_NO_ERROR != error) ) | |
7090 { | |
7091 ALmixer_SetError("Could not MakeContextCurrent"); | |
7092 alcDestroyContext(context); | |
7093 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7094 return AL_FALSE; |
0 | 7095 } |
7096 | |
7097 | |
7098 #if 0 | |
7099 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
7100 if(alcGetCurrentContext() != context) | |
7101 { | |
7102 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
7103 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
7104 * I think this is a bug in the OpenAL implementation. | |
7105 */ | |
7106 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
7107 | |
7108 fprintf(stderr, "Making context current\n"); | |
7109 #ifndef __APPLE__ | |
7110 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
7111 #else | |
7112 if(!alcMakeContextCurrent(context)) | |
7113 #endif | |
7114 { | |
7115 ALmixer_SetError("Could not MakeContextCurrent"); | |
7116 alcDestroyContext(context); | |
7117 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7118 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7119 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7120 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7121 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7122 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7123 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7124 /* 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
|
7125 * 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
|
7126 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7127 * 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
|
7128 * 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
|
7129 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7130 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7131 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7132 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
|
7133 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7134 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
|
7135 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7136 #endif |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7137 |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7138 |
0 | 7139 |
7140 /* Saw this in the README with the OS X OpenAL distribution. | |
7141 * It looked interesting and simple, so I thought I might | |
7142 * try it out. | |
7143 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
7144 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
7145 * Audio format, the audio data passed to the | |
7146 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
7147 * usage by removing an audio data conversion | |
7148 * (per source) at render timem at the expense of a larger memory footprint. | |
7149 * | |
7150 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
7151 * setting will be applied to all subsequent | |
7152 * calls to alBufferData(). | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7153 * 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
|
7154 * Rather than deal with it right now, I think I am going to make it an opt-in thing. |
0 | 7155 */ |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7156 #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
|
7157 /* |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7158 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
|
7159 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7160 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7161 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7162 #else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7163 /* 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
|
7164 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
|
7165 /* |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7166 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
|
7167 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7168 if(0 != convert_data_enum) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7169 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7170 alEnable(convert_data_enum); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7171 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7172 if( (AL_NO_ERROR != alGetError()) ) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7173 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7174 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
|
7175 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
|
7176 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7177 #endif |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7178 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7179 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7180 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7181 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7182 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7183 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7184 ALboolean ALmixer_InitMixer(ALuint num_sources) |
0 | 7185 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7186 ALint i; |
0 | 7187 ALenum error; |
7188 ALuint* source; | |
7189 | |
7190 | |
7191 ALmixer_Initialized = 1; | |
7192 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7193 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7194 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7195 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7196 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7197 /* 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
|
7198 /* 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
|
7199 * 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
|
7200 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7201 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7202 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7203 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7204 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7205 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7206 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7207 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7208 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7209 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7210 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7211 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7212 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7213 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
|
7214 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
|
7215 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7216 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7217 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7218 if(num_sources == 0) |
0 | 7219 { |
7220 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
7221 } | |
7222 else | |
7223 { | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7224 Number_of_Channels_global = (ALint)num_sources; |
0 | 7225 } |
7226 Number_of_Reserve_Channels_global = 0; | |
7227 Is_Playing_global = 0; | |
7228 /* Set to Null in case system quit and was reinitialized */ | |
7229 Channel_Done_Callback = NULL; | |
7230 Channel_Done_Callback_Userdata = NULL; | |
7231 Channel_Data_Callback = NULL; | |
1 | 7232 Channel_Data_Callback_Userdata = NULL; |
0 | 7233 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7234 /* Allocate memory for linked list of ALmixerData. */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7235 s_listOfALmixerData = LinkedList_Create(); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7236 if(NULL == s_listOfALmixerData) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7237 { |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7238 ALmixer_SetError("Couldn't create linked list"); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7239 ALmixer_Initialized = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7240 Number_of_Channels_global = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7241 return AL_FALSE; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7242 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7243 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7244 |
0 | 7245 /* Allocate memory for the list of channels */ |
7246 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
7247 if(NULL == ALmixer_Channel_List) | |
7248 { | |
7249 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
|
7250 LinkedList_Free(s_listOfALmixerData); |
0 | 7251 ALmixer_Initialized = 0; |
7252 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7253 return AL_FALSE; |
0 | 7254 } |
7255 | |
7256 /* Allocate memory for the list of sources that map to the channels */ | |
7257 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
7258 if(NULL == Source_Map_List) | |
7259 { | |
7260 ALmixer_SetError("Out of Memory for Source Map List"); | |
7261 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7262 LinkedList_Free(s_listOfALmixerData); |
0 | 7263 ALmixer_Initialized = 0; |
7264 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7265 return AL_FALSE; |
0 | 7266 } |
7267 | |
7268 /* Create array that will hold the sources */ | |
7269 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
7270 if(NULL == source) | |
7271 { | |
7272 ALmixer_SetError("Out of Memory for sources"); | |
7273 free(Source_Map_List); | |
7274 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7275 LinkedList_Free(s_listOfALmixerData); |
0 | 7276 ALmixer_Initialized = 0; |
7277 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7278 return AL_FALSE; |
0 | 7279 } |
7280 | |
7281 /* Clear the error state */ | |
7282 alGetError(); | |
7283 /* Generate the OpenAL sources */ | |
7284 alGenSources(Number_of_Channels_global, source); | |
7285 if( (error=alGetError()) != AL_NO_ERROR) | |
7286 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7287 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 7288 free(ALmixer_Channel_List); |
7289 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7290 LinkedList_Free(s_listOfALmixerData); |
0 | 7291 ALmixer_Initialized = 0; |
7292 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7293 return AL_FALSE; |
0 | 7294 } |
7295 | |
7296 /* Initialize each channel and associate one source to one channel */ | |
7297 for(i=0; i<Number_of_Channels_global; i++) | |
7298 { | |
7299 Init_Channel(i); | |
7300 /* Keeping the source allocation out of the Init function | |
7301 * in case I want to reuse the Init | |
7302 * function for resetting data | |
7303 */ | |
7304 ALmixer_Channel_List[i].alsource = source[i]; | |
7305 /* Now also keep a copy of the source to channel mapping | |
7306 * in case we need to look up a channel from the source | |
7307 * instead of a source from a channel | |
7308 */ | |
7309 Source_Map_List[i].source = source[i]; | |
7310 Source_Map_List[i].channel = i; | |
7311 /* Clean the channel because there are some things that need to | |
7312 * be done that can't happen until the source is set | |
7313 */ | |
7314 Clean_Channel(i); | |
7315 } | |
7316 | |
7317 /* The Source_Map_List must be sorted by source for binary searches | |
7318 */ | |
7319 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
7320 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7321 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7322 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7323 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7324 if(NULL == s_simpleLock) |
0 | 7325 { |
7326 /* SDL sets the error message already? */ | |
7327 free(source); | |
7328 free(ALmixer_Channel_List); | |
7329 free(Source_Map_List); | |
7330 ALmixer_Initialized = 0; | |
7331 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7332 return AL_FALSE; |
0 | 7333 } |
7334 | |
7335 | |
29
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7336 g_StreamThreadEnabled = 1; |
0 | 7337 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); |
7338 if(NULL == Stream_Thread_global) | |
7339 { | |
7340 /* 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
|
7341 SDL_DestroyMutex(s_simpleLock); |
0 | 7342 free(source); |
7343 free(ALmixer_Channel_List); | |
7344 free(Source_Map_List); | |
7345 ALmixer_Initialized = 0; | |
7346 Number_of_Channels_global = 0; | |
29
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7347 g_StreamThreadEnabled = 0; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7348 return AL_FALSE; |
0 | 7349 } |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
7350 |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
7351 /* 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
|
7352 Internal_LowerThreadPriority(Stream_Thread_global); |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
7353 |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7354 /* |
0 | 7355 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7356 */ |
0 | 7357 #endif /* End of ENABLE_ALMIXER_THREADS */ |
7358 | |
7359 /* We don't need this array any more because all the sources | |
7360 * are connected to channels | |
7361 */ | |
7362 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7363 return AL_TRUE; |
0 | 7364 } |
7365 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7366 void ALmixer_BeginInterruption() |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7367 { |
29
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7368 if(1 == g_inInterruption) |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7369 { |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7370 return; |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7371 } |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7372 #ifdef ENABLE_ALMIXER_THREADS |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7373 /* Kill bookkeeping thread to help minimize wasted CPU resources */ |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7374 |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7375 /* Is locking really necessary here? */ |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7376 /* SDL_LockMutex(s_simpleLock); */ |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7377 g_StreamThreadEnabled = 0; |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7378 /* SDL_UnlockMutex(s_simpleLock); */ |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7379 |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7380 SDL_WaitThread(Stream_Thread_global, NULL); |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7381 Stream_Thread_global = NULL; |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7382 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7383 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7384 s_interruptionContext = alcGetCurrentContext(); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7385 if(NULL != s_interruptionContext) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7386 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7387 /* iOS alcSuspendContext is a no-op */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7388 alcSuspendContext(s_interruptionContext); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7389 alcMakeContextCurrent(NULL); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7390 } |
29
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7391 |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7392 g_inInterruption = 1; |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7393 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7394 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7395 void ALmixer_EndInterruption() |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7396 { |
29
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7397 if(0 == g_inInterruption) |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7398 { |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7399 return; |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7400 } |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7401 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7402 /* Note: iOS, you need to set the AudioSession active. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7403 * But if the AudioSession is not initialized, this SetActive |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7404 * call fails. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7405 * 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
|
7406 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7407 /* |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7408 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7409 OSStatus the_error = AudioSessionSetActive(true); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7410 if(noErr != the_error) |
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 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
|
7413 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7414 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7415 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7416 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7417 if(NULL != s_interruptionContext) |
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 alcMakeContextCurrent(s_interruptionContext); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7420 alcProcessContext(s_interruptionContext); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7421 s_interruptionContext = NULL; |
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 #ifdef ENABLE_ALMIXER_THREADS |
29
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7424 g_StreamThreadEnabled = 1; |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7425 |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7426 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7427 if(NULL == Stream_Thread_global) |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7428 { |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7429 fprintf(stderr, "Critical Error: Could not create bookkeeping thread in EndInterruption\n"); |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7430 } |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7431 #endif |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7432 g_inInterruption = 0; |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7433 } |
0 | 7434 |
7435 /* Keep the return value void to allow easy use with | |
7436 * atexit() | |
7437 */ | |
7438 void ALmixer_Quit() | |
7439 { | |
7440 ALCcontext* context; | |
7441 ALCdevice* dev; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7442 ALint i; |
0 | 7443 |
7444 if( ! ALmixer_Initialized) | |
7445 { | |
7446 return; | |
7447 } | |
29
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7448 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7449 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7450 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7451 #endif |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7452 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7453 /* Several things we need to do: |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7454 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
|
7455 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
|
7456 Next, we should delete the OpenAL sources. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7457 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
|
7458 Finally, we can delete the OpenAL context. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7459 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7460 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7461 context = alcGetCurrentContext(); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7462 if(NULL == context) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7463 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7464 /* 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
|
7465 if(NULL == s_interruptionContext) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7466 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7467 /* Nothing left to try. I think we're done. */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7468 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
|
7469 return; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7470 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7471 else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7472 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7473 context = s_interruptionContext; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7474 /* reactivate the context so we can call OpenAL functions */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7475 alcMakeContextCurrent(context); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7476 s_interruptionContext = NULL; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7477 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7478 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7479 |
0 | 7480 /* Shutdown everything before closing context */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7481 Internal_HaltChannel(-1, AL_FALSE); |
0 | 7482 |
7483 /* This flag will cause the thread to terminate */ | |
7484 ALmixer_Initialized = 0; | |
7485 #ifdef ENABLE_ALMIXER_THREADS | |
29
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7486 g_StreamThreadEnabled = 0; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7487 SDL_UnlockMutex(s_simpleLock); |
29
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7488 /* This is safe to call with NULL thread, so we don't need to do anything special for interruptions. */ |
0 | 7489 SDL_WaitThread(Stream_Thread_global, NULL); |
29
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7490 Stream_Thread_global = NULL; |
1c23805d5ce9
Optimization to destroy bookkeeping thread on BeginInterruption() and recreate it on EndInterruption(). I'm concerned that Android may be running this thread and eating up unnecessary sleep cycles, particularly on certain devices that may have pathological sleep disorders. (There is a report about Samsung Galaxy Tab.)
Eric Wing <ewing . public |-at-| gmail . com>
parents:
28
diff
changeset
|
7491 g_inInterruption = 0; |
0 | 7492 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7493 SDL_DestroyMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7494 #endif |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7495 |
0 | 7496 /* Delete all the OpenAL sources */ |
7497 for(i=0; i<Number_of_Channels_global; i++) | |
7498 { | |
7499 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
7500 } | |
7501 /* Delete all the channels */ | |
7502 free(ALmixer_Channel_List); | |
7503 free(Source_Map_List); | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7504 |
0 | 7505 /* Reset the Number_of_Channels just in case somebody |
7506 * tries using a ALmixer function. | |
7507 * I probably should put "Initialized" checks everywhere, | |
7508 * but I'm too lazy at the moment. | |
7509 */ | |
7510 Number_of_Channels_global = 0; | |
7511 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7512 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7513 /* 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
|
7514 * 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
|
7515 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7516 while(LinkedList_Size(s_listOfALmixerData) > 0) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7517 { |
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
|
7518 /* 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
|
7519 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
|
7520 ALmixer_FreeData(almixer_data); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7521 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7522 LinkedList_Free(s_listOfALmixerData); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7523 s_listOfALmixerData = NULL; |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7524 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7525 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7526 /* 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
|
7527 dev = alcGetContextsDevice(context); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7528 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7529 alcMakeContextCurrent(NULL); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7530 alcDestroyContext(context); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7531 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7532 if(NULL == dev) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7533 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7534 return; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7535 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7536 alcCloseDevice(dev); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7537 |
0 | 7538 Sound_Quit(); |
7539 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7540 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7541 /* 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
|
7542 TError_FreeErrorPool(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7543 s_ALmixerErrorPool = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7544 #endif |
0 | 7545 return; |
7546 } | |
7547 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7548 ALboolean ALmixer_IsInitialized() |
0 | 7549 { |
7550 return ALmixer_Initialized; | |
7551 } | |
7552 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7553 ALuint ALmixer_GetFrequency() |
0 | 7554 { |
7555 return ALmixer_Frequency_global; | |
7556 } | |
7557 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7558 const ALmixer_version* ALmixer_GetLinkedVersion() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7559 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7560 static ALmixer_version linked_mixver; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7561 ALMIXER_GET_COMPILED_VERSION(&linked_mixver); |
0 | 7562 return(&linked_mixver); |
7563 } | |
7564 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7565 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7566 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7567 const char* ALmixer_GetError() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7568 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7569 const char* error_string = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7570 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7571 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7572 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
|
7573 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7574 error_string = TError_GetLastErrorStr(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7575 /* 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
|
7576 if(NULL == error_string) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7577 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7578 return ""; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7579 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7580 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7581 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7582 return error_string; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7583 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7584 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7585 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7586 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
|
7587 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7588 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7589 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7590 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
|
7591 return; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7592 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7593 va_list argp; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7594 va_start(argp, err_str); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7595 // 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
|
7596 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
|
7597 va_end(argp); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7598 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7599 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7600 #endif |
0 | 7601 |
7602 | |
7603 | |
7604 | |
7605 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7606 void ALmixer_OutputAttributes() |
0 | 7607 { |
7608 ALint num_flags = 0; | |
7609 ALint* flags = 0; | |
7610 int i; | |
7611 ALCdevice* dev = alcGetContextsDevice( alcGetCurrentContext() ); | |
7612 | |
7613 | |
7614 printf("custom context\n"); | |
7615 | |
7616 alcGetIntegerv(dev, ALC_ATTRIBUTES_SIZE, | |
7617 sizeof num_flags, &num_flags ); | |
7618 | |
7619 printf("Number of Flags: %d\n", num_flags); | |
7620 | |
7621 if(num_flags) | |
7622 { | |
7623 flags = malloc(sizeof(num_flags) * sizeof(ALint)); | |
7624 | |
7625 alcGetIntegerv(dev, ALC_ALL_ATTRIBUTES, | |
7626 sizeof num_flags * sizeof(ALint), | |
7627 flags ); | |
7628 } | |
7629 for(i = 0; i < num_flags-1; i += 2) | |
7630 { | |
7631 printf("key 0x%x : value %d\n", | |
7632 flags[i], flags[i+1]); | |
7633 } | |
7634 free(flags); | |
7635 } | |
7636 #endif | |
7637 | |
7638 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7639 void ALmixer_OutputDecoders() |
0 | 7640 { |
7641 Sound_Version sound_compile_version; | |
7642 Sound_Version sound_link_version; | |
7643 | |
7644 const Sound_DecoderInfo **rc = Sound_AvailableDecoders(); | |
7645 const Sound_DecoderInfo **i; | |
7646 const char **ext; | |
7647 FILE* stream = stdout; | |
7648 | |
7649 | |
7650 fprintf(stream, "SDL_sound Information:\n"); | |
7651 | |
7652 SOUND_VERSION(&sound_compile_version); | |
7653 fprintf(stream, "\tCompiled with SDL_sound version: %d.%d.%d\n", | |
7654 sound_compile_version.major, | |
7655 sound_compile_version.minor, | |
7656 sound_compile_version.patch); | |
7657 | |
7658 Sound_GetLinkedVersion(&sound_link_version); | |
7659 fprintf(stream, "\tRunning (linked) with SDL_sound version: %d.%d.%d\n", | |
7660 sound_link_version.major, | |
7661 sound_link_version.minor, | |
7662 sound_link_version.patch); | |
7663 | |
7664 fprintf(stream, "Supported sound formats:\n"); | |
7665 if (rc == NULL) | |
7666 fprintf(stream, " * Apparently, NONE!\n"); | |
7667 else | |
7668 { | |
7669 for (i = rc; *i != NULL; i++) | |
7670 { | |
7671 fprintf(stream, " * %s\n", (*i)->description); | |
7672 | |
7673 for (ext = (*i)->extensions; *ext != NULL; ext++) | |
7674 fprintf(stream, " File extension \"%s\"\n", *ext); | |
7675 | |
7676 fprintf(stream, " Written by %s.\n %s\n\n", | |
7677 (*i)->author, (*i)->url); | |
7678 } /* for */ | |
7679 } /* else */ | |
7680 | |
7681 fprintf(stream, "\n"); | |
7682 } | |
7683 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7684 void ALmixer_OutputOpenALInfo() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7685 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7686 ALmixer_version mixer_compile_version; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7687 const ALmixer_version * mixer_link_version=ALmixer_GetLinkedVersion(); |
0 | 7688 FILE* stream = stdout; |
7689 | |
7690 fprintf(stream, "OpenAL Information:\n"); | |
7691 fprintf(stream, "\tAL_VENDOR: %s\n", alGetString( AL_VENDOR ) ); | |
7692 fprintf(stream, "\tAL_VERSION: %s\n", alGetString( AL_VERSION ) ); | |
7693 fprintf(stream, "\tAL_RENDERER: %s\n", alGetString( AL_RENDERER ) ); | |
7694 fprintf(stream, "\tAL_EXTENSIONS: %s\n", alGetString( AL_EXTENSIONS ) ); | |
7695 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7696 ALMIXER_GET_COMPILED_VERSION(&mixer_compile_version); |
0 | 7697 fprintf(stream, "\nSDL_ALmixer Information:\n"); |
7698 fprintf(stream, "\tCompiled with SDL_ALmixer version: %d.%d.%d\n", | |
7699 mixer_compile_version.major, | |
7700 mixer_compile_version.minor, | |
7701 mixer_compile_version.patch); | |
7702 | |
7703 fprintf(stream, "\tRunning (linked) with SDL_ALmixer version: %d.%d.%d\n", | |
7704 mixer_link_version->major, | |
7705 mixer_link_version->minor, | |
7706 mixer_link_version->patch); | |
7707 | |
7708 fprintf(stream, "\tCompile flags: "); | |
7709 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
7710 fprintf(stream, "ENABLE_LOKI_QUEUE_FIX_HACK "); | |
7711 #endif | |
7712 #ifdef ENABLE_ALMIXER_THREADS | |
7713 fprintf(stream, "ENABLE_ALMIXER_THREADS "); | |
7714 #endif | |
7715 #ifdef ENABLE_ALC_SYNC | |
7716 fprintf(stream, "ENABLE_ALC_SYNC "); | |
7717 #endif | |
7718 fprintf(stream, "\n"); | |
7719 } | |
7720 | |
7721 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7722 ALint ALmixer_AllocateChannels(ALint numchans) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7723 { |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7724 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7725 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7726 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7727 } |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7728 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7729 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7730 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7731 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7732 #endif |
0 | 7733 retval = Internal_AllocateChannels(numchans); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7734 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7735 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7736 #endif |
0 | 7737 return retval; |
7738 } | |
7739 | |
7740 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7741 ALint ALmixer_ReserveChannels(ALint num) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7742 { |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7743 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7744 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7745 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7746 } |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7747 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7748 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7749 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7750 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7751 #endif |
0 | 7752 retval = Internal_ReserveChannels(num); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7753 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7754 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7755 #endif |
0 | 7756 return retval; |
7757 } | |
7758 | |
7759 | |
7760 | |
7761 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7762 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
|
7763 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7764 ALuint bytes_decoded; |
0 | 7765 ALmixer_Data* ret_data; |
7766 ALenum error; | |
7767 | |
7768 /* Allocate memory */ | |
7769 ret_data = (ALmixer_Data *)malloc(sizeof(ALmixer_Data)); | |
7770 if (NULL == ret_data) | |
7771 { | |
7772 ALmixer_SetError("Out of memory"); | |
7773 return(NULL); | |
7774 } | |
7775 | |
7776 /* Initialize the data fields */ | |
7777 | |
7778 /* Set the Sound_Sample pointer */ | |
7779 ret_data->sample = sample; | |
7780 | |
7781 /* Flag the data to note that it is not in use */ | |
7782 ret_data->in_use = 0; | |
7783 | |
7784 /* Initialize remaining flags */ | |
7785 ret_data->total_time = -1; | |
7786 ret_data->eof = 0; | |
7787 | |
7788 /* Just initialize */ | |
7789 ret_data->num_buffers_in_use = 0; | |
7790 | |
7791 /* Just initialize */ | |
7792 ret_data->total_bytes = 0; | |
7793 | |
7794 /* Just initialize */ | |
7795 ret_data->loaded_bytes = 0; | |
7796 | |
7797 /* Set the max queue buffers (minimum must be 2) */ | |
7798 if(max_queue_buffers < 2) | |
7799 { | |
7800 max_queue_buffers = ALMIXER_DEFAULT_QUEUE_BUFFERS; | |
7801 } | |
7802 ret_data->max_queue_buffers = max_queue_buffers; | |
7803 /* Set up the start up buffers */ | |
7804 if(0 == num_startup_buffers) | |
7805 { | |
7806 num_startup_buffers = ALMIXER_DEFAULT_STARTUP_BUFFERS; | |
7807 } | |
7808 /* Make sure start up buffers is less or equal to max_queue_buffers */ | |
7809 if(num_startup_buffers > max_queue_buffers) | |
7810 { | |
7811 num_startup_buffers = max_queue_buffers; | |
7812 } | |
7813 ret_data->num_startup_buffers = num_startup_buffers; | |
7814 | |
7815 ret_data->buffer_map_list = NULL; | |
7816 ret_data->current_buffer = 0; | |
7817 | |
7818 ret_data->circular_buffer_queue = NULL; | |
7819 | |
7820 /* Now decode and load the data into a data chunk */ | |
7821 /* Different cases for Streamed and Predecoded | |
7822 * Streamed might turn into a predecoded if buffersize | |
7823 * is large enough */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7824 if(AL_FALSE == decode_mode_is_predecoded) |
0 | 7825 { |
7826 bytes_decoded = Sound_Decode(sample); | |
7827 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7828 { | |
7829 ALmixer_SetError(Sound_GetError()); | |
7830 Sound_FreeSample(sample); | |
7831 free(ret_data); | |
7832 return NULL; | |
7833 } | |
7834 | |
7835 /* If no data, return an error */ | |
7836 if(0 == bytes_decoded) | |
7837 { | |
7838 ALmixer_SetError("File has no data"); | |
7839 Sound_FreeSample(sample); | |
7840 free(ret_data); | |
7841 return NULL; | |
7842 } | |
7843 | |
7844 /* Note, currently, my Ogg conservative modifications | |
7845 * prevent EOF from being detected in the first read | |
7846 * because of the weird packet behavior of ov_read(). | |
7847 * The EAGAIN will get set, but not the EOF. | |
7848 * I don't know the best way to handle this, | |
7849 * so for now, Ogg's can only be explicitly | |
7850 * predecoded. | |
7851 */ | |
7852 | |
7853 /* Correction: Since we no longer actually keep the | |
7854 * streamed data we read here (we rewind and throw | |
7855 * it away, and start over on Play), it is | |
7856 * safe to read another chunk to see if we've hit EOF | |
7857 */ | |
7858 if(sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
7859 { | |
7860 bytes_decoded = Sound_Decode(sample); | |
7861 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7862 { | |
7863 ALmixer_SetError(Sound_GetError()); | |
7864 Sound_FreeSample(sample); | |
7865 free(ret_data); | |
7866 return NULL; | |
7867 } | |
7868 } | |
7869 | |
7870 | |
7871 /* If we found an EOF, the entire file was | |
7872 * decoded, so we can treat it like one. | |
7873 */ | |
7874 | |
7875 if(sample->flags & SOUND_SAMPLEFLAG_EOF) | |
7876 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7877 /* |
0 | 7878 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
|
7879 */ |
0 | 7880 ret_data->decoded_all = 1; |
7881 /* Need to keep this information around for | |
7882 * seek and rewind abilities. | |
7883 */ | |
7884 ret_data->total_bytes = bytes_decoded; | |
7885 /* For now, the loaded bytes is the same as total bytes, but | |
7886 * this could change during a seek operation | |
7887 */ | |
7888 ret_data->loaded_bytes = bytes_decoded; | |
7889 | |
7890 /* Let's compute the total playing time | |
7891 * SDL_sound does not yet provide this (we're working on | |
7892 * that at the moment...) | |
7893 */ | |
7894 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
7895 | |
7896 /* Create one element in the buffer array for data for OpanAL */ | |
7897 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
7898 if(NULL == ret_data->buffer) | |
7899 { | |
7900 ALmixer_SetError("Out of Memory"); | |
7901 Sound_FreeSample(sample); | |
7902 free(ret_data); | |
7903 return NULL; | |
7904 } | |
7905 /* Clear the error code */ | |
7906 alGetError(); | |
7907 /* Now generate an OpenAL buffer using that first element */ | |
7908 alGenBuffers(1, ret_data->buffer); | |
7909 if( (error = alGetError()) != AL_NO_ERROR) | |
7910 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7911 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7912 Sound_FreeSample(sample); |
7913 free(ret_data->buffer); | |
7914 free(ret_data); | |
7915 return NULL; | |
7916 } | |
7917 | |
7918 | |
7919 /* Now copy the data to the OpenAL buffer */ | |
7920 /* We can't just set a pointer because the API needs | |
7921 * its own copy to assist hardware acceleration */ | |
7922 alBufferData(ret_data->buffer[0], | |
7923 TranslateFormat(&sample->desired), | |
7924 sample->buffer, | |
7925 bytes_decoded, | |
7926 sample->desired.rate | |
7927 ); | |
7928 if( (error = alGetError()) != AL_NO_ERROR) | |
7929 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7930 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 7931 Sound_FreeSample(sample); |
7932 alDeleteBuffers(1, ret_data->buffer); | |
7933 free(ret_data->buffer); | |
7934 free(ret_data); | |
7935 return NULL; | |
7936 } | |
7937 | |
7938 /* We should be done with the sample since it's all | |
7939 * predecoded. So we can free the memory */ | |
7940 | |
7941 /* Additional notes: | |
7942 * We need to keep data around in case Seek() is needed | |
7943 * or other Sound_AudioInfo is needed. | |
7944 * This can either be done by not deleting the sample, | |
7945 * or it can be done by dynamically recreating it | |
7946 * when we need it. | |
7947 */ | |
7948 /* Since OpenAL won't let us retrieve it | |
7949 * (aka dynamically), we have to keep the Sample | |
7950 * around because since the user requested | |
7951 * streamed and we offered predecoded, | |
7952 * we don't want to mess up the user who | |
7953 * was expecting seek support | |
7954 * So Don't Do anything | |
7955 */ | |
7956 /* | |
7957 if(0 == access_data) | |
7958 { | |
7959 Sound_FreeSample(sample); | |
7960 ret_data->sample = NULL; | |
7961 } | |
7962 */ | |
7963 /* Else, We keep a copy of the sample around. | |
7964 * so don't do anything. | |
7965 */ | |
7966 | |
7967 #if 0 | |
7968 #if defined(DISABLE_PREDECODED_SEEK) | |
7969 Sound_FreeSample(sample); | |
7970 ret_data->sample = NULL; | |
7971 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
7972 Sound_FreeSample(sample); | |
7973 ret_data->sample = NULL; | |
7974 #else | |
7975 /* We keep a copy of the sample around. | |
7976 * so don't do anything. | |
7977 */ | |
7978 #endif | |
7979 #endif | |
7980 /* okay we're done here */ | |
7981 | |
7982 } | |
7983 /* Else, we need to stream the data, so we'll | |
7984 * create multple buffers for queuing */ | |
7985 else | |
7986 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7987 /* |
0 | 7988 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
|
7989 */ |
0 | 7990 ret_data->decoded_all = 0; |
7991 | |
7992 /* This information is for predecoded. | |
7993 * Set to 0, since we don't know. | |
7994 */ | |
7995 ret_data->total_bytes = 0; | |
7996 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7997 ret_data->total_time = Sound_GetDuration(sample); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7998 |
0 | 7999 /* Create buffers for data |
8000 */ | |
8001 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) * max_queue_buffers); | |
8002 if(NULL == ret_data->buffer) | |
8003 { | |
8004 ALmixer_SetError("Out of Memory"); | |
8005 Sound_FreeSample(sample); | |
8006 free(ret_data); | |
8007 return NULL; | |
8008 } | |
8009 | |
8010 /* Clear the error code */ | |
8011 alGetError(); | |
8012 /* Now generate an OpenAL buffer using that first element */ | |
8013 alGenBuffers(max_queue_buffers, ret_data->buffer); | |
8014 if( (error = alGetError()) != AL_NO_ERROR) | |
8015 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8016 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 8017 Sound_FreeSample(sample); |
8018 free(ret_data->buffer); | |
8019 free(ret_data); | |
8020 return NULL; | |
8021 } | |
8022 | |
8023 /* Redesign: Okay, because of the unqueuing problems and such, | |
8024 * I've decided to redesign where and how queuing is handled. | |
8025 * Before, everything was queued up here. However, this | |
8026 * placed a penalty on load and made performance inconsistent | |
8027 * when samples had to be rewound. It did make things easier | |
8028 * to queue because I could let OpenAL decide which buffer | |
8029 * needed to be queued next. | |
8030 * Now, I'm going to push off the queuing to the actual | |
8031 * Play() command. I'm going to add some book keeping, | |
8032 * and allow for additional buffers to be filled at later | |
8033 * times. | |
8034 */ | |
8035 | |
8036 | |
8037 /* So first of all, because of I already decoded the sample | |
8038 * for testing, I need to decide what to do with it. | |
8039 * The best thing would be be to alBufferData() it. | |
8040 * The problem is it may conflict with the rest of | |
8041 * the system because everything now assumes buffers | |
8042 * are entirely stripped (because of the unqueing | |
8043 * problem). | |
8044 * So it looks like I have to do the crappy thing | |
8045 * and throw away the data, and rewind. | |
8046 */ | |
8047 | |
8048 if(0 == Sound_Rewind(ret_data->sample)) | |
8049 { | |
8050 ALmixer_SetError("Cannot use sample for streamed data because it must be rewindable: %s", Sound_GetError() ); | |
8051 Sound_FreeSample(sample); | |
8052 free(ret_data->buffer); | |
8053 free(ret_data); | |
8054 return NULL; | |
8055 } | |
8056 | |
8057 | |
8058 /* If the user has selected access_data, we need to | |
8059 * keep copies of the queuing buffers around because | |
8060 * OpenAL won't let us access the data. | |
8061 * Allocate the memory for the buffers here | |
8062 * and initialize the albuffer-index map | |
8063 */ | |
8064 if(access_data) | |
8065 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8066 ALuint j; |
0 | 8067 /* Create buffers for data access |
8068 * Should be the same number as the number of queue buffers | |
8069 */ | |
1 | 8070 ret_data->buffer_map_list = (ALmixer_Buffer_Map*)malloc( sizeof(ALmixer_Buffer_Map) * max_queue_buffers); |
0 | 8071 if(NULL == ret_data->buffer_map_list) |
8072 { | |
8073 ALmixer_SetError("Out of Memory"); | |
8074 Sound_FreeSample(sample); | |
8075 free(ret_data->buffer); | |
8076 free(ret_data); | |
8077 return NULL; | |
8078 } | |
8079 | |
8080 ret_data->circular_buffer_queue = CircularQueueUnsignedInt_CreateQueue(max_queue_buffers); | |
8081 if(NULL == ret_data->circular_buffer_queue) | |
8082 { | |
8083 ALmixer_SetError("Out of Memory"); | |
8084 free(ret_data->buffer_map_list); | |
8085 Sound_FreeSample(sample); | |
8086 free(ret_data->buffer); | |
8087 free(ret_data); | |
8088 return NULL; | |
8089 } | |
8090 | |
8091 | |
8092 for(j=0; j<max_queue_buffers; j++) | |
8093 { | |
8094 ret_data->buffer_map_list[j].albuffer = ret_data->buffer[j]; | |
8095 ret_data->buffer_map_list[j].index = j; | |
8096 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
|
8097 ret_data->buffer_map_list[j].data = (ALbyte*)malloc( sizeof(ALbyte) * buffersize); |
0 | 8098 if(NULL == ret_data->buffer_map_list[j].data) |
8099 { | |
8100 ALmixer_SetError("Out of Memory"); | |
8101 break; | |
8102 } | |
8103 } | |
8104 /* If an error happened, we have to clean up the memory */ | |
8105 if(j < max_queue_buffers) | |
8106 { | |
8107 fprintf(stderr, "################## Buffer allocation failed\n"); | |
8108 for( ; j>=0; j--) | |
8109 { | |
8110 free(ret_data->buffer_map_list[j].data); | |
8111 } | |
8112 free(ret_data->buffer_map_list); | |
8113 CircularQueueUnsignedInt_FreeQueue(ret_data->circular_buffer_queue); | |
8114 Sound_FreeSample(sample); | |
8115 free(ret_data->buffer); | |
8116 free(ret_data); | |
8117 return NULL; | |
8118 } | |
8119 | |
8120 /* The Buffer_Map_List must be sorted by albuffer for binary searches | |
8121 */ | |
1 | 8122 qsort(ret_data->buffer_map_list, max_queue_buffers, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 8123 } /* End if access_data==true */ |
8124 | |
8125 | |
8126 } /* End of do stream */ | |
8127 } /* end of DECODE_STREAM */ | |
8128 /* 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
|
8129 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
|
8130 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8131 #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
|
8132 /* 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
|
8133 * 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
|
8134 * 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
|
8135 * so looping isn't needed. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8136 * 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
|
8137 * 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
|
8138 * 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
|
8139 * 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
|
8140 * 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
|
8141 * 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
|
8142 * to load a file. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8143 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8144 ALint sound_duration = Sound_GetDuration(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8145 if(sound_duration > 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8146 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8147 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
|
8148 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
|
8149 if(0 == buffer_resize_succeeded) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8150 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8151 ALmixer_SetError(Sound_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8152 Sound_FreeSample(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8153 free(ret_data); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8154 return NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8155 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8156 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8157 #endif /* ALMIXER_DISABLE_PREDECODED_PRECOMPUTE_BUFFER_SIZE_OPTIMIZATION */ |
0 | 8158 bytes_decoded = Sound_DecodeAll(sample); |
8159 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
8160 { | |
8161 ALmixer_SetError(Sound_GetError()); | |
8162 Sound_FreeSample(sample); | |
8163 free(ret_data); | |
8164 return NULL; | |
8165 } | |
8166 | |
8167 /* If no data, return an error */ | |
8168 if(0 == bytes_decoded) | |
8169 { | |
8170 ALmixer_SetError("File has no data"); | |
8171 Sound_FreeSample(sample); | |
8172 free(ret_data); | |
8173 return NULL; | |
8174 } | |
8175 | |
8176 | |
8177 ret_data->decoded_all = 1; | |
8178 /* Need to keep this information around for | |
8179 * seek and rewind abilities. | |
8180 */ | |
8181 ret_data->total_bytes = bytes_decoded; | |
8182 /* For now, the loaded bytes is the same as total bytes, but | |
8183 * this could change during a seek operation | |
8184 */ | |
8185 ret_data->loaded_bytes = bytes_decoded; | |
8186 | |
8187 /* Let's compute the total playing time | |
8188 * SDL_sound does not yet provide this (we're working on | |
8189 * that at the moment...) | |
8190 */ | |
8191 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
8192 | |
8193 /* Create one element in the buffer array for data for OpanAL */ | |
8194 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
8195 if(NULL == ret_data->buffer) | |
8196 { | |
8197 ALmixer_SetError("Out of Memory"); | |
8198 Sound_FreeSample(sample); | |
8199 free(ret_data); | |
8200 return NULL; | |
8201 } | |
8202 /* Clear the error code */ | |
8203 alGetError(); | |
8204 /* Now generate an OpenAL buffer using that first element */ | |
8205 alGenBuffers(1, ret_data->buffer); | |
8206 if( (error = alGetError()) != AL_NO_ERROR) | |
8207 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8208 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 8209 Sound_FreeSample(sample); |
8210 free(ret_data->buffer); | |
8211 free(ret_data); | |
8212 return NULL; | |
8213 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8214 /* |
0 | 8215 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
|
8216 */ |
0 | 8217 /* Now copy the data to the OpenAL buffer */ |
8218 /* We can't just set a pointer because the API needs | |
8219 * its own copy to assist hardware acceleration */ | |
8220 alBufferData(ret_data->buffer[0], | |
8221 TranslateFormat(&sample->desired), | |
8222 sample->buffer, | |
8223 bytes_decoded, | |
8224 sample->desired.rate | |
8225 ); | |
8226 if( (error = alGetError()) != AL_NO_ERROR) | |
8227 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8228 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 8229 Sound_FreeSample(sample); |
8230 alDeleteBuffers(1, ret_data->buffer); | |
8231 free(ret_data->buffer); | |
8232 free(ret_data); | |
8233 return NULL; | |
8234 } | |
8235 | |
8236 /* We should be done with the sample since it's all | |
8237 * predecoded. So we can free the memory */ | |
8238 /* Need to keep around because Seek() needs it */ | |
8239 | |
8240 /* Additional notes: | |
8241 * We need to keep data around in case Seek() is needed | |
8242 * or other Sound_AudioInfo is needed. | |
8243 * This can either be done by not deleting the sample, | |
8244 * or it can be done by dynamically recreating it | |
8245 * when we need it. | |
8246 * Update: I think now it's up to the user by passing the | |
8247 * access_data flag. If they set the flag, then they get | |
8248 * data callbacks and seek support. If not, then they can | |
8249 * get all that stuff at the expense of keeping extra memory | |
8250 * around. | |
8251 */ | |
8252 if(0 == access_data) | |
8253 { | |
8254 Sound_FreeSample(sample); | |
8255 ret_data->sample = NULL; | |
8256 } | |
8257 | |
8258 /* Else, We keep a copy of the sample around. | |
8259 * so don't do anything. | |
8260 */ | |
8261 #if 0 | |
8262 #if defined(DISABLE_PREDECODED_SEEK) | |
8263 Sound_FreeSample(sample); | |
8264 ret_data->sample = NULL; | |
8265 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
8266 Sound_FreeSample(sample); | |
8267 ret_data->sample = NULL; | |
8268 #else | |
8269 /* We keep a copy of the sample around. | |
8270 * so don't do anything. | |
8271 */ | |
8272 #endif | |
8273 #endif | |
8274 | |
8275 /* okay we're done here */ | |
8276 } | |
8277 else | |
8278 { | |
8279 /* Shouldn't get here */ | |
8280 ALmixer_SetError("Unknown decode mode"); | |
8281 Sound_FreeSample(sample); | |
8282 free(ret_data); | |
8283 return NULL; | |
8284 } | |
8285 | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8286 /* 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
|
8287 * 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
|
8288 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8289 LinkedList_PushBack(s_listOfALmixerData, ret_data); |
0 | 8290 return ret_data; |
8291 } | |
8292 | |
8293 | |
8294 /* This will load a sample for us. Most of the uglyness is | |
8295 * error checking and the fact that streamed/predecoded files | |
8296 * must be treated differently. | |
8297 * I don't like the AudioInfo parameter. I removed it once, | |
8298 * but the system will fail on RAW samples because the user | |
8299 * must specify it, so I had to bring it back. | |
8300 * Remember I must close the rwops if there is an error before NewSample() | |
8301 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8302 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 | 8303 { |
8304 Sound_Sample* sample = NULL; | |
8305 Sound_AudioInfo target; | |
8306 | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8307 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8308 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8309 return NULL; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8310 } |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8311 |
0 | 8312 /* Initialize target values to defaults |
8313 * 0 tells SDL_sound to use the "actual" values | |
8314 */ | |
8315 target.channels = 0; | |
8316 target.rate = 0; | |
8317 #if 0 | |
8318 /* This requires my new additions to SDL_sound. It will | |
8319 * convert the sample to the proper endian order. | |
8320 * If the actual is 8-bit, it will do unsigned, if | |
8321 * the actual is 16-bit, it will do signed. | |
8322 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
8323 * in this way. | |
8324 */ | |
8325 target.format = AUDIO_U8S16SYS; | |
8326 #else | |
8327 target.format = AUDIO_S16SYS; | |
8328 #endif | |
8329 | |
8330 /* Set a default buffersize if needed */ | |
8331 if(0 == buffersize) | |
8332 { | |
8333 buffersize = ALMIXER_DEFAULT_BUFFERSIZE; | |
8334 } | |
8335 | |
8336 sample = Sound_NewSample(rwops, fileext, &target, buffersize); | |
8337 if(NULL == sample) | |
8338 { | |
8339 ALmixer_SetError(Sound_GetError()); | |
8340 return NULL; | |
8341 } | |
8342 | |
1 | 8343 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8344 } |
8345 | |
8346 | |
8347 | |
8348 /* This will load a sample for us from | |
8349 * a file (instead of RWops). Most of the uglyness is | |
8350 * error checking and the fact that streamed/predecoded files | |
8351 * must be treated differently. | |
8352 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8353 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 | 8354 { |
8355 Sound_Sample* sample = NULL; | |
8356 Sound_AudioInfo target; | |
8357 | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8358 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8359 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8360 return NULL; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8361 } |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8362 |
0 | 8363 /* Initialize target values to defaults |
8364 * 0 tells SDL_sound to use the "actual" values | |
8365 */ | |
8366 target.channels = 0; | |
8367 target.rate = 0; | |
8368 | |
8369 #if 0 | |
8370 /* This requires my new additions to SDL_sound. It will | |
8371 * convert the sample to the proper endian order. | |
8372 * If the actual is 8-bit, it will do unsigned, if | |
8373 * the actual is 16-bit, it will do signed. | |
8374 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
8375 * in this way. | |
8376 */ | |
8377 target.format = AUDIO_U8S16SYS; | |
8378 #else | |
8379 target.format = AUDIO_S16SYS; | |
8380 #endif | |
8381 | |
8382 #if 0 | |
8383 /* Okay, here's a messy hack. The problem is that we need | |
8384 * to convert the sample to have the correct bitdepth, | |
8385 * endian order, and signedness values. | |
8386 * The bit depth is 8 or 16. | |
8387 * The endian order is the native order of the system. | |
8388 * The signedness depends on what the original value | |
8389 * of the sample. Unfortunately, we can't specify these | |
8390 * values until we after we already know what the original | |
8391 * values were for bitdepth and signedness. | |
8392 * So we must open the file once to get the values, | |
8393 * then close it, and then reopen it with the | |
8394 * correct desired target values. | |
8395 * I tried changing the sample->desired field after | |
8396 * the NewSample call, but it had no effect, so | |
8397 * it looks like it must be set on open. | |
8398 */ | |
8399 /* Pick a small buffersize for the first open to not | |
8400 * waste much time allocating memory */ | |
8401 sample = Sound_NewSampleFromFile(filename, NULL, 512); | |
8402 if(NULL == sample) | |
8403 { | |
8404 ALmixer_SetError(Sound_GetError()); | |
8405 return NULL; | |
8406 } | |
8407 | |
8408 bit_depth = GetBitDepth(sample->actual.format); | |
8409 signedness_value = GetSignednessValue(sample->actual.format); | |
8410 if(8 == bit_depth) | |
8411 { | |
8412 /* If 8 bit, then we don't have to worry about | |
8413 * endian issues. We can just use the actual format | |
8414 * value and it should do the right thing | |
8415 */ | |
8416 target.format = sample->actual.format; | |
8417 } | |
8418 else | |
8419 { | |
8420 /* We'll assume it's 16-bit, and if it's not | |
8421 * hopefully SDL_sound will return an error, | |
8422 * or let us convert to 16-bit | |
8423 */ | |
8424 /* Now we need to get the correct signedness */ | |
8425 if(ALMIXER_UNSIGNED_VALUE == signedness_value) | |
8426 { | |
8427 /* Set to Unsigned 16-bit, system endian order */ | |
8428 target.format = AUDIO_U16SYS; | |
8429 } | |
8430 else | |
8431 { | |
8432 /* Again, we'll assume it's Signed 16-bit system order | |
8433 * or force the conversion and hope it works out | |
8434 */ | |
8435 target.format = AUDIO_S16SYS; | |
8436 } | |
8437 } | |
8438 | |
8439 /* Now we have the correct info. We need to close and reopen */ | |
8440 Sound_FreeSample(sample); | |
8441 #endif | |
8442 | |
8443 sample = Sound_NewSampleFromFile(filename, &target, buffersize); | |
8444 if(NULL == sample) | |
8445 { | |
8446 ALmixer_SetError(Sound_GetError()); | |
8447 return NULL; | |
8448 } | |
8449 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8450 /* |
0 | 8451 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
|
8452 */ |
1 | 8453 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8454 } |
8455 | |
8456 | |
8457 /* This is a back door for RAW samples or if you need the | |
8458 * AudioInfo field. Use at your own risk. | |
8459 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8460 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 | 8461 { |
8462 Sound_Sample* sample = NULL; | |
1 | 8463 Sound_AudioInfo sound_desired; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8464 |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8465 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8466 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8467 return NULL; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8468 } |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8469 |
1 | 8470 /* Rather than copying the data from struct to struct, I could just |
8471 * cast the thing since the structs are meant to be identical. | |
8472 * But if SDL_sound changes it's implementation, bad things | |
8473 * will probably happen. (Or if I change my implementation and | |
8474 * forget about the cast, same bad scenario.) Since this is a load | |
8475 * function, performance of this is negligible. | |
8476 */ | |
8477 if(NULL == desired) | |
8478 { | |
8479 sample = Sound_NewSample(rwops, fileext, NULL, buffersize); | |
8480 } | |
8481 else | |
8482 { | |
8483 sound_desired.format = desired->format; | |
8484 sound_desired.channels = desired->channels; | |
8485 sound_desired.rate = desired->rate; | |
8486 sample = Sound_NewSample(rwops, fileext, &sound_desired, buffersize); | |
8487 } | |
0 | 8488 if(NULL == sample) |
8489 { | |
8490 ALmixer_SetError(Sound_GetError()); | |
8491 return NULL; | |
8492 } | |
1 | 8493 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8494 } |
8495 | |
8496 | |
8497 | |
8498 | |
8499 /* This is a back door for RAW samples or if you need the | |
8500 * AudioInfo field. Use at your own risk. | |
8501 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8502 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 | 8503 { |
8504 Sound_Sample* sample = NULL; | |
1 | 8505 Sound_AudioInfo sound_desired; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8506 |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8507 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8508 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8509 return; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8510 } |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8511 |
1 | 8512 /* Rather than copying the data from struct to struct, I could just |
8513 * cast the thing since the structs are meant to be identical. | |
8514 * But if SDL_sound changes it's implementation, bad things | |
8515 * will probably happen. (Or if I change my implementation and | |
8516 * forget about the cast, same bad scenario.) Since this is a load | |
8517 * function, performance of this is negligible. | |
8518 */ | |
8519 if(NULL == desired) | |
8520 { | |
8521 sample = Sound_NewSampleFromFile(filename, NULL, buffersize); | |
8522 } | |
8523 else | |
8524 { | |
8525 sound_desired.format = desired->format; | |
8526 sound_desired.channels = desired->channels; | |
8527 sound_desired.rate = desired->rate; | |
8528 sample = Sound_NewSampleFromFile(filename, &sound_desired, buffersize); | |
8529 } | |
8530 | |
0 | 8531 if(NULL == sample) |
8532 { | |
8533 ALmixer_SetError(Sound_GetError()); | |
8534 return NULL; | |
8535 } | |
1 | 8536 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8537 } |
8538 | |
8539 | |
8540 | |
8541 | |
8542 void ALmixer_FreeData(ALmixer_Data* data) | |
8543 { | |
8544 ALenum error; | |
8545 if(NULL == data) | |
8546 { | |
8547 return; | |
8548 } | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8549 |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8550 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8551 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8552 return; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8553 } |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8554 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8555 /* Bypass if in interruption event */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8556 if(NULL == alcGetCurrentContext()) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8557 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8558 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
|
8559 return; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8560 } |
0 | 8561 |
8562 if(data->decoded_all) | |
8563 { | |
8564 /* If access_data was enabled, then the Sound_Sample* | |
8565 * still exists. We need to free it | |
8566 */ | |
8567 if(data->sample != NULL) | |
8568 { | |
8569 Sound_FreeSample(data->sample); | |
8570 } | |
8571 alDeleteBuffers(1, data->buffer); | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8572 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8573 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8574 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
|
8575 } |
0 | 8576 } |
8577 else | |
8578 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8579 ALuint i; |
0 | 8580 |
8581 /* Delete buffer copies if access_data was enabled */ | |
8582 if(data->buffer_map_list != NULL) | |
8583 { | |
8584 for(i=0; i<data->max_queue_buffers; i++) | |
8585 { | |
8586 free(data->buffer_map_list[i].data); | |
8587 } | |
8588 free(data->buffer_map_list); | |
8589 } | |
8590 if(data->circular_buffer_queue != NULL) | |
8591 { | |
8592 CircularQueueUnsignedInt_FreeQueue(data->circular_buffer_queue); | |
8593 } | |
8594 | |
8595 Sound_FreeSample(data->sample); | |
8596 alDeleteBuffers(data->max_queue_buffers, data->buffer); | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8597 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8598 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8599 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
|
8600 } |
0 | 8601 } |
8602 free(data->buffer); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8603 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8604 LinkedList_Remove(s_listOfALmixerData, |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8605 LinkedList_Find(s_listOfALmixerData, data, NULL) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8606 ); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8607 |
0 | 8608 free(data); |
8609 } | |
8610 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8611 ALint ALmixer_GetTotalTime(ALmixer_Data* 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 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8614 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8615 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8616 } |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8617 |
0 | 8618 return data->total_time; |
8619 } | |
8620 | |
8621 /* This function will look up the source for the corresponding channel */ | |
8622 /* 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
|
8623 ALuint ALmixer_GetSource(ALint channel) |
0 | 8624 { |
8625 ALuint retval; | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8626 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8627 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8628 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8629 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8630 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8631 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8632 #endif |
0 | 8633 retval = Internal_GetSource(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8634 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8635 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8636 #endif |
0 | 8637 return retval; |
8638 } | |
8639 | |
8640 /* 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
|
8641 ALint ALmixer_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8642 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8643 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8644 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8645 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8646 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8647 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8648 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8649 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8650 #endif |
0 | 8651 retval = Internal_GetChannel(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8652 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8653 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8654 #endif |
0 | 8655 return retval; |
8656 } | |
8657 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8658 ALint ALmixer_FindFreeChannel(ALint start_channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8659 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8660 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8661 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8662 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8663 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8664 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8665 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8666 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8667 #endif |
0 | 8668 retval = Internal_FindFreeChannel(start_channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8669 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8670 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8671 #endif |
0 | 8672 return retval; |
8673 } | |
8674 | |
8675 | |
8676 | |
8677 /* API update function. | |
8678 * It should return the number of buffers that were | |
8679 * queued during the call. The value might be | |
8680 * used to guage how long you might wait to | |
8681 * call the next update loop in case you are worried | |
8682 * about preserving CPU cycles. The idea is that | |
8683 * when a buffer is queued, there was probably some | |
8684 * CPU intensive looping which took awhile. | |
8685 * 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
|
8686 * Timing the call with ALmixer_GetTicks() would produce |
0 | 8687 * more accurate information. |
8688 * Returns a negative value if there was an error, | |
8689 * the value being the number of errors. | |
8690 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8691 ALint ALmixer_Update() |
0 | 8692 { |
8693 #ifdef ENABLE_ALMIXER_THREADS | |
8694 /* The thread will handle all updates by itself. | |
8695 * Don't allow the user to explicitly call update. | |
8696 */ | |
8697 return 0; | |
8698 #else | |
8699 return( Update_ALmixer(NULL) ); | |
8700 #endif | |
8701 } | |
8702 | |
8703 | |
8704 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8705 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
|
8706 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8707 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8708 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8709 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8710 Channel_Done_Callback = playback_finished_callback; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8711 Channel_Done_Callback_Userdata = user_data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8712 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8713 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8714 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8715 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8716 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8717 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8718 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
|
8719 { |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8723 Channel_Data_Callback = playback_data_callback; |
1 | 8724 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
|
8725 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8726 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8727 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8728 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8729 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8730 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8731 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8732 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8733 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8734 ALint 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
|
8735 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8736 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8737 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8738 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8739 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8740 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8741 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8742 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8743 #endif |
0 | 8744 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
|
8745 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8746 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8747 #endif |
0 | 8748 return retval; |
8749 } | |
8750 | |
8751 | |
8752 /* In case the user wants to specify a source instead of a channel, | |
8753 * they may use this function. This function will look up the | |
8754 * source-to-channel map, and convert the call into a | |
8755 * PlayChannelTimed() function call. | |
8756 * Returns the channel it's being played on. | |
8757 * Note: If you are prefer this method, then you need to be careful | |
8758 * about using PlayChannel, particularly if you request the | |
8759 * first available channels because source and channels have | |
8760 * a one-to-one mapping in this API. It is quite easy for | |
8761 * a channel/source to already be in use because of this. | |
8762 * In this event, an error message will be returned to you. | |
8763 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8764 ALuint ALmixer_PlaySourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALint ticks) |
0 | 8765 { |
8766 ALuint retval; | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8767 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8768 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8769 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8770 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8771 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8772 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8773 #endif |
0 | 8774 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
|
8775 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8776 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8777 #endif |
0 | 8778 return retval; |
8779 } | |
8780 | |
8781 | |
8782 /* Will return the number of channels halted | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8783 * or -1 for error |
0 | 8784 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8785 ALint ALmixer_HaltChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8786 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8787 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8788 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8789 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8790 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8791 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8792 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8793 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8794 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8795 retval = Internal_HaltChannel(channel, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8796 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8797 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8798 #endif |
0 | 8799 return retval; |
8800 } | |
8801 | |
8802 /* Will return the number of channels halted | |
8803 * or 0 for error | |
8804 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8805 ALint ALmixer_HaltSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8806 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8807 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8808 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8809 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8810 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8811 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8812 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8813 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8814 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8815 retval = Internal_HaltSource(source, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8816 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8817 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8818 #endif |
0 | 8819 return retval; |
8820 } | |
8821 | |
8822 | |
8823 /* This will rewind the SDL_Sound sample for streamed | |
8824 * samples and start buffering up the data for the next | |
8825 * playback. This may require samples to be halted | |
8826 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8827 ALboolean ALmixer_RewindData(ALmixer_Data* data) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8828 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8829 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8830 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8831 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8832 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8833 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8834 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8835 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8836 #endif |
0 | 8837 retval = Internal_RewindData(data); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8838 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8839 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8840 #endif |
0 | 8841 return retval; |
8842 } | |
8843 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8844 ALint ALmixer_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8845 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8846 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8847 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8848 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8849 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8850 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8851 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8852 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8853 #endif |
0 | 8854 retval = Internal_RewindChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8855 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8856 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8857 #endif |
0 | 8858 return retval; |
8859 } | |
8860 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8861 ALint ALmixer_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8862 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8863 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8864 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8865 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8866 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8867 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8868 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8869 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8870 #endif |
0 | 8871 retval = Internal_RewindSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8872 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8873 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8874 #endif |
0 | 8875 return retval; |
8876 } | |
8877 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8878 ALint ALmixer_PauseChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8879 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8880 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8881 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8882 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8883 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8884 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8885 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8886 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8887 #endif |
0 | 8888 retval = Internal_PauseChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8889 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8890 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8891 #endif |
0 | 8892 return retval; |
8893 } | |
8894 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8895 ALint ALmixer_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8896 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8897 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8898 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8899 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8900 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8901 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8902 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8903 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8904 #endif |
0 | 8905 retval = Internal_PauseSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8906 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8907 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8908 #endif |
0 | 8909 return retval; |
8910 } | |
8911 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8912 ALint ALmixer_ResumeChannel(ALint channel) |
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 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8915 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8916 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8917 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8918 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8919 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8920 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8921 #endif |
0 | 8922 retval = Internal_ResumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8923 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8924 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8925 #endif |
0 | 8926 return retval; |
8927 } | |
8928 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8929 ALint ALmixer_ResumeSource(ALuint source) |
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 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8932 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8933 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8934 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8935 } |
2
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8938 #endif |
0 | 8939 retval = Internal_ResumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8940 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8941 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8942 #endif |
0 | 8943 return retval; |
8944 } | |
8945 | |
8946 /* Might consider setting eof to 0 as a "feature" | |
8947 * This will allow seek to end to stay there because | |
8948 * Play automatically rewinds if at the end */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8949 ALboolean ALmixer_SeekData(ALmixer_Data* data, ALuint msec) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8950 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8951 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8952 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8953 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8954 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8955 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8956 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8957 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8958 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8959 retval = Internal_SeekData(data, msec); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8960 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8961 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8962 #endif |
0 | 8963 return retval; |
8964 } | |
8965 | |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8966 ALint ALmixer_SeekChannel(ALint channel, ALuint msec) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8967 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8968 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8969 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8970 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8971 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8972 } |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8973 #ifdef ENABLE_ALMIXER_THREADS |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8974 SDL_LockMutex(s_simpleLock); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8975 #endif |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8976 retval = Internal_SeekChannel(channel, msec); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8977 #ifdef ENABLE_ALMIXER_THREADS |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8978 SDL_UnlockMutex(s_simpleLock); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8979 #endif |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8980 return retval; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8981 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8982 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8983 ALint ALmixer_SeekSource(ALuint source, ALuint msec) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8984 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8985 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8986 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8987 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8988 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8989 } |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8990 #ifdef ENABLE_ALMIXER_THREADS |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8991 SDL_LockMutex(s_simpleLock); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8992 #endif |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8993 retval = Internal_SeekSource(source, msec); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8994 #ifdef ENABLE_ALMIXER_THREADS |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8995 SDL_UnlockMutex(s_simpleLock); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8996 #endif |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8997 return retval; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8998 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8999 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9000 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
|
9001 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9002 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9003 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9004 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9005 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9006 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9007 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9008 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9009 #endif |
0 | 9010 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
|
9011 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9012 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9013 #endif |
0 | 9014 return retval; |
9015 } | |
9016 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9017 ALuint ALmixer_FadeInSourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 9018 { |
9019 ALuint retval; | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9020 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9021 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9022 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9023 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9024 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9025 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9026 #endif |
0 | 9027 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
|
9028 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9029 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9030 #endif |
0 | 9031 return retval; |
9032 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9033 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9034 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
|
9035 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9036 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9037 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9038 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9039 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9040 } |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9043 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9044 retval = Internal_FadeOutChannel(channel, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9045 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9046 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9047 #endif |
0 | 9048 return retval; |
9049 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9050 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9051 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
|
9052 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9053 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9054 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9055 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9056 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9057 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9058 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9059 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9060 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9061 retval = Internal_FadeOutSource(source, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9062 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9063 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9064 #endif |
0 | 9065 return retval; |
9066 } | |
9067 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9068 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
|
9069 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9070 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9071 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9072 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9073 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9074 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9075 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9076 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9077 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9078 retval = Internal_FadeChannel(channel, ticks, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9079 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9080 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9081 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9082 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9083 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9084 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9085 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
|
9086 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9087 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9088 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9089 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9090 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9091 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9092 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9093 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9094 #endif |
0 | 9095 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
|
9096 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9097 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9098 #endif |
0 | 9099 return retval; |
9100 } | |
9101 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9102 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9103 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
|
9104 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9105 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9106 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9107 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9108 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9109 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9110 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9111 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9112 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9113 retval = Internal_SetVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9114 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9115 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9116 #endif |
0 | 9117 return retval; |
9118 } | |
9119 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9120 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
|
9121 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9122 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9123 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9124 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9125 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9126 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9127 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9128 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9129 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9130 retval = Internal_SetVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9131 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9132 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9133 #endif |
0 | 9134 return retval; |
9135 } | |
9136 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9137 ALfloat ALmixer_GetVolumeChannel(ALint channel) |
0 | 9138 { |
9139 ALfloat retval; | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9140 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9141 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9142 return -1.0f; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9143 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9144 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9145 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9146 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9147 retval = Internal_GetVolumeChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9148 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9149 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9150 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9151 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9152 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9153 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9154 ALfloat ALmixer_GetVolumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9155 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9156 ALfloat retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9157 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9158 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9159 return -1.0f; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9160 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9161 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9162 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9163 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9164 retval = Internal_GetVolumeSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9165 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9166 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9167 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9168 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9169 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9170 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9171 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
|
9172 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9173 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9174 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9175 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9176 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9177 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9178 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9179 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9180 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9181 retval = Internal_SetMaxVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9182 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9183 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9184 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9185 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9186 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9187 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9188 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
|
9189 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9190 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9191 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9192 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9193 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9194 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9195 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9196 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9197 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9198 retval = Internal_SetMaxVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9199 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9200 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9201 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9202 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9203 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9204 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9205 ALfloat ALmixer_GetMaxVolumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9206 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9207 ALfloat retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9208 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9209 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9210 return -1.0f; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9211 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9212 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9213 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9214 #endif |
0 | 9215 retval = Internal_GetMaxVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9216 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9217 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9218 #endif |
0 | 9219 return retval; |
9220 } | |
9221 | |
9222 ALfloat ALmixer_GetMaxVolumeSource(ALuint source) | |
9223 { | |
9224 ALfloat retval; | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9225 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9226 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9227 return -1.0f; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9228 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9229 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9230 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9231 #endif |
0 | 9232 retval = Internal_GetMaxVolumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9233 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9234 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9235 #endif |
0 | 9236 return retval; |
9237 } | |
9238 | |
9239 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9240 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
|
9241 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9242 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9243 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9244 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9245 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9246 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9247 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9248 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9249 #endif |
0 | 9250 retval = Internal_SetMinVolumeChannel(channel, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9251 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9252 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9253 #endif |
0 | 9254 return retval; |
9255 } | |
9256 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9257 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
|
9258 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9259 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9260 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9261 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9262 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9263 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9264 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9265 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9266 #endif |
0 | 9267 retval = Internal_SetMinVolumeSource(source, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9268 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9269 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9270 #endif |
0 | 9271 return retval; |
9272 } | |
9273 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9274 ALfloat ALmixer_GetMinVolumeChannel(ALint channel) |
0 | 9275 { |
9276 ALfloat retval; | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9277 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9278 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9279 return -1.0f; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9280 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9281 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9282 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9283 #endif |
0 | 9284 retval = Internal_GetMinVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9285 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9286 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9287 #endif |
0 | 9288 return retval; |
9289 } | |
9290 | |
9291 ALfloat ALmixer_GetMinVolumeSource(ALuint source) | |
9292 { | |
9293 ALfloat retval; | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9294 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9295 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9296 return -1.0f; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9297 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9298 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9299 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9300 #endif |
0 | 9301 retval = Internal_GetMinVolumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9302 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9303 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9304 #endif |
0 | 9305 return retval; |
9306 } | |
9307 | |
9308 | |
9309 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9310 ALboolean ALmixer_SetMasterVolume(ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9311 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9312 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9313 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9314 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9315 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9316 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9317 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9318 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9319 #endif |
0 | 9320 retval = Internal_SetMasterVolume(volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9321 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9322 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9323 #endif |
0 | 9324 return retval; |
9325 } | |
9326 | |
9327 ALfloat ALmixer_GetMasterVolume() | |
9328 { | |
9329 ALfloat retval; | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9330 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9331 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9332 return -1.0f; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9333 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9334 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9335 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9336 #endif |
0 | 9337 retval = Internal_GetMasterVolume(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9338 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9339 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9340 #endif |
0 | 9341 return retval; |
9342 } | |
9343 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9344 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
|
9345 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9346 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9347 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9348 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9349 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9350 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9351 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9352 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9353 #endif |
0 | 9354 retval = Internal_ExpireChannel(channel, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9355 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9356 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9357 #endif |
0 | 9358 return retval; |
9359 } | |
9360 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9361 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
|
9362 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9363 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9364 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9365 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9366 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9367 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9368 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9369 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9370 #endif |
0 | 9371 retval = Internal_ExpireSource(source, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9372 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9373 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9374 #endif |
0 | 9375 return retval; |
9376 } | |
9377 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9378 ALint ALmixer_IsActiveChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9379 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9380 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9381 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9382 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9383 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9384 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9385 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9386 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9387 #endif |
0 | 9388 retval = Internal_QueryChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9389 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9390 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9391 #endif |
0 | 9392 return retval; |
9393 } | |
9394 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9395 ALint ALmixer_IsActiveSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9396 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9397 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9398 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9399 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9400 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9401 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9402 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9403 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9404 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9405 retval = Internal_QuerySource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9406 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9407 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9408 #endif |
0 | 9409 return retval; |
9410 } | |
9411 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9412 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9413 ALint ALmixer_IsPlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9414 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9415 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9416 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9417 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9418 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9419 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9420 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9421 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9422 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9423 retval = Internal_PlayingChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9424 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9425 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9426 #endif |
0 | 9427 return retval; |
9428 } | |
9429 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9430 ALint ALmixer_IsPlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9431 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9432 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9433 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9434 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9435 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9436 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9437 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9438 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9439 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9440 retval = Internal_PlayingSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9441 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9442 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9443 #endif |
0 | 9444 return retval; |
9445 } | |
9446 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9447 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9448 ALint ALmixer_IsPausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9449 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9450 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9451 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9452 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9453 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9454 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9455 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9456 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9457 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9458 retval = Internal_PausedChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9459 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9460 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9461 #endif |
0 | 9462 return retval; |
9463 } | |
9464 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9465 ALint ALmixer_IsPausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9466 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9467 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9468 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9469 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9470 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9471 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9472 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9473 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9474 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9475 retval = Internal_PausedSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9476 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9477 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9478 #endif |
0 | 9479 return retval; |
9480 } | |
9481 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9482 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9483 ALuint ALmixer_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9484 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9485 ALuint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9486 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9487 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9488 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9489 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9490 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9491 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9492 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9493 retval = Internal_CountAllFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9494 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9495 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9496 #endif |
0 | 9497 return retval; |
9498 } | |
9499 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9500 ALuint ALmixer_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9501 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9502 ALuint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9503 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9504 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9505 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9506 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9507 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9508 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9509 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9510 retval = Internal_CountUnreservedFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9511 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9512 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9513 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9514 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9515 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9516 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9517 ALuint ALmixer_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9518 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9519 ALuint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9520 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9521 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9522 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9523 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9524 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9525 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9526 #endif |
0 | 9527 retval = Internal_CountAllUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9528 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9529 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9530 #endif |
0 | 9531 return retval; |
9532 } | |
9533 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9534 ALuint ALmixer_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9535 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9536 ALuint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9537 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9538 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9539 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9540 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9541 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9542 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9543 #endif |
0 | 9544 retval = Internal_CountUnreservedUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9545 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9546 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9547 #endif |
0 | 9548 return retval; |
9549 } | |
9550 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9551 ALboolean ALmixer_IsPredecoded(ALmixer_Data* data) |
1 | 9552 { |
9553 if(NULL == data) | |
9554 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9555 return AL_FALSE; |
1 | 9556 } |
9557 return data->decoded_all; | |
9558 } | |
9559 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9560 ALboolean ALmixer_CompiledWithThreadBackend() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9561 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9562 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9563 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9564 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9565 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9566 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9567 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9568 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9569 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9570 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9571 |