Mercurial > almixer_isolated
annotate ALmixer.c @ 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.
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Mon, 28 Mar 2011 15:16:26 -0700 |
parents | 9cf93a099f75 |
children | 1c23805d5ce9 |
rev | line source |
---|---|
0 | 1 |
2 /* Here's an OpenAL implementation modeled after | |
3 * the SDL_SoundMixer which was built ontop of SDL_Mixer | |
4 * and SDL_Sound. | |
5 * Eric Wing | |
6 */ | |
7 | |
3
a929285e1db0
Added CMake build system.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
2
diff
changeset
|
8 #include "ALmixer.h" |
0 | 9 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
10 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
11 #include "ALmixer_RWops.h" |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
12 #include "SoundDecoder.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
13 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
14 #include "SDL_sound.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
15 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
16 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
17 #include "al.h" /* OpenAL */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
18 #include "alc.h" /* For creating OpenAL contexts */ |
0 | 19 |
1 | 20 #ifdef __APPLE__ |
21 /* For performance things like ALC_CONVERT_DATA_UPON_LOADING */ | |
22 /* Note: ALC_CONVERT_DATA_UPON_LOADING used to be in the alc.h header. | |
23 * But in the Tiger OpenAL 1.1 release (10.4.7 and Xcode 2.4), the | |
24 * define was moved to a new header file and renamed to | |
25 * ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING. | |
26 */ | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
27 #include <TargetConditionals.h> |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
28 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
29 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
30 #include <AudioToolbox/AudioToolbox.h> |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
31 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
32 #include <OpenAL/MacOSX_OALExtensions.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
33 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
34 */ |
1 | 35 #endif |
36 | |
0 | 37 /* For malloc, bsearch, qsort */ |
38 #include <stdlib.h> | |
39 | |
40 /* For memcpy */ | |
41 #include <string.h> | |
42 | |
43 #if 0 | |
44 /* for toupper */ | |
45 #include <ctype.h> | |
46 /* for strrchr */ | |
47 #include <string.h> | |
48 #endif | |
49 | |
50 /* Currently used in the output debug functions */ | |
51 #include <stdio.h> | |
52 | |
53 /* My own CircularQueue implementation needed | |
54 * to work around the Nvidia problem of the | |
55 * lack of a buffer query. | |
56 */ | |
57 #include "CircularQueue.h" | |
58 | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
59 /* SDL_sound keeps a private linked list of sounds which get auto-deleted |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
60 * on Sound_Quit. This might actually create some leaks for me in certain |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
61 * usage patterns. To be safe, I should do the same. |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
62 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
63 #include "LinkedList.h" |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
64 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
65 #ifdef ENABLE_ALMIXER_THREADS |
0 | 66 /* Needed for the Mutex locks (and threads if enabled) */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
67 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
68 #include "SimpleMutex.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
69 #include "SimpleThread.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
70 typedef struct SimpleMutex SDL_mutex; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
71 typedef struct SimpleThread SDL_Thread; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
72 #define SDL_CreateMutex SimpleMutex_CreateMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
73 #define SDL_DestroyMutex SimpleMutex_DestroyMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
74 #define SDL_LockMutex SimpleMutex_LockMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
75 #define SDL_UnlockMutex SimpleMutex_UnlockMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
76 #define SDL_CreateThread SimpleThread_CreateThread |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
77 #define SDL_WaitThread SimpleThread_WaitThread |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
78 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
79 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
80 #include "SDL_thread.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
81 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
82 #endif |
0 | 83 |
84 /* Because of the API differences between the Loki | |
85 * and Creative distributions, we need to know which | |
86 * version to use. The LOKI distribution currently | |
87 * has AL_BYTE_LOKI defined in altypes.h which | |
88 * I will use as a flag to identify the distributions. | |
89 * If this is ever removed, I might revert back to the | |
90 * if defined(_WIN32) or defined(__APPLE__) test to | |
91 * identify the Creative dist. | |
92 * I'm not sure if or how the Nvidia distribution differs | |
93 * from the Creative distribution. So for | |
94 * now, the Nvidia distribution gets lumped with the | |
95 * Creative dist and I hope nothing will break. | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
96 * My alGetString may be the most vulnerable. |
0 | 97 */ |
98 #ifdef AL_BYTE_LOKI | |
99 #define USING_LOKI_AL_DIST | |
100 /* This is a short term fix to get around the | |
101 * queuing problem with non-power of two buffer sizes. | |
102 * Hopefully the maintainers will fix this before | |
103 * we're ready to ship. | |
104 */ | |
105 #define ENABLE_LOKI_QUEUE_FIX_HACK | |
106 | |
107 /* The AL_GAIN in the Loki dist doesn't seem to do | |
108 * what I want/expect it to do. I want to use it for | |
109 * Fading, but it seems to work like an off/on switch. | |
110 * 0 = off, >0 = on. | |
111 * The AL_GAIN_LINEAR_LOKI switch seems to do what | |
112 * I want, so I'll redefine it here so the code is consistent | |
113 */ | |
114 /* Update: I've changed the source volume implementations | |
115 * to use AL_MAX_GAIN, so I don't think I need this block | |
116 * of code anymore. The listener uses AL_GAIN, but I | |
117 * hope they got this one right since there isn't a AL_MAX_GAIN | |
118 * for the listener. | |
119 */ | |
120 /* | |
121 #undef AL_GAIN | |
122 #include "alexttypes.h" | |
123 #define AL_GAIN AL_GAIN_LINEAR_LOKI | |
124 */ | |
125 #else | |
126 /* Might need to run other tests to figure out the DIST */ | |
127 /* I've been told that Nvidia doesn't define constants | |
128 * in the headers like Creative. Instead of | |
129 * #define AL_REFERENCE_DISTANCE 0x1020, | |
130 * Nvidia prefers you query OpenAL for a value. | |
131 * int AL_REFERENCE_DISTANCE = alGetEnumValue(ALubyte*)"AL_REFERNECE_DISTANCE"); | |
132 * So I'm assuming this means the Nvidia lacks this value. | |
133 * If this is the case, | |
134 * I guess we can use it to identify the Nvidia dist | |
135 */ | |
136 #ifdef AL_REFERENCE_DISTANCE | |
137 #define USING_CREATIVE_AL_DIST | |
138 #else | |
139 #define USING_NVIDIA_AL_DIST | |
140 #endif | |
141 #endif | |
142 | |
143 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
144 /* Need memset to zero out data */ | |
145 #include <string.h> | |
146 #endif | |
147 | |
148 | |
149 /* Seek issues for predecoded samples: | |
150 * The problem is that OpenAL makes us copy an | |
151 * entire buffer if we want to use it. This | |
152 * means we potentially have two copies of the | |
153 * same data. For predecoded data, this can be a | |
154 * large amount of memory. However, for seek | |
155 * support, I need to be able to get access to | |
156 * the original data so I can set byte positions. | |
157 * The following flags let you disable seek support | |
158 * if you don't want the memory hit, keep everything, | |
159 * or let you try to minimize the memory wasted by | |
160 * fetching it from the OpenAL buffer if needed | |
161 * and making a copy of it. | |
162 * Update: I don't think I need this flag anymore. I've made the | |
163 * effects of this user customizable by the access_data flag on load. | |
164 * If set to true, then seek and data callbacks work, with the | |
165 * cost of more memory and possibly CPU for copying the data through | |
166 * the callbacks. If false, then the extra memory is freed, but | |
167 * you don't get the features. | |
168 */ | |
169 /* | |
170 #define DISABLE_PREDECODED_SEEK | |
171 */ | |
172 /* Problem: Even though alGetBufferi(., AL_DATA, .) | |
173 * is in the Creative Programmer's reference, | |
174 * it actually isn't in the dist. (Invalid enum | |
175 * in Creative, can't compile in Loki.) | |
176 * So we have to keep it disabled | |
177 */ | |
178 #define DISABLE_SEEK_MEMORY_OPTIMIZATION | |
179 | |
180 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION | |
181 /* Needed for memcpy */ | |
182 #include <string.h> | |
183 #endif | |
184 | |
185 /* Old way of doing things: | |
186 #if defined(_WIN32) || defined(__APPLE__) | |
187 #define USING_CREATIVE_AL_DIST | |
188 #else | |
189 #define USING_LOKI_AL_DIST | |
190 #endif | |
191 */ | |
192 | |
193 /************ REMOVE ME (Don't need anymore) ********/ | |
194 #if 0 | |
195 /* Let's get fancy and see if triple buffering | |
196 * does anything good for us | |
197 * Must be 2 or more or things will probably break | |
198 */ | |
199 #define NUMBER_OF_QUEUE_BUFFERS 5 | |
200 /* This is the number of buffers that are queued up | |
201 * when play first starts up. This should be at least 1 | |
202 * and no more than NUMBER_OF_QUEUE_BUFFERS | |
203 */ | |
204 #define NUMBER_OF_START_UP_BUFFERS 2 | |
205 #endif | |
206 /************ END REMOVE ME (Don't need anymore) ********/ | |
207 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
208 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
209 #include "tErrorLib.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
210 static TErrorPool* s_ALmixerErrorPool = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
211 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
212 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
213 static ALboolean ALmixer_Initialized = 0; |
0 | 214 /* This should be set correctly by Init */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
215 static ALuint ALmixer_Frequency_global = ALMIXER_DEFAULT_FREQUENCY; |
0 | 216 |
217 /* Will be initialized in Init */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
218 static ALint Number_of_Channels_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
219 static ALint Number_of_Reserve_Channels_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
220 static ALuint Is_Playing_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
221 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
222 #ifdef ENABLE_ALMIXER_THREADS |
0 | 223 /* This is for a simple lock system. It is not meant to be good, |
224 * but just sufficient to minimize/avoid threading issues | |
225 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
226 static SDL_mutex* s_simpleLock; |
0 | 227 static SDL_Thread* Stream_Thread_global = NULL; |
26
884cce2515eb
Put LowerThreadPriority in ENABLE_ALMIXER_THREADS_BLOCK
Eric Wing <ewing . public |-at-| gmail . com>
parents:
25
diff
changeset
|
228 #endif /* ENABLE_ALMIXER_THREADS */ |
0 | 229 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
230 static LinkedList* s_listOfALmixerData = NULL; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
231 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
232 /* Special stuff for iOS interruption handling */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
233 static ALCcontext* s_interruptionContext = NULL; |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
234 |
0 | 235 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
236 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
237 static ALvoid Internal_alcMacOSXMixerOutputRate(const ALdouble sample_rate) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
238 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
239 static void (*alcMacOSXMixerOutputRateProcPtr)(const ALdouble) = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
240 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
241 if(NULL == alcMacOSXMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
242 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
243 alcMacOSXMixerOutputRateProcPtr = alGetProcAddress((const ALCchar*) "alcMacOSXMixerOutputRate"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
244 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
245 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
246 if(NULL != alcMacOSXMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
247 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
248 alcMacOSXMixerOutputRateProcPtr(sample_rate); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
249 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
250 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
251 return; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
252 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
253 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
254 ALdouble Internal_alcMacOSXGetMixerOutputRate() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
255 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
256 static ALdouble (*alcMacOSXGetMixerOutputRateProcPtr)(void) = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
257 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
258 if(NULL == alcMacOSXGetMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
259 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
260 alcMacOSXGetMixerOutputRateProcPtr = alGetProcAddress((const ALCchar*) "alcMacOSXGetMixerOutputRate"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
261 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
262 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
263 if(NULL != alcMacOSXGetMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
264 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
265 return alcMacOSXGetMixerOutputRateProcPtr(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
266 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
267 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
268 return 0.0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
269 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
270 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
271 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
272 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
273 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
274 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
275 #include <QuartzCore/QuartzCore.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
276 #include <unistd.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
277 static CFTimeInterval s_ticksBaseTime = 0.0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
278 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
279 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
280 #define WIN32_LEAN_AND_MEAN |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
281 #include <windows.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
282 #include <winbase.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
283 LARGE_INTEGER s_hiResTicksPerSecond; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
284 double s_hiResSecondsPerTick; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
285 LARGE_INTEGER s_ticksBaseTime; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
286 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
287 #include <unistd.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
288 #include <time.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
289 static struct timespec s_ticksBaseTime; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
290 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
291 static void ALmixer_InitTime() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
292 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
293 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
294 s_ticksBaseTime = CACurrentMediaTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
295 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
296 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
297 LARGE_INTEGER hi_res_ticks_per_second; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
298 if(TRUE == QueryPerformanceFrequency(&hi_res_ticks_per_second)) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
299 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
300 QueryPerformanceCounter(&s_ticksBaseTime); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
301 s_hiResSecondsPerTick = 1.0 / hi_res_ticks_per_second; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
302 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
303 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
304 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
305 ALMixer_SetError("Windows error: High resolution clock failed."); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
306 fprintf(stderr, "Windows error: High resolution clock failed. Audio will not work correctly.\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
307 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
308 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
309 /* clock_gettime is POSIX.1-2001 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
310 clock_gettime(CLOCK_MONOTONIC, &s_ticksBaseTime); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
311 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
312 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
313 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
314 static ALuint ALmixer_GetTicks() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
315 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
316 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
317 return (ALuint)((CACurrentMediaTime()-s_ticksBaseTime)*1000.0); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
318 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
319 LARGE_INTEGER current_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
320 QueryPerformanceCounter(¤t_time); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
321 return (ALuint)((current_time.QuadPart - s_ticksBaseTime.QuadPart) * 1000 * s_hiResSecondsPerTick); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
322 #else /* assuming POSIX */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
323 /* clock_gettime is POSIX.1-2001 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
324 struct timespec current_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
325 clock_gettime(CLOCK_MONOTONIC, ¤t_time); |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
326 return (ALuint)((current_time.tv_sec - s_ticksBaseTime.tv_sec)*1000.0 + (current_time.tv_nsec - s_ticksBaseTime.tv_nsec) / 1000000); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
327 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
328 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
329 static void ALmixer_Delay(ALuint milliseconds_delay) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
330 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
331 #if defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
332 Sleep(milliseconds_delay); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
333 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
334 usleep(milliseconds_delay); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
335 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
336 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
337 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
338 #include "SDL.h" /* For SDL_GetTicks(), SDL_Delay */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
339 #define ALmixer_GetTicks SDL_GetTicks |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
340 #define ALmixer_Delay SDL_Delay |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
341 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
342 |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
343 /* On iOS, usleep() of small numbers (say less than 100, very pronounced from 0-50) |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
344 * seems to be sucking up quite a bit of CPU time and causing performance problems. |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
345 * Instead of increasing the sleep time, I started changing the thread priority. |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
346 * This seemed to help the problem. |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
347 * Experimentally, the default priority seems to be 31. According to the docs, |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
348 * valid ranges are from 0 to 31. 6 was still giving me some hiccups so setting to |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
349 * 0 (PTHREAD_MIN_PRIORITY) seems to be the best value so far. |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
350 * Mac also reports 31 as the default. However, I have not noticed the same |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
351 * performance problems and cannot get audio to show up as a significant percentage |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
352 * of the CPU time in Shark/Instruments. |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
353 */ |
26
884cce2515eb
Put LowerThreadPriority in ENABLE_ALMIXER_THREADS_BLOCK
Eric Wing <ewing . public |-at-| gmail . com>
parents:
25
diff
changeset
|
354 #ifdef ENABLE_ALMIXER_THREADS |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
355 #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
|
356 #include <pthread.h> |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
357 #endif |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
358 static void Internal_LowerThreadPriority(SDL_Thread* simple_thread) |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
359 { |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
360 /* Might open to other platforms as needed */ |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
361 #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
|
362 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
363 SimpleThread_SetThreadPriority(Stream_Thread_global, 0); |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
364 #else |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
365 struct sched_param schedule_param; |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
366 int sched_policy; |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
367 int ret_val; |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
368 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
|
369 /* 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
|
370 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
|
371 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
|
372 #endif |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
373 #else |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
374 /* No-Op */ |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
375 #endif |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
376 } |
26
884cce2515eb
Put LowerThreadPriority in ENABLE_ALMIXER_THREADS_BLOCK
Eric Wing <ewing . public |-at-| gmail . com>
parents:
25
diff
changeset
|
377 #endif /* ENABLE_ALMIXER_THREADS */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
378 |
0 | 379 /* If ENABLE_PARANOID_SIGNEDNESS_CHECK is used, |
380 * these values will be reset on Init() | |
381 * Consider these values Read-Only. | |
382 */ | |
383 | |
384 #define ALMIXER_SIGNED_VALUE 127 | |
385 #define ALMIXER_UNSIGNED_VALUE 255 | |
386 | |
387 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
388 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
|
389 static ALushort SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; |
0 | 390 #else |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
391 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
|
392 static const ALushort SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; |
0 | 393 #endif |
394 | |
1 | 395 |
396 /* This can be private instead of being in the header now that I moved | |
397 * ALmixer_Data inside here. | |
398 */ | |
399 typedef struct ALmixer_Buffer_Map ALmixer_Buffer_Map; | |
400 | |
401 | |
402 struct ALmixer_Data | |
403 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
404 ALboolean decoded_all; /* dictates different behaviors */ |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
405 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
|
406 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
407 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
|
408 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
|
409 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
410 ALuint total_bytes; /* For predecoded */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
411 ALuint loaded_bytes; /* For predecoded (for seek) */ |
1 | 412 |
413 Sound_Sample* sample; /* SDL_Sound provides the data */ | |
414 ALuint* buffer; /* array of OpenAL buffers (at least 1 for predecoded) */ | |
415 | |
416 /* Needed for streamed buffers */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
417 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
|
418 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
|
419 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
|
420 ALuint num_target_buffers_per_pass; /* number of buffers to try to queue in an update pass */ |
1 | 421 |
422 /* This stuff is for streamed buffers that require data access */ | |
423 ALmixer_Buffer_Map* buffer_map_list; /* translate ALbuffer to index | |
424 and holds pointer to copy of data for | |
425 data access */ | |
426 ALuint current_buffer; /* The current playing buffer */ | |
427 | |
428 /* Nvidia distribution refuses to recognize a simple buffer query command | |
429 * unlike all other distributions. It's forcing me to redo the code | |
430 * to accomodate this Nvidia flaw by making me maintain a "best guess" | |
431 * copy of what I think the buffer queue state looks like. | |
432 * A circular queue would a helpful data structure for this task, | |
433 * but I wanted to avoid making an additional header requirement, | |
434 * so I'm making it a void* | |
435 */ | |
436 void* circular_buffer_queue; | |
437 | |
438 | |
439 }; | |
440 | |
0 | 441 static struct ALmixer_Channel |
442 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
443 ALboolean channel_in_use; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
444 ALboolean callback_update; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
445 ALboolean needs_stream; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
446 ALboolean halted; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
447 ALboolean paused; |
0 | 448 ALuint alsource; |
449 ALmixer_Data* almixer_data; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
450 ALint loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
451 ALint expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
452 ALuint start_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
453 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
454 ALboolean fade_enabled; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
455 ALuint fade_expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
456 ALuint fade_start_time; |
0 | 457 ALfloat fade_inv_time; |
458 ALfloat fade_start_volume; | |
459 ALfloat fade_end_volume; | |
460 ALfloat max_volume; | |
461 ALfloat min_volume; | |
462 | |
463 /* Do we need other flags? | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
464 ALbyte *samples; |
0 | 465 int volume; |
466 int looping; | |
467 int tag; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
468 ALuint expire; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
469 ALuint start_time; |
0 | 470 Mix_Fading fading; |
471 int fade_volume; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
472 ALuint fade_length; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
473 ALuint ticks_fade; |
0 | 474 effect_info *effects; |
475 */ | |
476 } *ALmixer_Channel_List = NULL; | |
477 | |
1 | 478 struct ALmixer_Buffer_Map |
479 { | |
480 ALuint albuffer; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
481 ALint index; /* might not need */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
482 ALbyte* data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
483 ALuint num_bytes; |
1 | 484 }; |
485 | |
0 | 486 /* This will be used to find a channel if the user supplies a source */ |
487 typedef struct Source_Map | |
488 { | |
489 ALuint source; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
490 ALint channel; |
0 | 491 } Source_Map; |
492 /* Keep an array of all sources with their associated channel */ | |
493 static Source_Map* Source_Map_List; | |
494 | |
495 static int Compare_Source_Map(const void* a, const void* b) | |
496 { | |
497 return ( ((Source_Map*)a)->source - ((Source_Map*)b)->source ); | |
498 } | |
499 | |
500 /* Sort by channel instead of source */ | |
501 static int Compare_Source_Map_by_channel(const void* a, const void* b) | |
502 { | |
503 return ( ((Source_Map*)a)->channel - ((Source_Map*)b)->channel ); | |
504 } | |
505 | |
506 /* Compare by albuffer */ | |
507 static int Compare_Buffer_Map(const void* a, const void* b) | |
508 { | |
1 | 509 return ( ((ALmixer_Buffer_Map*)a)->albuffer - ((ALmixer_Buffer_Map*)b)->albuffer ); |
0 | 510 } |
511 | |
512 /* This is for the user defined callback via | |
513 * ALmixer_ChannelFinished() | |
514 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
515 static void (*Channel_Done_Callback)(ALint which_channel, ALuint al_source, ALmixer_Data* almixer_data, ALboolean finished_naturally, void* user_data) = NULL; |
0 | 516 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
|
517 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 | 518 static void* Channel_Data_Callback_Userdata = NULL; |
0 | 519 |
520 | |
521 static void PrintQueueStatus(ALuint source) | |
522 { | |
523 ALint buffers_queued = 0; | |
524 ALint buffers_processed = 0; | |
525 ALenum error; | |
526 | |
527 /* Get the number of buffers still queued */ | |
528 alGetSourcei( | |
529 source, | |
530 AL_BUFFERS_QUEUED, | |
531 &buffers_queued | |
532 ); | |
533 | |
534 if((error = alGetError()) != AL_NO_ERROR) | |
535 { | |
536 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
|
537 alGetString(error)); |
0 | 538 } |
539 /* Get the number of buffers processed | |
540 * so we know if we need to refill | |
541 */ | |
542 alGetSourcei( | |
543 source, | |
544 AL_BUFFERS_PROCESSED, | |
545 &buffers_processed | |
546 ); | |
547 if((error = alGetError()) != AL_NO_ERROR) | |
548 { | |
549 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
|
550 alGetString(error)); |
0 | 551 } |
552 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
553 /* |
0 | 554 fprintf(stderr, "For source: %d, buffers_queued=%d, buffers_processed=%d\n", |
555 source, | |
556 buffers_queued, | |
557 buffers_processed); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
558 */ |
0 | 559 } |
560 | |
561 | |
562 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
563 static void Init_Channel(ALint channel) |
0 | 564 { |
565 ALmixer_Channel_List[channel].channel_in_use = 0; | |
566 ALmixer_Channel_List[channel].callback_update = 0; | |
567 ALmixer_Channel_List[channel].needs_stream = 0; | |
568 ALmixer_Channel_List[channel].paused = 0; | |
569 ALmixer_Channel_List[channel].halted = 0; | |
570 ALmixer_Channel_List[channel].loops = 0; | |
571 | |
572 ALmixer_Channel_List[channel].expire_ticks = 0; | |
573 ALmixer_Channel_List[channel].start_time = 0; | |
574 | |
575 ALmixer_Channel_List[channel].fade_enabled = 0; | |
576 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
577 ALmixer_Channel_List[channel].fade_start_time = 0; | |
578 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
579 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
580 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
581 ALmixer_Channel_List[channel].max_volume = 1.0f; | |
582 ALmixer_Channel_List[channel].min_volume = 0.0f; | |
583 | |
584 ALmixer_Channel_List[channel].almixer_data = NULL; | |
585 } | |
586 /* Quick helper function to clean up a channel | |
587 * after it's done playing */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
588 static void Clean_Channel(ALint channel) |
0 | 589 { |
590 ALenum error; | |
591 ALmixer_Channel_List[channel].channel_in_use = 0; | |
592 ALmixer_Channel_List[channel].callback_update = 0; | |
593 ALmixer_Channel_List[channel].needs_stream = 0; | |
594 ALmixer_Channel_List[channel].paused = 0; | |
595 ALmixer_Channel_List[channel].halted = 0; | |
596 ALmixer_Channel_List[channel].loops = 0; | |
597 | |
598 | |
599 ALmixer_Channel_List[channel].expire_ticks = 0; | |
600 ALmixer_Channel_List[channel].start_time = 0; | |
601 | |
602 ALmixer_Channel_List[channel].fade_enabled = 0; | |
603 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
604 ALmixer_Channel_List[channel].fade_start_time = 0; | |
605 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
606 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
607 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
608 | |
609 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MAX_GAIN, | |
610 ALmixer_Channel_List[channel].max_volume); | |
611 | |
612 if((error = alGetError()) != AL_NO_ERROR) | |
613 { | |
614 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
|
615 alGetString(error)); |
0 | 616 } |
617 | |
618 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MIN_GAIN, | |
619 ALmixer_Channel_List[channel].min_volume); | |
620 if((error = alGetError()) != AL_NO_ERROR) | |
621 { | |
622 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
|
623 alGetString(error)); |
0 | 624 } |
625 | |
626 if(ALmixer_Channel_List[channel].almixer_data != NULL) | |
627 { | |
628 if(ALmixer_Channel_List[channel].almixer_data->in_use > 0) | |
629 { | |
630 ALmixer_Channel_List[channel].almixer_data->in_use--; | |
631 } | |
632 } | |
633 /* Needed to determine if rewind is needed, can't reset */ | |
634 /* | |
635 ALmixer_Channel_List[channel].almixer_data->eof = 0; | |
636 */ | |
637 | |
638 ALmixer_Channel_List[channel].almixer_data = NULL; | |
639 } | |
640 | |
641 /* What shoud this return? | |
642 * 127 for signed, 255 for unsigned | |
643 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
644 static ALubyte GetSignednessValue(ALushort format) |
0 | 645 { |
646 switch(format) | |
647 { | |
648 case AUDIO_U8: | |
649 case AUDIO_U16LSB: | |
650 case AUDIO_U16MSB: | |
651 return ALMIXER_UNSIGNED_VALUE; | |
652 break; | |
653 case AUDIO_S8: | |
654 case AUDIO_S16LSB: | |
655 case AUDIO_S16MSB: | |
656 return ALMIXER_SIGNED_VALUE; | |
657 break; | |
658 default: | |
659 return 0; | |
660 } | |
661 return 0; | |
662 } | |
663 | |
664 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
665 static ALubyte GetBitDepth(ALushort format) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
666 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
667 ALubyte bit_depth = 16; |
0 | 668 |
669 switch(format) | |
670 { | |
671 case AUDIO_U8: | |
672 case AUDIO_S8: | |
673 bit_depth = 8; | |
674 break; | |
675 | |
676 case AUDIO_U16LSB: | |
677 /* | |
678 case AUDIO_U16: | |
679 */ | |
680 case AUDIO_S16LSB: | |
681 /* | |
682 case AUDIO_S16: | |
683 */ | |
684 case AUDIO_U16MSB: | |
685 case AUDIO_S16MSB: | |
686 /* | |
687 case AUDIO_U16SYS: | |
688 case AUDIO_S16SYS: | |
689 */ | |
690 bit_depth = 16; | |
691 break; | |
692 default: | |
693 bit_depth = 0; | |
694 } | |
695 return bit_depth; | |
696 } | |
697 | |
698 /* Need to translate between SDL/SDL_Sound audiospec | |
699 * and OpenAL conventions */ | |
700 static ALenum TranslateFormat(Sound_AudioInfo* info) | |
701 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
702 ALubyte bit_depth; |
0 | 703 |
704 bit_depth = GetBitDepth(info->format); | |
705 if(0 == bit_depth) | |
706 { | |
707 fprintf(stderr, "Warning: Unknown bit depth. Setting to 16\n"); | |
708 bit_depth = 16; | |
709 } | |
710 | |
711 if(2 == info->channels) | |
712 { | |
713 if(16 == bit_depth) | |
714 { | |
715 return AL_FORMAT_STEREO16; | |
716 } | |
717 else | |
718 { | |
719 return AL_FORMAT_STEREO8; | |
720 } | |
721 } | |
722 else | |
723 { | |
724 if(16 == bit_depth) | |
725 { | |
726 return AL_FORMAT_MONO16; | |
727 } | |
728 else | |
729 { | |
730 return AL_FORMAT_MONO8; | |
731 } | |
732 } | |
733 /* Make compiler happy. Shouldn't get here */ | |
734 return AL_FORMAT_STEREO16; | |
735 } | |
736 | |
1 | 737 |
738 /* This will compute the total playing time | |
739 * based upon the number of bytes and audio info. | |
740 * (In prinicple, it should compute the time for any given length) | |
741 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
742 static ALuint Compute_Total_Time_Decomposed(ALuint bytes_per_sample, ALuint frequency, ALubyte channels, size_t total_bytes) |
1 | 743 { |
744 double total_sec; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
745 ALuint total_msec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
746 ALuint bytes_per_sec; |
1 | 747 |
748 if(0 == total_bytes) | |
749 { | |
750 return 0; | |
751 } | |
752 /* To compute Bytes per second, do | |
753 * samples_per_sec * bytes_per_sample * number_of_channels | |
754 */ | |
755 bytes_per_sec = frequency * bytes_per_sample * channels; | |
756 | |
757 /* Now to get total time (sec), do | |
758 * total_bytes / bytes_per_sec | |
759 */ | |
760 total_sec = total_bytes / (double)bytes_per_sec; | |
761 | |
762 /* Now convert seconds to milliseconds | |
763 * Add .5 to the float to do rounding before the final cast | |
764 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
765 total_msec = (ALuint) ( (total_sec * 1000) + 0.5 ); |
1 | 766 /* |
767 fprintf(stderr, "freq=%d, bytes_per_sample=%d, channels=%d, total_msec=%d\n", frequency, bytes_per_sample, channels, total_msec); | |
768 */ | |
769 return total_msec; | |
770 } | |
771 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
772 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
|
773 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
774 ALuint bytes_per_sample; |
1 | 775 |
776 if(0 == total_bytes) | |
777 { | |
778 return 0; | |
779 } | |
780 /* 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
|
781 * 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
|
782 * 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
|
783 * 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
|
784 * 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
|
785 * 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
|
786 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
787 bytes_per_sample = (ALuint) ((info->format & 0xFF) / 8); |
1 | 788 |
789 return Compute_Total_Time_Decomposed(bytes_per_sample, info->rate, info->channels, total_bytes); | |
790 } /* End Compute_Total_Time */ | |
791 | |
792 | |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
793 #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
|
794 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
|
795 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
796 double total_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
797 ALuint bytes_per_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
798 size_t total_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
799 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
800 if(0 >= total_msec) |
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 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
803 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
804 /* To compute Bytes per second, do |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
805 * 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
|
806 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
807 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
|
808 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
809 /* convert milliseconds to seconds */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
810 total_sec = total_msec / 1000.0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
811 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
812 /* Now to get total bytes */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
813 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
|
814 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
815 /* 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
|
816 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
817 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
818 return total_bytes; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
821 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
|
822 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
823 ALuint bytes_per_sample; |
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 if(0 >= total_msec) |
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 return 0; |
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 /* 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
|
830 * 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
|
831 * 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
|
832 * 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
|
833 * 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
|
834 * 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
|
835 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
836 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
|
837 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
838 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
|
839 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
840 |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
841 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
842 /* 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
|
843 * 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
|
844 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
845 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
|
846 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
847 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
848 ALuint bytes_per_frame; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
849 size_t evenly_divisible_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
850 size_t remainder_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
851 size_t return_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
852 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
853 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
|
854 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
855 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
|
856 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
857 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
|
858 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
859 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
|
860 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
|
861 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
862 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
|
863 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
864 /* 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
|
865 * 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
|
866 * 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
|
867 * 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
|
868 * 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
|
869 * 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
|
870 * 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
|
871 * 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
|
872 * 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
|
873 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
874 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
875 return_bytes += 64; |
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 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
878 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
|
879 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
880 return return_bytes; |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
881 } |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
882 #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
|
883 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
884 |
1 | 885 |
0 | 886 /**************** REMOVED ****************************/ |
887 /* This was removed because I originally thought | |
888 * OpenAL could return a pointer to the buffer data, | |
889 * but I was wrong. If something like that is ever | |
890 * implemented, then this might become useful. | |
891 */ | |
892 #if 0 | |
893 /* Reconstruct_Sound_Sample and Set_AudioInfo only | |
894 * are needed if the Seek memory optimization is | |
895 * used. Also, the Loki dist doesn't seem to support | |
896 * AL_DATA which I need for it. | |
897 */ | |
898 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION | |
899 | |
900 static void Set_AudioInfo(Sound_AudioInfo* info, ALint frequency, ALint bits, ALint channels) | |
901 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
902 info->rate = (ALuint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
903 info->channels = (ALubyte)channels; |
0 | 904 |
905 /* Not sure if it should be signed or unsigned. Hopefully | |
906 * that detail won't be needed. | |
907 */ | |
908 if(8 == bits) | |
909 { | |
910 info->format = AUDIO_U8; | |
911 } | |
912 else | |
913 { | |
914 info->format = AUDIO_U16SYS; | |
915 } | |
916 fprintf(stderr, "Audio info: freq=%d, chan=%d, format=%d\n", | |
917 info->rate, info->channels, info->format); | |
918 | |
919 } | |
920 | |
921 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
922 static ALint Reconstruct_Sound_Sample(ALmixer_Data* data) |
0 | 923 { |
924 ALenum error; | |
925 ALint* data_from_albuffer; | |
926 ALint freq; | |
927 ALint bits; | |
928 ALint channels; | |
929 ALint size; | |
930 | |
931 /* Create memory all initiallized to 0. */ | |
932 data->sample = (Sound_Sample*)calloc(1, sizeof(Sound_Sample)); | |
933 if(NULL == data->sample) | |
934 { | |
935 ALmixer_SetError("Out of memory for Sound_Sample"); | |
936 return -1; | |
937 } | |
938 | |
939 /* Clear errors */ | |
940 alGetError(); | |
941 | |
942 alGetBufferi(data->buffer[0], AL_FREQUENCY, &freq); | |
943 if((error = alGetError()) != AL_NO_ERROR) | |
944 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
945 ALmixer_SetError("alGetBufferi(AL_FREQUENCY): %s", alGetString(error) ); |
0 | 946 free(data->sample); |
947 data->sample = NULL; | |
948 return -1; | |
949 } | |
950 | |
951 alGetBufferi(data->buffer[0], AL_BITS, &bits); | |
952 if((error = alGetError()) != AL_NO_ERROR) | |
953 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
954 ALmixer_SetError("alGetBufferi(AL_BITS): %s", alGetString(error) ); |
0 | 955 free(data->sample); |
956 data->sample = NULL; | |
957 return -1; | |
958 } | |
959 | |
960 alGetBufferi(data->buffer[0], AL_CHANNELS, &channels); | |
961 if((error = alGetError()) != AL_NO_ERROR) | |
962 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
963 ALmixer_SetError("alGetBufferi(AL_CHANNELS): %s", alGetString(error) ); |
0 | 964 free(data->sample); |
965 data->sample = NULL; | |
966 return -1; | |
967 } | |
968 | |
969 alGetBufferi(data->buffer[0], AL_SIZE, &size); | |
970 if((error = alGetError()) != AL_NO_ERROR) | |
971 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
972 ALmixer_SetError("alGetBufferi(AL_SIZE): %s", alGetString(error) ); |
0 | 973 free(data->sample); |
974 data->sample = NULL; | |
975 return -1; | |
976 } | |
977 | |
978 alGetBufferi(data->buffer[0], AL_DATA, data_from_albuffer); | |
979 if((error = alGetError()) != AL_NO_ERROR) | |
980 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
981 ALmixer_SetError("alGetBufferi(AL_DATA): %s", alGetString(error) ); |
0 | 982 free(data->sample); |
983 data->sample = NULL; | |
984 return -1; | |
985 } | |
986 | |
987 if(size <= 0) | |
988 { | |
989 ALmixer_SetError("No data in al buffer"); | |
990 free(data->sample); | |
991 data->sample = NULL; | |
992 return -1; | |
993 } | |
994 | |
995 /* Now that we have all the attributes, we need to | |
996 * allocate memory for the buffer and reconstruct | |
997 * the AudioInfo attributes. | |
998 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
999 data->sample->buffer = malloc(size*sizeof(ALbyte)); |
0 | 1000 if(NULL == data->sample->buffer) |
1001 { | |
1002 ALmixer_SetError("Out of memory for sample->buffer"); | |
1003 free(data->sample); | |
1004 data->sample = NULL; | |
1005 return -1; | |
1006 } | |
1007 | |
1008 memcpy(data->sample->buffer, data_from_albuffer, size); | |
1009 data->sample->buffer_size = size; | |
1010 | |
1011 /* Fill up the Sound_AudioInfo structures */ | |
1012 Set_AudioInfo(&data->sample->desired, freq, bits, channels); | |
1013 Set_AudioInfo(&data->sample->actual, freq, bits, channels); | |
1014 | |
1015 return 0; | |
1016 } | |
1017 | |
1018 #endif /* End DISABLE_SEEK_MEMORY_OPTIMIZATION */ | |
1019 #endif | |
1020 /*************** END REMOVED *************************/ | |
1021 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1022 static void Invoke_Channel_Done_Callback(ALint which_channel, ALboolean did_finish_naturally) |
0 | 1023 { |
1024 if(NULL == Channel_Done_Callback) | |
1025 { | |
1026 return; | |
1027 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1028 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
|
1029 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1030 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1031 static ALint LookUpBuffer(ALuint buffer, ALmixer_Buffer_Map* buffer_map_list, ALuint num_items_in_list) |
0 | 1032 { |
1033 /* Only the first value is used for the key */ | |
1 | 1034 ALmixer_Buffer_Map key = { 0, 0, NULL, 0 }; |
1035 ALmixer_Buffer_Map* found_item = NULL; | |
0 | 1036 key.albuffer = buffer; |
1037 | |
1038 /* Use the ANSI C binary search feature (yea!) */ | |
1 | 1039 found_item = (ALmixer_Buffer_Map*)bsearch(&key, buffer_map_list, num_items_in_list, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 1040 if(NULL == found_item) |
1041 { | |
1042 ALmixer_SetError("Can't find buffer"); | |
1043 return -1; | |
1044 } | |
1045 return found_item->index; | |
1046 } | |
1047 | |
1048 | |
1049 /* FIXME: Need to pass back additional info to be useful. | |
1050 * Bit rate, stereo/mono (num chans), time in msec? | |
1051 * Precoded/streamed flag so user can plan for future data? | |
1052 */ | |
1 | 1053 /* |
1054 * channels: 1 for mono, 2 for stereo | |
1055 * | |
1056 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1057 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
|
1058 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1059 ALboolean is_unsigned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1060 ALubyte bits_per_sample = GetBitDepth(format); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1061 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1062 ALuint length_in_msec; |
1 | 1063 |
1064 if(GetSignednessValue(format) == ALMIXER_UNSIGNED_VALUE) | |
1065 { | |
1066 is_unsigned = 1; | |
1067 } | |
1068 else | |
1069 { | |
1070 is_unsigned = 0; | |
1071 } | |
1072 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1073 bytes_per_sample = (ALuint) (bits_per_sample / 8); |
1 | 1074 |
1075 length_in_msec = Compute_Total_Time_Decomposed(bytes_per_sample, frequency, channels, num_bytes); | |
1076 | |
0 | 1077 /* |
1078 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); | |
1079 */ | |
1080 if(NULL == Channel_Data_Callback) | |
1081 { | |
1082 return; | |
1083 } | |
1 | 1084 /* |
1085 * Channel_Data_Callback(which_channel, data, num_bytes, frequency, channels, GetBitDepth(format), format, decode_mode_is_predecoded); | |
1086 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1087 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
|
1088 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1089 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1090 static void Invoke_Predecoded_Channel_Data_Callback(ALint channel, ALmixer_Data* data) |
0 | 1091 { |
1092 if(NULL == data->sample) | |
1093 { | |
1094 return; | |
1095 } | |
1096 /* The buffer position is complicated because if the current data was seeked, | |
1097 * we must adjust the buffer to the seek position | |
1098 */ | |
1099 Invoke_Channel_Data_Callback(channel, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1100 (((ALbyte*) data->sample->buffer) + (data->total_bytes - data->loaded_bytes) ), |
0 | 1101 data->loaded_bytes, |
1102 data->sample->desired.rate, | |
1103 data->sample->desired.channels, | |
1104 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1105 AL_TRUE |
0 | 1106 ); |
1107 } | |
1108 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1109 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
|
1110 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1111 ALint index; |
0 | 1112 if(NULL == data->buffer_map_list) |
1113 { | |
1114 return; | |
1115 } | |
1116 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1117 /* This should catch the case where all buffers are unqueued | |
1118 * and the "current" buffer is id: 0 | |
1119 */ | |
1120 if(-1 == index) | |
1121 { | |
1122 return; | |
1123 } | |
1124 Invoke_Channel_Data_Callback(channel, | |
1125 data->buffer_map_list[index].data, | |
1126 data->buffer_map_list[index].num_bytes, | |
1127 data->sample->desired.rate, | |
1128 data->sample->desired.channels, | |
1129 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1130 AL_FALSE |
0 | 1131 ); |
1132 } | |
1133 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1134 /* Converts milliseconds to byte positions. |
0 | 1135 * This is needed for seeking on predecoded samples |
1136 */ | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1137 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
|
1138 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1139 ALuint bytes_per_sample; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1140 ALuint bytes_per_frame; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1141 float bytes_per_millisecond; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1142 float byte_position; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1143 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1144 if(audio_info == NULL) |
0 | 1145 { |
1146 fprintf(stderr, "Error, info is NULL\n"); | |
1147 } | |
1148 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1149 /* 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
|
1150 * 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
|
1151 * 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
|
1152 * 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
|
1153 * 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
|
1154 * Uint32 to unspecified size types like ALuint. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1155 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1156 bytes_per_sample = (ALuint) ((audio_info->format & 0xFF) / 8); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1157 bytes_per_frame = bytes_per_sample * audio_info->channels; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1158 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
|
1159 byte_position = ((float)(number_of_milliseconds)) * bytes_per_millisecond; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1160 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
|
1161 } |
0 | 1162 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1163 static ALint Set_Predecoded_Seek_Position(ALmixer_Data* data, ALuint byte_position) |
0 | 1164 { |
1165 ALenum error; | |
1166 /* clear error */ | |
1167 alGetError(); | |
1168 | |
1169 /* Is it greater than, or greater-than or equal to ?? */ | |
1170 if(byte_position > data->total_bytes) | |
1171 { | |
1172 /* 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
|
1173 /* |
0 | 1174 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
|
1175 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1176 |
0 | 1177 /* In case the below thing doesn't work, |
1178 * just rewind the whole thing. | |
1179 * | |
1180 alBufferData(data->buffer[0], | |
1181 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1182 (ALbyte*) data->sample->buffer, |
0 | 1183 data->total_bytes, |
1184 data->sample->desired.rate | |
1185 ); | |
1186 */ | |
1187 | |
1188 /* I was trying to set to the end, (1 byte remaining), | |
1189 * but I was getting freezes. I'm thinking it might be | |
1190 * another Power of 2 bug in the Loki dist. I tried 2, | |
1191 * and it still hung. 4 didn't hang, but I got a clip | |
1192 * artifact. 8 seemed to work okay. | |
1193 */ | |
1194 alBufferData(data->buffer[0], | |
1195 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1196 (((ALbyte*) data->sample->buffer) + (data->total_bytes - 8) ), |
0 | 1197 8, |
1198 data->sample->desired.rate | |
1199 ); | |
1200 if( (error = alGetError()) != AL_NO_ERROR) | |
1201 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1202 ALmixer_SetError("Can't seek past end and alBufferData failed: %s\n", alGetString(error)); |
0 | 1203 return -1; |
1204 } | |
1205 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1206 * query command to work because I don't know if it will mutilate the | |
1207 * size for its own purposes or return the original size | |
1208 */ | |
1209 data->loaded_bytes = 8; | |
1210 | |
1211 /* Not sure if this should be an error or not */ | |
1212 /* | |
1213 ALmixer_SetError("Can't Seek past end"); | |
1214 return -1; | |
1215 */ | |
1216 return 0; | |
1217 } | |
1218 | |
1219 alBufferData(data->buffer[0], | |
1220 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1221 &(((ALbyte*)data->sample->buffer)[byte_position]), |
0 | 1222 data->total_bytes - byte_position, |
1223 data->sample->desired.rate | |
1224 ); | |
1225 if( (error = alGetError()) != AL_NO_ERROR) | |
1226 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1227 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1228 return -1; |
1229 } | |
1230 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1231 * query command to work because I don't know if it will mutilate the | |
1232 * size for its own purposes or return the original size | |
1233 */ | |
1234 data->loaded_bytes = data->total_bytes - byte_position; | |
1235 | |
1236 return 0; | |
1237 } | |
1238 | |
1239 /* Because we have multiple queue buffers and OpenAL won't let | |
1240 * us access them, we need to keep copies of each buffer around | |
1241 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1242 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
|
1243 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1244 ALint index; |
0 | 1245 /* We only want to copy if access_data is true. |
1246 * This is determined by whether memory has been | |
1247 * allocated in the buffer_map_list or not | |
1248 */ | |
1249 if(NULL == data->buffer_map_list) | |
1250 { | |
1251 return -1; | |
1252 } | |
1253 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1254 if(-1 == index) | |
1255 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1256 /* |
0 | 1257 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
|
1258 */ |
0 | 1259 return -1; |
1260 } | |
1261 /* Copy the data to the access buffer */ | |
1262 memcpy(data->buffer_map_list[index].data, data->sample->buffer, num_bytes); | |
1263 data->buffer_map_list[index].num_bytes = data->sample->buffer_size; | |
1264 | |
1265 return 0; | |
1266 } | |
1267 | |
1268 | |
1269 /* For streamed data, gets more data | |
1270 * and prepares it in the active Mix_chunk | |
1271 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1272 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
|
1273 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1274 ALuint bytes_decoded; |
0 | 1275 ALenum error; |
1276 if(NULL == data) | |
1277 { | |
1278 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1279 return 0; | |
1280 } | |
1281 | |
1282 bytes_decoded = Sound_Decode(data->sample); | |
1283 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1284 { | |
1285 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1286 ALmixer_SetError(Sound_GetError()); | |
1287 /* Force cleanup through FreeData | |
1288 Sound_FreeSample(data->sample); | |
1289 */ | |
1290 return 0; | |
1291 } | |
1292 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1293 /* 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
|
1294 |
0 | 1295 /* Don't forget to add check for EOF */ |
1296 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1297 if(0 == bytes_decoded) | |
1298 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1299 data->eof = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1300 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1301 #if 0 |
0 | 1302 fprintf(stderr, "Hit eof while trying to buffer\n"); |
1303 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1304 { | |
1305 fprintf(stderr, "\tEOF flag\n"); | |
1306 } | |
1307 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1308 { | |
1309 fprintf(stderr, "\tCanSeek flag\n"); | |
1310 } | |
1311 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1312 { | |
1313 fprintf(stderr, "\tEAGAIN flag\n"); | |
1314 } | |
1315 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1316 { | |
1317 fprintf(stderr, "\tNONE flag\n"); | |
1318 } | |
1319 #endif | |
1320 return 0; | |
1321 } | |
1322 | |
1323 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
1324 /******* REMOVE ME ********************************/ | |
1325 /***************** ANOTHER EXPERIEMENT *******************/ | |
1326 /* The PROBLEM: It seems that the Loki distribution has problems | |
1327 * with Queuing when the buffer size is not a power of two | |
1328 * and additional buffers must come after it. | |
1329 * The behavior is inconsistent, but one of several things | |
1330 * usually happens: | |
1331 * Playback is normal | |
1332 * Playback immediately stops after the non-pow2 buffer | |
1333 * Playback gets distorted on the non-pow2 buffer | |
1334 * The entire program segfaults. | |
1335 * The workaround is to always specify a power of two buffer size | |
1336 * and hope that SDL_sound always fill it. (By lucky coincidence, | |
1337 * I already submitted the Ogg fix.) However, this won't catch | |
1338 * cases where a loop happens because the read at the end of the | |
1339 * file is typically less than the buffer size. | |
1340 * | |
1341 * This fix addresses this issue, however it may break in | |
1342 * other conditions. Always decode in buffer sizes of powers of 2. | |
1343 * | |
1344 * The HACK: | |
1345 * If the buffer is short, try filling it up with 0's | |
1346 * to meet the user requested buffer_size which | |
1347 * is probably a nice number OpenAL likes, in | |
1348 * hopes to avoid a possible Loki bug with | |
1349 * short buffers. If looping (which is the main | |
1350 * reason for this), the negative side effect is | |
1351 * that it may take longer for the loop to start | |
1352 * because it must play dead silence. Or if the decoder | |
1353 * doesn't guarantee to return the requested bytes | |
1354 * (like Ogg), then you will get breakup in between | |
1355 * packets. | |
1356 */ | |
1357 if( (bytes_decoded) < data->sample->buffer_size) | |
1358 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1359 ALubyte bit_depth; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1360 ALubyte signedness_value; |
0 | 1361 int silence_value; |
1362 /* Crap, memset value needs to be the "silent" value, | |
1363 * but it will differ for signed/unsigned and bit depth | |
1364 */ | |
1365 bit_depth = GetBitDepth(data->sample->desired.format); | |
1366 signedness_value = GetSignednessValue(data->sample->desired.format); | |
1367 if(ALMIXER_SIGNED_VALUE == signedness_value) | |
1368 { | |
1369 /* I'm guessing that if it's signed, then 0 is the | |
1370 * "silent" value */ | |
1371 silence_value = 0; | |
1372 } | |
1373 else | |
1374 { | |
1375 if(8 == bit_depth) | |
1376 { | |
1377 /* If 8 bit, I'm guessing it's (2^7)-1 = 127 */ | |
1378 silence_value = 127; | |
1379 } | |
1380 else | |
1381 { | |
1382 /* For 16 bit, I'm guessing it's (2^15)-1 = 32767 */ | |
1383 silence_value = 32767; | |
1384 } | |
1385 } | |
1386 /* Now fill up the rest of the data buffer with the | |
1387 * silence_value. | |
1388 * I don't think I have to worry about endian issues for | |
1389 * this part since the data is for internal use only | |
1390 * at this point. | |
1391 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1392 memset( &( ((ALbyte*)(data->sample->buffer))[bytes_decoded] ), silence_value, data->sample->buffer_size - bytes_decoded); |
0 | 1393 /* Now reset the bytes_decoded to reflect the entire |
1394 * buffer to tell alBufferData what our full size is. | |
1395 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1396 /* |
0 | 1397 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
|
1398 */ |
0 | 1399 bytes_decoded = data->sample->buffer_size; |
1400 } | |
1401 /*********** END EXPERIMENT ******************************/ | |
1402 /******* END REMOVE ME ********************************/ | |
1403 #endif | |
1404 | |
1405 /* Now copy the data to the OpenAL buffer */ | |
1406 /* We can't just set a pointer because the API needs | |
1407 * its own copy to assist hardware acceleration */ | |
1408 alBufferData(buffer, | |
1409 TranslateFormat(&data->sample->desired), | |
1410 data->sample->buffer, | |
1411 bytes_decoded, | |
1412 data->sample->desired.rate | |
1413 ); | |
1414 if( (error = alGetError()) != AL_NO_ERROR) | |
1415 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1416 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1417 return 0; |
1418 } | |
1419 | |
1420 /* If we need to, copy the data also to the access area | |
1421 * (the function will do the check for us) | |
1422 */ | |
1423 CopyDataToAccessBuffer(data, bytes_decoded, buffer); | |
1424 return bytes_decoded; | |
1425 } | |
1426 | |
1427 | |
1428 | |
1429 | |
1430 /******************** EXPERIEMENT **************************** | |
1431 * Test function to force maximum buffer filling during loops | |
1432 * REMOVE LATER | |
1433 *********************************************/ | |
1434 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1435 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
|
1436 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1437 ALint bytes_decoded; |
0 | 1438 ALenum error; |
1439 if(NULL == data) | |
1440 { | |
1441 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1442 return -1; | |
1443 } | |
1444 | |
1445 if(AL_FALSE == alIsBuffer(buffer)) | |
1446 { | |
1447 fprintf(stderr, "NOT A BUFFER>>>>>>>>>>>>>>>\n"); | |
1448 return -1; | |
1449 } | |
1450 fprintf(stderr, "Entered GetMoreData222222: buffer id is %d\n", buffer); | |
1451 | |
1452 /* | |
1453 fprintf(stderr, "Decode in GetMoreData\n"); | |
1454 */ | |
1455 | |
1456 #if 0 | |
1457 if(buffer%2 == 1) | |
1458 { | |
1459 fprintf(stderr, "Setting buffer size to 16384\n"); | |
1460 Sound_SetBufferSize(data->sample, 16384); | |
1461 } | |
1462 else | |
1463 { | |
1464 fprintf(stderr, "Setting buffer size to 8192\n"); | |
1465 Sound_SetBufferSize(data->sample, 8192); | |
1466 } | |
1467 #endif | |
1468 | |
1469 bytes_decoded = Sound_Decode(data->sample); | |
1470 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1471 { | |
1472 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1473 ALmixer_SetError(Sound_GetError()); | |
1474 /* | |
1475 Sound_FreeSample(data->sample); | |
1476 */ | |
1477 return -1; | |
1478 } | |
1479 /* Don't forget to add check for EOF */ | |
1480 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1481 if(0 == bytes_decoded) | |
1482 { | |
1483 #if 1 | |
1484 fprintf(stderr, "Hit eof while trying to buffer\n"); | |
1485 data->eof = 1; | |
1486 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1487 { | |
1488 fprintf(stderr, "\tEOF flag\n"); | |
1489 } | |
1490 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1491 { | |
1492 fprintf(stderr, "\tCanSeek flag\n"); | |
1493 } | |
1494 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1495 { | |
1496 fprintf(stderr, "\tEAGAIN flag\n"); | |
1497 } | |
1498 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1499 { | |
1500 fprintf(stderr, "\tNONE flag\n"); | |
1501 } | |
1502 #endif | |
1503 return 0; | |
1504 } | |
1505 | |
1506 if(bytes_decoded < 16384) | |
1507 { | |
1508 char* tempbuffer1 = (char*)malloc(16384); | |
1509 char* tempbuffer2 = (char*)malloc(16384); | |
1510 int retval; | |
1511 memcpy(tempbuffer1, data->sample->buffer, bytes_decoded); | |
1512 retval = Sound_SetBufferSize(data->sample, 16384-bytes_decoded); | |
1513 if(retval == 1) | |
1514 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1515 ALuint new_bytes; |
0 | 1516 Sound_Rewind(data->sample); |
1517 new_bytes = Sound_Decode(data->sample); | |
1518 fprintf(stderr, "Orig bytes: %d, Make up bytes_decoded=%d, total=%d\n", bytes_decoded, new_bytes, new_bytes+bytes_decoded); | |
1519 | |
1520 memcpy(tempbuffer2, data->sample->buffer, new_bytes); | |
1521 | |
1522 retval = Sound_SetBufferSize(data->sample, 16384); | |
1523 fprintf(stderr, "Finished reset...now danger copy\n"); | |
1524 memcpy(data->sample->buffer, tempbuffer1,bytes_decoded); | |
1525 | |
1526 fprintf(stderr, "Finished reset...now danger copy2\n"); | |
1527 memcpy( &( ((char*)(data->sample->buffer))[bytes_decoded] ), tempbuffer2, new_bytes); | |
1528 | |
1529 fprintf(stderr, "Finished \n"); | |
1530 | |
1531 free(tempbuffer1); | |
1532 free(tempbuffer2); | |
1533 bytes_decoded += new_bytes; | |
1534 fprintf(stderr, "ASSERT bytes should equal 16384: %d\n", bytes_decoded); | |
1535 } | |
1536 else | |
1537 { | |
1538 fprintf(stderr, "Experiment failed: %s\n", Sound_GetError()); | |
1539 } | |
1540 } | |
1541 | |
1542 /* Now copy the data to the OpenAL buffer */ | |
1543 /* We can't just set a pointer because the API needs | |
1544 * its own copy to assist hardware acceleration */ | |
1545 alBufferData(buffer, | |
1546 TranslateFormat(&data->sample->desired), | |
1547 data->sample->buffer, | |
1548 bytes_decoded, | |
1549 data->sample->desired.rate | |
1550 ); | |
1551 if( (error = alGetError()) != AL_NO_ERROR) | |
1552 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1553 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1554 return -1; |
1555 } | |
1556 | |
1557 fprintf(stderr, "GetMoreData2222 returning %d bytes decoded\n", bytes_decoded); | |
1558 return bytes_decoded; | |
1559 } | |
1560 #endif | |
1561 | |
1562 /************ END EXPERIEMENT - REMOVE ME *************************/ | |
1563 | |
1564 | |
1565 | |
1566 | |
1567 | |
1568 | |
1569 | |
1570 | |
1571 | |
1572 /* This function will look up the source for the corresponding channel */ | |
1573 /* 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
|
1574 static ALuint Internal_GetSource(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1575 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1576 ALint i; |
0 | 1577 /* Make sure channel is in bounds */ |
1578 if(channel >= Number_of_Channels_global) | |
1579 { | |
1580 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); | |
1581 return 0; | |
1582 } | |
1583 /* If the user specified -1, then return the an available source */ | |
1584 if(channel < 0) | |
1585 { | |
1586 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1587 { | |
1588 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1589 { | |
1590 return ALmixer_Channel_List[i].alsource; | |
1591 } | |
1592 } | |
1593 /* If we get here, all sources are in use */ | |
1594 /* Error message seems too harsh | |
1595 ALmixer_SetError("All sources are in use"); | |
1596 */ | |
1597 return 0; | |
1598 } | |
1599 /* Last case: Return the source for the channel */ | |
1600 return ALmixer_Channel_List[channel].alsource; | |
1601 } | |
1602 | |
1603 /* 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
|
1604 static ALint Internal_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1605 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1606 ALint i; |
0 | 1607 /* Only the first value is used for the key */ |
1608 Source_Map key = { 0, 0 }; | |
1609 Source_Map* found_item = NULL; | |
1610 key.source = source; | |
1611 | |
1612 /* If the source is 0, look up the first available channel */ | |
1613 if(0 == source) | |
1614 { | |
1615 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1616 { | |
1617 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1618 { | |
1619 return i; | |
1620 } | |
1621 } | |
1622 /* If we get here, all sources are in use */ | |
1623 /* Error message seems too harsh | |
1624 ALmixer_SetError("All channels are in use"); | |
1625 */ | |
1626 return -1; | |
1627 } | |
1628 | |
1629 | |
1630 /* Else, look up the source and return the channel */ | |
1631 if(AL_FALSE == alIsSource(source)) | |
1632 { | |
1633 ALmixer_SetError("Is not a source"); | |
1634 return -1; | |
1635 } | |
1636 | |
1637 /* Use the ANSI C binary search feature (yea!) */ | |
1638 found_item = (Source_Map*)bsearch(&key, Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
1639 if(NULL == found_item) | |
1640 { | |
1641 ALmixer_SetError("Source is valid but not registered with ALmixer (to a channel)"); | |
1642 return -1; | |
1643 } | |
1644 return found_item->channel; | |
1645 } | |
1646 | |
1647 | |
1648 | |
1649 /* This function will find the first available channel (not in use) | |
1650 * from the specified start channel. Reserved channels to not qualify | |
1651 * as available. | |
1652 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1653 static ALint Internal_FindFreeChannel(ALint start_channel) |
0 | 1654 { |
1655 /* Start at the number of reserved so we skip over | |
1656 * all the reserved channels. | |
1657 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1658 ALint i = Number_of_Reserve_Channels_global; |
0 | 1659 /* Quick check to see if we're out of bounds */ |
1660 if(start_channel >= Number_of_Channels_global) | |
1661 { | |
1662 return -1; | |
1663 } | |
1664 | |
1665 /* If the start channel is even higher than the reserved, | |
1666 * then start at the higher value. | |
1667 */ | |
1668 if(start_channel > Number_of_Reserve_Channels_global) | |
1669 { | |
1670 i = start_channel; | |
1671 } | |
1672 | |
1673 /* i has already been set */ | |
1674 for( ; i<Number_of_Channels_global; i++) | |
1675 { | |
1676 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1677 { | |
1678 return i; | |
1679 } | |
1680 } | |
1681 /* If we get here, all sources are in use */ | |
1682 return -1; | |
1683 } | |
1684 | |
1685 | |
1686 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1687 /* 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
|
1688 * or 0 for error |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1689 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1690 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
|
1691 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1692 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1693 ALint counter = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1694 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1695 ALint buffers_still_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1696 ALint buffers_processed; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1697 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1698 if(channel >= Number_of_Channels_global) |
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 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
|
1701 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1702 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1703 /* 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
|
1704 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1705 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1706 /* 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
|
1707 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
|
1708 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1709 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1710 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1711 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1712 fprintf(stderr, "14Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1713 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1714 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1715 /* 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
|
1716 * 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
|
1717 * 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
|
1718 * 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
|
1719 * 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
|
1720 * 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
|
1721 * 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
|
1722 * 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
|
1723 * 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
|
1724 * 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
|
1725 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1726 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1727 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1728 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1729 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1730 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1731 if((error = alGetError()) != AL_NO_ERROR) |
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 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
|
1734 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1735 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
|
1736 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1737 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1738 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1739 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1740 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1741 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1742 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1743 if((error = alGetError()) != AL_NO_ERROR) |
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 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
|
1746 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1747 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
|
1748 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1749 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1750 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1751 /* If 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
|
1752 * to clear the source |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1753 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1754 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
|
1755 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1756 alSourcei(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1757 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1758 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1759 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1760 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1761 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
|
1762 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1763 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
|
1764 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1765 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1766 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1767 } |
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 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
|
1770 |
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
|
1771 /* 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
|
1772 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
|
1773 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1774 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1775 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1776 counter++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1777 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1778 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1779 /* 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
|
1780 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1781 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1782 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1783 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
|
1784 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1785 /* 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
|
1786 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
|
1787 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1788 alSourceStop(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1789 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1790 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1791 fprintf(stderr, "19Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1792 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1793 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1794 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1795 /* 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
|
1796 * 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
|
1797 * 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
|
1798 * 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
|
1799 * 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
|
1800 * 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
|
1801 * 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
|
1802 * 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
|
1803 * 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
|
1804 * 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
|
1805 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1806 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1807 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1808 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1809 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1810 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1811 if((error = alGetError()) != AL_NO_ERROR) |
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 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
|
1814 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1815 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
|
1816 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1817 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1818 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1819 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1820 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1821 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1822 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1823 if((error = alGetError()) != AL_NO_ERROR) |
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 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
|
1826 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1827 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
|
1828 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1829 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1830 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1831 /* If 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
|
1832 * to clear the source |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1833 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1834 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
|
1835 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1836 alSourcei(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1837 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1838 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1839 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1840 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1841 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
|
1842 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1843 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
|
1844 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1845 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1846 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1847 } |
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 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
|
1850 |
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
|
1851 /* 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
|
1852 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
|
1853 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1854 Clean_Channel(i); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1855 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1856 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1857 /* Increment the counter */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1858 counter++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1859 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1860 /* 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
|
1861 * are bugs. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1862 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1863 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1864 else |
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 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1867 / * 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
|
1868 * data will get messed up * / |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1869 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1870 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1871 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1872 /* Just in case */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1873 Is_Playing_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1874 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1875 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1876 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1877 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1878 return -1; |
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 counter; |
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 |
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 /* 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
|
1885 * 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
|
1886 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1887 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
|
1888 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1889 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1890 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1891 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1892 /* 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
|
1893 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
|
1894 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1895 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1896 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1897 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1898 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1899 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
|
1900 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1901 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1902 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
|
1903 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1904 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1905 |
0 | 1906 |
1907 /* Note: Behaves, almost like SDL_mixer, but keep in mind | |
1908 * that there is no "music" channel anymore, so 0 | |
1909 * will remove everything. (Note, I no longer allow 0 | |
1910 * so it gets set to the default number.) | |
1911 * Also, callbacks for deleted channels will not be called. | |
1912 * I really need to do error checking, for realloc and | |
1913 * GenSources, but reversing the damage is too painful | |
1914 * for me to think about at the moment, so it's not in here. | |
1915 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1916 static ALint Internal_AllocateChannels(ALint numchans) |
0 | 1917 { |
1918 ALenum error; | |
1919 int i; | |
1920 /* Return info */ | |
1921 if(numchans < 0) | |
1922 { | |
1923 return Number_of_Channels_global; | |
1924 } | |
1925 if(0 == numchans) | |
1926 { | |
1927 numchans = ALMIXER_DEFAULT_NUM_CHANNELS; | |
1928 } | |
1929 /* No change */ | |
1930 if(numchans == Number_of_Channels_global) | |
1931 { | |
1932 return Number_of_Channels_global; | |
1933 } | |
1934 /* We need to increase the number of channels */ | |
1935 if(numchans > Number_of_Channels_global) | |
1936 { | |
1937 /* Not sure how safe this is, but SDL_mixer does it | |
1938 * the same way */ | |
1939 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1940 | |
1941 /* Allocate memory for the list of sources that map to the channels */ | |
1942 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
1943 | |
1944 for(i=Number_of_Channels_global; i<numchans; i++) | |
1945 { | |
1946 Init_Channel(i); | |
1947 /* Generate a new source and associate it with the channel */ | |
1948 alGenSources(1, &ALmixer_Channel_List[i].alsource); | |
1949 if((error = alGetError()) != AL_NO_ERROR) | |
1950 { | |
1951 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
|
1952 alGetString(error)); |
0 | 1953 } |
1954 /* Copy the source so the SourceMap has it too */ | |
1955 Source_Map_List[i].source = ALmixer_Channel_List[i].alsource; | |
1956 Source_Map_List[i].channel = i; | |
1957 /* Clean the channel because there are some things that need to | |
1958 * be done that can't happen until the source is set | |
1959 */ | |
1960 Clean_Channel(i); | |
1961 } | |
1962 | |
1963 /* The Source_Map_List must be sorted by source for binary searches | |
1964 */ | |
1965 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
1966 | |
1967 Number_of_Channels_global = numchans; | |
1968 return numchans; | |
1969 } | |
1970 /* Need to remove channels. This might be dangerous */ | |
1971 if(numchans < Number_of_Channels_global) | |
1972 { | |
1973 for(i=numchans; i<Number_of_Channels_global; i++) | |
1974 { | |
1975 /* Halt the channel */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1976 Internal_HaltChannel(i, AL_FALSE); |
0 | 1977 |
1978 /* Delete source associated with the channel */ | |
1979 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
1980 if((error = alGetError()) != AL_NO_ERROR) | |
1981 { | |
1982 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
|
1983 alGetString(error)); |
0 | 1984 } |
1985 } | |
1986 | |
1987 | |
1988 /* Not sure how safe this is, but SDL_mixer does it | |
1989 * the same way */ | |
1990 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1991 | |
1992 /* The tricky part is that we must remove the entries | |
1993 * in the source map that correspond to the deleted channels. | |
1994 * We'll resort the map by channels so we can pick them off | |
1995 * in order. | |
1996 */ | |
1997 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map_by_channel); | |
1998 | |
1999 /* Deallocate memory for the list of sources that map to the channels */ | |
2000 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
2001 | |
2002 /* Now resort the map by source and the correct num of chans */ | |
2003 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
2004 | |
2005 /* Reset the number of channels */ | |
2006 Number_of_Channels_global = numchans; | |
2007 return numchans; | |
2008 } | |
2009 /* Shouldn't ever reach here */ | |
2010 return -1; | |
2011 | |
2012 } | |
2013 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2014 static ALint Internal_ReserveChannels(ALint num) |
0 | 2015 { |
2016 /* Can't reserve more than the max num of channels */ | |
2017 /* Actually, I'll allow it for people who just want to | |
2018 * set the value really high to effectively disable | |
2019 * auto-assignment | |
2020 */ | |
2021 | |
2022 /* Return the current number of reserved channels */ | |
2023 if(num < 0) | |
2024 { | |
2025 return Number_of_Reserve_Channels_global; | |
2026 } | |
2027 Number_of_Reserve_Channels_global = num; | |
2028 return Number_of_Reserve_Channels_global; | |
2029 } | |
2030 | |
2031 | |
2032 /* This will rewind the SDL_Sound sample for streamed | |
2033 * samples and start buffering up the data for the next | |
2034 * playback. This may require samples to be halted | |
2035 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2036 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
|
2037 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2038 ALint retval = 0; |
0 | 2039 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2040 ALint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2041 ALint i; |
0 | 2042 */ |
2043 if(NULL == data) | |
2044 { | |
2045 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
|
2046 return AL_FALSE; |
0 | 2047 } |
2048 | |
2049 | |
2050 /* Might have to require Halt */ | |
2051 /* Okay, we assume Halt or natural stop has already | |
2052 * cleared the data buffers | |
2053 */ | |
2054 if(data->in_use) | |
2055 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2056 /* |
0 | 2057 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
|
2058 */ |
0 | 2059 /* |
2060 ALmixer_SetError("Data is in use. Cannot rewind unless all sources using the data are halted\n"); | |
2061 return -1; | |
2062 */ | |
2063 } | |
2064 | |
2065 | |
2066 /* Because Seek can alter things even in predecoded data, | |
2067 * decoded data must also be rewound | |
2068 */ | |
2069 if(data->decoded_all) | |
2070 { | |
2071 data->eof = 0; | |
2072 | |
2073 #if 0 | |
2074 #if defined(DISABLE_PREDECODED_SEEK) | |
2075 /* 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
|
2076 return AL_TRUE; |
0 | 2077 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) |
2078 /* This case is if the Sound_Sample has been deleted. | |
2079 * It assumes the data is already at the beginning. | |
2080 */ | |
2081 if(NULL == data->sample) | |
2082 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2083 return AL_TRUE; |
0 | 2084 } |
2085 /* Else, the sample has already been reallocated, | |
2086 * and we can fall to normal behavior | |
2087 */ | |
2088 #endif | |
2089 #endif | |
2090 /* If access_data, was enabled, the sound sample | |
2091 * still exists and we can do stuff. | |
2092 * If it's NULL, we can't do anything, but | |
2093 * it should already be "rewound". | |
2094 */ | |
2095 if(NULL == data->sample) | |
2096 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2097 return AL_TRUE; |
0 | 2098 } |
2099 /* Else, the sample has already been reallocated, | |
2100 * and we can fall to normal behavior | |
2101 */ | |
2102 | |
2103 Set_Predecoded_Seek_Position(data, 0); | |
2104 /* | |
2105 return data->total_bytes; | |
2106 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2107 return AL_TRUE; |
0 | 2108 } |
2109 | |
2110 /* Remaining stuff for streamed data */ | |
2111 | |
2112 data->eof = 0; | |
2113 retval = Sound_Rewind(data->sample); | |
2114 if(0 == retval) | |
2115 { | |
2116 ALmixer_SetError( Sound_GetError() ); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2117 return AL_FALSE; |
0 | 2118 } |
2119 #if 0 | |
2120 /* Clear error */ | |
2121 alGetError(); | |
2122 for(i=0; i<data->num_buffers; i++) | |
2123 { | |
2124 bytes_returned = GetMoreData(data, data->buffer[i]); | |
2125 if(-1 == bytes_returned) | |
2126 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2127 return AL_FALSE; |
0 | 2128 } |
2129 else if(0 == bytes_returned) | |
2130 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2131 return AL_FALSE; |
0 | 2132 } |
2133 retval += bytes_returned; | |
2134 | |
2135 } | |
2136 #endif | |
2137 | |
2138 | |
2139 | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2140 return AL_TRUE; |
0 | 2141 } |
2142 | |
2143 | |
2144 | |
2145 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2146 static ALint Internal_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2147 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2148 ALint retval = 0; |
0 | 2149 ALenum error; |
2150 ALint state; | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2151 ALint running_count = 0; |
0 | 2152 |
2153 if(channel >= Number_of_Channels_global) | |
2154 { | |
2155 ALmixer_SetError("Cannot rewind channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2156 return -1; | |
2157 } | |
2158 | |
2159 if((error = alGetError()) != AL_NO_ERROR) | |
2160 { | |
2161 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
|
2162 alGetString(error)); |
0 | 2163 } |
2164 /* Clear error */ | |
2165 alGetError(); | |
2166 | |
2167 /* If the user specified a specific channel */ | |
2168 if(channel >= 0) | |
2169 { | |
2170 /* only need to process channel if in use */ | |
2171 if(ALmixer_Channel_List[channel].channel_in_use) | |
2172 { | |
2173 | |
2174 /* What should I do? Do I just rewind the channel | |
2175 * or also rewind the data? Since the data is | |
2176 * shared, let's make it the user's responsibility | |
2177 * to rewind the data. | |
2178 */ | |
2179 if(ALmixer_Channel_List[channel].almixer_data->decoded_all) | |
2180 { | |
2181 alGetSourcei( | |
2182 ALmixer_Channel_List[channel].alsource, | |
2183 AL_SOURCE_STATE, &state | |
2184 ); | |
2185 if((error = alGetError()) != AL_NO_ERROR) | |
2186 { | |
2187 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
|
2188 alGetString(error)); |
0 | 2189 } |
2190 alSourceRewind(ALmixer_Channel_List[channel].alsource); | |
2191 if((error = alGetError()) != AL_NO_ERROR) | |
2192 { | |
2193 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2194 alGetString(error) ); |
0 | 2195 retval = -1; |
2196 } | |
2197 /* Need to resume playback if it was originally playing */ | |
2198 if(AL_PLAYING == state) | |
2199 { | |
2200 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2201 if((error = alGetError()) != AL_NO_ERROR) | |
2202 { | |
2203 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2204 alGetString(error) ); |
0 | 2205 retval = -1; |
2206 } | |
2207 } | |
2208 else if(AL_PAUSED == state) | |
2209 { | |
2210 /* HACK: The problem is that when paused, after | |
2211 * the Rewind, I can't get it off the INITIAL | |
2212 * state without restarting | |
2213 */ | |
2214 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2215 if((error = alGetError()) != AL_NO_ERROR) | |
2216 { | |
2217 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
|
2218 alGetString(error)); |
0 | 2219 } |
2220 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2221 if((error = alGetError()) != AL_NO_ERROR) | |
2222 { | |
2223 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2224 alGetString(error) ); |
0 | 2225 retval = -1; |
2226 } | |
2227 } | |
2228 } | |
2229 else | |
2230 { | |
2231 /* Streamed data is different. Rewinding the channel | |
2232 * does no good. Rewinding the data will have an | |
2233 * effect, but it will be lagged based on how | |
2234 * much data is queued. Recommend users call Halt | |
2235 * before rewind if they want immediate results. | |
2236 */ | |
2237 retval = Internal_RewindData(ALmixer_Channel_List[channel].almixer_data); | |
2238 } | |
2239 } | |
2240 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2241 /* The user wants to rewind all channels */ |
0 | 2242 else |
2243 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2244 ALint i; |
0 | 2245 for(i=0; i<Number_of_Channels_global; i++) |
2246 { | |
2247 /* only need to process channel if in use */ | |
2248 if(ALmixer_Channel_List[i].channel_in_use) | |
2249 { | |
2250 /* What should I do? Do I just rewind the channel | |
2251 * or also rewind the data? Since the data is | |
2252 * shared, let's make it the user's responsibility | |
2253 * to rewind the data. | |
2254 */ | |
2255 if(ALmixer_Channel_List[i].almixer_data->decoded_all) | |
2256 { | |
2257 alGetSourcei( | |
2258 ALmixer_Channel_List[i].alsource, | |
2259 AL_SOURCE_STATE, &state | |
2260 ); | |
2261 if((error = alGetError()) != AL_NO_ERROR) | |
2262 { | |
2263 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
|
2264 alGetString(error)); |
0 | 2265 } |
2266 alSourceRewind(ALmixer_Channel_List[i].alsource); | |
2267 if((error = alGetError()) != AL_NO_ERROR) | |
2268 { | |
2269 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2270 alGetString(error) ); |
0 | 2271 retval = -1; |
2272 } | |
2273 /* Need to resume playback if it was originally playing */ | |
2274 if(AL_PLAYING == state) | |
2275 { | |
2276 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2277 if((error = alGetError()) != AL_NO_ERROR) | |
2278 { | |
2279 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2280 alGetString(error) ); |
0 | 2281 retval = -1; |
2282 } | |
2283 } | |
2284 else if(AL_PAUSED == state) | |
2285 { | |
2286 /* HACK: The problem is that when paused, after | |
2287 * the Rewind, I can't get it off the INITIAL | |
2288 * state without restarting | |
2289 */ | |
2290 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2291 if((error = alGetError()) != AL_NO_ERROR) | |
2292 { | |
2293 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
|
2294 alGetString(error)); |
0 | 2295 } |
2296 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2297 if((error = alGetError()) != AL_NO_ERROR) | |
2298 { | |
2299 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2300 alGetString(error) ); |
0 | 2301 retval = -1; |
2302 } | |
2303 } | |
2304 } | |
2305 else | |
2306 { | |
2307 /* Streamed data is different. Rewinding the channel | |
2308 * does no good. Rewinding the data will have an | |
2309 * effect, but it will be lagged based on how | |
2310 * much data is queued. Recommend users call Halt | |
2311 * before rewind if they want immediate results. | |
2312 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2313 running_count += Internal_RewindData(ALmixer_Channel_List[i].almixer_data); |
0 | 2314 } |
2315 } | |
2316 } | |
2317 } | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2318 if(-1 == retval) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2319 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2320 return -1; |
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 else |
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 return running_count; |
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 |
0 | 2327 } |
2328 | |
2329 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2330 static ALint Internal_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2331 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2332 ALint channel; |
0 | 2333 if(0 == source) |
2334 { | |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
2335 return Internal_RewindChannel(-1); |
0 | 2336 } |
2337 | |
2338 channel = Internal_GetChannel(source); | |
2339 if(-1 == channel) | |
2340 { | |
2341 ALmixer_SetError("Cannot rewind source: %s", ALmixer_GetError()); | |
2342 return 0; | |
2343 } | |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
2344 return Internal_RewindChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2345 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2346 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2347 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2348 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2349 |
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 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
|
2352 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2353 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2354 int ret_flag = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2355 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2356 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2357 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
|
2358 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2359 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2360 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2361 /* 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
|
2362 * 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
|
2363 * 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
|
2364 * 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
|
2365 * 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
|
2366 * to prevent sharing |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2367 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2368 if(0 == data->decoded_all) |
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(data->in_use) |
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 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
|
2373 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2374 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2375 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2376 /* 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
|
2377 * This mainly affects streamed files, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2378 * so the check is placed here |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2379 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2380 if(data->eof) |
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( -1 == Internal_RewindData(data) ) |
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 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
|
2385 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2386 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2387 } |
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 /* 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
|
2390 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2391 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2392 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2393 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
|
2394 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2395 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
|
2396 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2397 channel = i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2398 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2399 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2400 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2401 /* 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
|
2402 if(i == Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2403 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2404 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
|
2405 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2406 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2407 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2408 /* 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
|
2409 * out of bounds or in use */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2410 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2411 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2412 if(channel >= Number_of_Channels_global) |
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 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
|
2415 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2416 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2417 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
|
2418 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2419 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
|
2420 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2421 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2422 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2423 /* 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
|
2424 if(loops < -1) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2425 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2426 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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2429 /* 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
|
2430 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2431 /* 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
|
2432 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
|
2433 data->in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2434 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2435 /* 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
|
2436 * (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
|
2437 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2438 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
|
2439 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
|
2440 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
|
2441 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2442 /* 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
|
2443 if(ticks < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2444 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2445 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
|
2446 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2447 else |
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 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
|
2450 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2451 |
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 ALmixer_Channel_List[channel].halted = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2454 ALmixer_Channel_List[channel].paused = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2455 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2456 /* 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
|
2457 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2458 if( (-1 == loops) && (data->decoded_all) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2459 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2460 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
|
2461 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2462 else |
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 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
|
2465 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2466 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2467 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2468 fprintf(stderr, "13Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2469 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2470 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2471 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2472 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2473 /* Because of the corner case, predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2474 * 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
|
2475 * Streams do not have this problem |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2476 * 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
|
2477 * avoid the conflict. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2478 * 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
|
2479 * Since streams, cannot share, only predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2480 * files are affected |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2481 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2482 if(data->decoded_all) |
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 /* 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
|
2485 * 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
|
2486 * 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
|
2487 * must be +1 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2488 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2489 if(-1 == loops) |
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 /* -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
|
2492 * to add +1 to it */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2493 ALmixer_Channel_List[channel].loops = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2494 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
|
2495 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2496 else |
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 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
|
2499 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
|
2500 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2501 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2502 else |
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 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2505 /* 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
|
2506 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
|
2507 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2508 #endif |
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 /* 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
|
2511 /* 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
|
2512 * 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
|
2513 * 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
|
2514 * 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
|
2515 * 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
|
2516 * 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
|
2517 * easier to maintain. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2518 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2519 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2520 /* Clear the error flag */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2521 alGetError(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2522 if(data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2523 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2524 /* Bind the data to the source */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2525 alSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2526 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2527 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2528 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2529 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2530 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2531 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
|
2532 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2533 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2534 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2535 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2536 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2537 /* 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
|
2538 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
|
2539 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2540 else |
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 /* 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
|
2543 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2544 ALuint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2545 ALuint j; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2546 data->num_buffers_in_use=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2547 /****** MODIFICATION must go here *********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2548 /* 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
|
2549 * 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
|
2550 * 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
|
2551 * 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
|
2552 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2553 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2554 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2555 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2556 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2557 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2558 /* No data or error */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2559 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
|
2560 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2561 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2562 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2563 /* 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
|
2564 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2565 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2566 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2567 /* 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
|
2568 * 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
|
2569 * before the last buffer is filled. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2570 * 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
|
2571 * 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
|
2572 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2573 |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2574 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2575 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
|
2576 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2577 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
|
2578 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2579 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2580 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
|
2581 fprintf(stderr, ">>>>>>>>>>>>>>>>>>HACK for GetMoreData2\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2582 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2583 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2584 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2585 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2586 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2587 * 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
|
2588 * 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
|
2589 * 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
|
2590 * 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
|
2591 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2592 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2593 if(bytes_returned < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2594 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2595 /* Error found */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2596 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
|
2597 /* 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
|
2598 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2599 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2600 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2601 else if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2602 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2603 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2604 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2605 /* No more data to buffer */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2606 /* Check for loops */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2607 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
|
2608 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2609 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2610 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
|
2611 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2612 if(0 == Sound_Rewind(data->sample)) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2613 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2614 fprintf(stderr, "error in rewind\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2615 ALmixer_SetError( Sound_GetError() ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2616 ALmixer_Channel_List[channel].loops = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2617 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2618 /* 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
|
2619 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2620 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2621 /* 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
|
2622 data->eof = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2623 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
|
2624 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2625 ALmixer_Channel_List[channel].loops--; |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2626 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2627 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
|
2628 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2629 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2630 /* 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
|
2631 * 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
|
2632 * into an infinite loop |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2633 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2634 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2635 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2636 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2637 if(bytes_returned <= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2638 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2639 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
|
2640 /* 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
|
2641 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2642 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2643 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2644 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2645 else |
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 /* 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
|
2648 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2649 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2650 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2651 /* 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
|
2652 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2653 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2654 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2655 fprintf(stderr, "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
|
2656 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2657 data->num_buffers_in_use); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2658 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2659 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2660 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2661 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2662 data->num_buffers_in_use, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2663 data->buffer); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2664 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2665 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2666 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
|
2667 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2668 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2669 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2670 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2671 /* 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
|
2672 * 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
|
2673 * 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
|
2674 * 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
|
2675 * "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
|
2676 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2677 if(data->circular_buffer_queue != 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 ALuint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2680 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2681 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
|
2682 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2683 // fprintf(stderr, "56c: CircularQueue_PushBack.\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2684 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
|
2685 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2686 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2687 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
|
2688 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
|
2689 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2690 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2691 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2692 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2693 fprintf(stderr, "Queue in PlayTimed\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2694 CircularQueueUnsignedInt_Print(data->circular_buffer_queue); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2695 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2696 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2697 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2698 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2699 |
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 /****** END **********/ |
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 /* 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
|
2704 * so now we can play |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2705 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2706 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2707 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2708 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2709 ALmixer_SetError("Play failed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2710 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2711 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2712 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2713 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2714 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2715 /* 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
|
2716 Is_Playing_global++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2717 if(-1 == ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2718 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2719 fprintf(stderr, "BACKDOOR ERROR >>>>>>>>>>>>>>>>>>\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2720 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2721 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2722 return channel; |
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 |
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 /* 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
|
2727 * 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
|
2728 * 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
|
2729 * PlayChannelTimed() function call. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2730 * 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
|
2731 * 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
|
2732 * 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
|
2733 * 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
|
2734 * 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
|
2735 * 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
|
2736 * 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
|
2737 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2738 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
|
2739 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2740 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2741 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2742 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2743 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2744 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
|
2745 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2746 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2747 return 0; |
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 else |
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 return Internal_GetSource(retval); |
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 } |
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 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2756 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2757 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2758 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
|
2759 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2760 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2761 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
|
2762 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2763 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2764 return 0; |
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 else |
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 return source; |
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 /* make compiler happy */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2771 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2772 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2773 |
0 | 2774 |
2775 | |
2776 | |
2777 /* Returns the channel or number of channels actually paused */ | |
2778 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2779 static ALint Internal_PauseChannel(ALint channel) |
0 | 2780 { |
2781 ALenum error; | |
2782 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2783 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2784 ALint counter = 0; |
0 | 2785 |
2786 if(channel >= Number_of_Channels_global) | |
2787 { | |
2788 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2789 return -1; | |
2790 } | |
2791 | |
2792 if((error = alGetError()) != AL_NO_ERROR) | |
2793 { | |
2794 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
|
2795 alGetString(error)); |
0 | 2796 } |
2797 /* Clear error */ | |
2798 alGetError(); | |
2799 | |
2800 /* If the user specified a specific channel */ | |
2801 if(channel >= 0) | |
2802 { | |
2803 /* only need to process channel if in use */ | |
2804 if(ALmixer_Channel_List[channel].channel_in_use) | |
2805 { | |
2806 /* We don't want to repause if already | |
2807 * paused because the fadeout/expire | |
2808 * timing will get messed up | |
2809 */ | |
2810 alGetSourcei( | |
2811 ALmixer_Channel_List[channel].alsource, | |
2812 AL_SOURCE_STATE, &state | |
2813 ); | |
2814 if((error = alGetError()) != AL_NO_ERROR) | |
2815 { | |
2816 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
|
2817 alGetString(error)); |
0 | 2818 } |
2819 if(AL_PLAYING == state) | |
2820 { | |
2821 /* Count the actual number of channels being paused */ | |
2822 counter++; | |
2823 | |
2824 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2825 if((error = alGetError()) != AL_NO_ERROR) | |
2826 { | |
2827 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2828 alGetString(error) ); |
0 | 2829 retval = -1; |
2830 } | |
2831 /* We need to pause the expire time count down */ | |
2832 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
2833 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2834 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2835 ALuint diff_time; |
0 | 2836 diff_time = current_time - |
2837 ALmixer_Channel_List[channel].start_time; | |
2838 /* When we unpause, we will want to reset | |
2839 * the start time so we can continue | |
2840 * to base calculations off GetTicks(). | |
2841 * This means we need to subtract the amount | |
2842 * of time already used up from expire_ticks. | |
2843 */ | |
2844 ALmixer_Channel_List[channel].expire_ticks = | |
2845 ALmixer_Channel_List[channel].expire_ticks - | |
2846 diff_time; | |
2847 /* Because -1 is a special value, we can't | |
2848 * allow the time to go negative | |
2849 */ | |
2850 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2851 { | |
2852 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2853 } | |
2854 } | |
2855 /* Do the same as expire time for fading */ | |
2856 if(ALmixer_Channel_List[channel].fade_enabled) | |
2857 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2858 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2859 ALuint diff_time; |
0 | 2860 diff_time = current_time - |
2861 ALmixer_Channel_List[channel].fade_start_time; | |
2862 /* When we unpause, we will want to reset | |
2863 * the start time so we can continue | |
2864 * to base calculations off GetTicks(). | |
2865 * This means we need to subtract the amount | |
2866 * of time already used up from expire_ticks. | |
2867 */ | |
2868 ALmixer_Channel_List[channel].fade_expire_ticks = | |
2869 ALmixer_Channel_List[channel].fade_expire_ticks - | |
2870 diff_time; | |
2871 /* Don't allow the time to go negative */ | |
2872 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2873 { | |
2874 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2875 } | |
2876 } /* End fade check */ | |
2877 } /* End if PLAYING */ | |
2878 } /* End If in use */ | |
2879 } /* End specific channel */ | |
2880 /* The user wants to halt all channels */ | |
2881 else | |
2882 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2883 ALint i; |
0 | 2884 for(i=0; i<Number_of_Channels_global; i++) |
2885 { | |
2886 /* only need to process channel if in use */ | |
2887 if(ALmixer_Channel_List[i].channel_in_use) | |
2888 { | |
2889 /* We don't want to repause if already | |
2890 * paused because the fadeout/expire | |
2891 * timing will get messed up | |
2892 */ | |
2893 alGetSourcei( | |
2894 ALmixer_Channel_List[i].alsource, | |
2895 AL_SOURCE_STATE, &state | |
2896 ); | |
2897 if((error = alGetError()) != AL_NO_ERROR) | |
2898 { | |
2899 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
|
2900 alGetString(error)); |
0 | 2901 } |
2902 if(AL_PLAYING == state) | |
2903 { | |
2904 /* Count the actual number of channels being paused */ | |
2905 counter++; | |
2906 | |
2907 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2908 if((error = alGetError()) != AL_NO_ERROR) | |
2909 { | |
2910 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2911 alGetString(error) ); |
0 | 2912 retval = -1; |
2913 } | |
2914 /* We need to pause the expire time count down */ | |
2915 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
2916 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2917 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2918 ALuint diff_time; |
0 | 2919 diff_time = current_time - |
2920 ALmixer_Channel_List[i].start_time; | |
2921 /* When we unpause, we will want to reset | |
2922 * the start time so we can continue | |
2923 * to base calculations off GetTicks(). | |
2924 * This means we need to subtract the amount | |
2925 * of time already used up from expire_ticks. | |
2926 */ | |
2927 ALmixer_Channel_List[i].expire_ticks = | |
2928 ALmixer_Channel_List[i].expire_ticks - | |
2929 diff_time; | |
2930 /* Because -1 is a special value, we can't | |
2931 * allow the time to go negative | |
2932 */ | |
2933 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2934 { | |
2935 ALmixer_Channel_List[i].expire_ticks = 0; | |
2936 } | |
2937 } | |
2938 /* Do the same as expire time for fading */ | |
2939 if(ALmixer_Channel_List[i].fade_enabled) | |
2940 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2941 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2942 ALuint diff_time; |
0 | 2943 diff_time = current_time - |
2944 ALmixer_Channel_List[i].fade_start_time; | |
2945 /* When we unpause, we will want to reset | |
2946 * the start time so we can continue | |
2947 * to base calculations off GetTicks(). | |
2948 * This means we need to subtract the amount | |
2949 * of time already used up from expire_ticks. | |
2950 */ | |
2951 ALmixer_Channel_List[i].fade_expire_ticks = | |
2952 ALmixer_Channel_List[i].fade_expire_ticks - | |
2953 diff_time; | |
2954 /* Don't allow the time to go negative */ | |
2955 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2956 { | |
2957 ALmixer_Channel_List[i].expire_ticks = 0; | |
2958 } | |
2959 } /* End fade check */ | |
2960 } /* End if PLAYING */ | |
2961 } /* End channel in use */ | |
2962 } /* End for-loop */ | |
2963 } | |
2964 if(-1 == retval) | |
2965 { | |
2966 return -1; | |
2967 } | |
2968 return counter; | |
2969 } | |
2970 | |
2971 /* 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
|
2972 static ALint Internal_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2973 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2974 ALint channel; |
0 | 2975 if(0 == source) |
2976 { | |
2977 return Internal_PauseChannel(-1); | |
2978 } | |
2979 | |
2980 channel = Internal_GetChannel(source); | |
2981 if(-1 == channel) | |
2982 { | |
2983 ALmixer_SetError("Cannot pause source: %s", ALmixer_GetError()); | |
2984 return -1; | |
2985 } | |
2986 return Internal_PauseChannel(channel); | |
2987 } | |
2988 | |
2989 | |
2990 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2991 static ALint Internal_ResumeChannel(ALint channel) |
0 | 2992 { |
2993 ALint state; | |
2994 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2995 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2996 ALint counter = 0; |
0 | 2997 |
2998 if(channel >= Number_of_Channels_global) | |
2999 { | |
3000 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
3001 return -1; | |
3002 } | |
3003 | |
3004 if((error = alGetError()) != AL_NO_ERROR) | |
3005 { | |
3006 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
|
3007 alGetString(error)); |
0 | 3008 } |
3009 /* Clear error */ | |
3010 alGetError(); | |
3011 | |
3012 /* If the user specified a specific channel */ | |
3013 if(channel >= 0) | |
3014 { | |
3015 /* only need to process channel if in use */ | |
3016 if(ALmixer_Channel_List[channel].channel_in_use) | |
3017 { | |
3018 alGetSourcei( | |
3019 ALmixer_Channel_List[channel].alsource, | |
3020 AL_SOURCE_STATE, &state | |
3021 ); | |
3022 if((error = alGetError()) != AL_NO_ERROR) | |
3023 { | |
3024 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
|
3025 alGetString(error)); |
0 | 3026 } |
3027 if(AL_PAUSED == state) | |
3028 { | |
3029 /* Count the actual number of channels resumed */ | |
3030 counter++; | |
3031 | |
3032 /* We need to resume the expire time count down */ | |
3033 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
3034 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3035 ALmixer_Channel_List[channel].start_time = ALmixer_GetTicks(); |
0 | 3036 } |
3037 /* Do the same as expire time for fading */ | |
3038 if(ALmixer_Channel_List[channel].fade_enabled) | |
3039 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3040 ALmixer_Channel_List[channel].fade_start_time = ALmixer_GetTicks(); |
0 | 3041 } |
3042 | |
3043 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
3044 if((error = alGetError()) != AL_NO_ERROR) | |
3045 { | |
3046 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3047 alGetString(error) ); |
0 | 3048 retval = -1; |
3049 } | |
3050 } | |
3051 } | |
3052 } | |
3053 /* The user wants to halt all channels */ | |
3054 else | |
3055 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3056 ALint i; |
0 | 3057 for(i=0; i<Number_of_Channels_global; i++) |
3058 { | |
3059 /* only need to process channel if in use */ | |
3060 if(ALmixer_Channel_List[i].channel_in_use) | |
3061 { | |
3062 alGetSourcei( | |
3063 ALmixer_Channel_List[i].alsource, | |
3064 AL_SOURCE_STATE, &state | |
3065 ); | |
3066 if((error = alGetError()) != AL_NO_ERROR) | |
3067 { | |
3068 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
|
3069 alGetString(error)); |
0 | 3070 } |
3071 if(AL_PAUSED == state) | |
3072 { | |
3073 /* Count the actual number of channels resumed */ | |
3074 counter++; | |
3075 | |
3076 /* We need to resume the expire time count down */ | |
3077 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
3078 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3079 ALmixer_Channel_List[i].start_time = ALmixer_GetTicks(); |
0 | 3080 } |
3081 /* Do the same as expire time for fading */ | |
3082 if(ALmixer_Channel_List[i].fade_enabled) | |
3083 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3084 ALmixer_Channel_List[i].fade_start_time = ALmixer_GetTicks(); |
0 | 3085 } |
3086 | |
3087 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
3088 if((error = alGetError()) != AL_NO_ERROR) | |
3089 { | |
3090 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3091 alGetString(error) ); |
0 | 3092 retval = -1; |
3093 } | |
3094 } | |
3095 } | |
3096 } | |
3097 } | |
3098 if(-1 == retval) | |
3099 { | |
3100 return -1; | |
3101 } | |
3102 return counter; | |
3103 } | |
3104 | |
3105 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3106 static ALint Internal_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3107 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3108 ALint channel; |
0 | 3109 if(0 == source) |
3110 { | |
3111 return Internal_ResumeChannel(-1); | |
3112 } | |
3113 | |
3114 channel = Internal_GetChannel(source); | |
3115 if(-1 == channel) | |
3116 { | |
3117 ALmixer_SetError("Cannot resume source: %s", ALmixer_GetError()); | |
3118 return -1; | |
3119 } | |
3120 return Internal_ResumeChannel(channel); | |
3121 } | |
3122 | |
3123 | |
3124 /* Might consider setting eof to 0 as a "feature" | |
3125 * This will allow seek to end to stay there because | |
3126 * Play automatically rewinds if at the end */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3127 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
|
3128 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3129 ALint retval; |
0 | 3130 |
3131 if(NULL == data) | |
3132 { | |
3133 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
|
3134 return AL_FALSE; |
0 | 3135 } |
3136 | |
3137 /* Seek for predecoded files involves moving the chunk pointer around */ | |
3138 if(data->decoded_all) | |
3139 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3140 ALuint byte_position; |
0 | 3141 |
3142 /* OpenAL doesn't seem to like it if I change the buffer | |
3143 * while playing (crashes), so I must require that Seek only | |
3144 * be done when the data is not in use. | |
3145 * Since data may be shared among multiple sources, | |
3146 * I can't shut them down myself, so I have to return an error. | |
3147 */ | |
3148 if(data->in_use) | |
3149 { | |
3150 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
|
3151 return AL_FALSE; |
0 | 3152 } |
3153 #if 0 | |
3154 #if defined(DISABLE_PREDECODED_SEEK) | |
3155 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
|
3156 return AL_FALSE; |
0 | 3157 |
3158 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
3159 /* By default, ALmixer frees the Sound_Sample for predecoded | |
3160 * samples because of the potential memory waste. | |
3161 * However, to seek a sample, we need to have a full | |
3162 * copy of the data around. So the strategy is to | |
3163 * recreate a hackish Sound_Sample to be used for seeking | |
3164 * purposes. If Sound_Sample is NULL, we will reallocate | |
3165 * memory for it and then procede as if everything | |
3166 * was normal. | |
3167 */ | |
3168 if(NULL == data->sample) | |
3169 { | |
3170 if( -1 == Reconstruct_Sound_Sample(data) ) | |
3171 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3172 return AL_FALSE; |
0 | 3173 } |
3174 } | |
3175 #endif | |
3176 #endif | |
3177 /* If access_data was set, then we still have the | |
3178 * Sound_Sample and we can move around in the data. | |
3179 * If it was not set, the data has been freed and we | |
3180 * cannot do anything because there is no way to | |
3181 * recover the data because OpenAL won't let us | |
3182 * get access to the buffers | |
3183 */ | |
3184 if(NULL == data->sample) | |
3185 { | |
3186 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
|
3187 return AL_FALSE; |
0 | 3188 } |
3189 | |
3190 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
|
3191 retval = Set_Predecoded_Seek_Position(data, byte_position); |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3192 if(-1 == retval) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3193 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3194 return AL_FALSE; |
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 else |
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 return AL_TRUE; |
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 |
0 | 3201 } |
3202 else | |
3203 { | |
3204 /* Reset eof flag?? */ | |
3205 data->eof = 0; | |
3206 retval = Sound_Seek(data->sample, msec); | |
3207 if(0 == retval) | |
3208 { | |
3209 ALmixer_SetError(Sound_GetError()); | |
3210 | |
3211 fprintf(stderr, "Sound seek error: %s\n", ALmixer_GetError()); | |
3212 /* Try rewinding to clean up? */ | |
3213 /* | |
3214 Internal_RewindData(data); | |
3215 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3216 return AL_FALSE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3217 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3218 return AL_TRUE; |
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 |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3221 return AL_TRUE; |
0 | 3222 } |
3223 | |
3224 | |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3225 static ALint Internal_SeekChannel(ALint channel, ALuint msec) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3226 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3227 ALint retval = 0; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3228 ALenum error; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3229 ALint state; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3230 ALint running_count = 0; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3231 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3232 if(0 == msec) |
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 return Internal_RewindChannel(channel); |
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 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3237 if(channel >= Number_of_Channels_global) |
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 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
|
3240 return -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3241 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3242 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3243 if((error = alGetError()) != AL_NO_ERROR) |
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 fprintf(stderr, "24Testing error: %s\n", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3246 alGetString(error)); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3247 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3248 /* Clear error */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3249 alGetError(); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3250 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3251 /* If the user specified a specific channel */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3252 if(channel >= 0) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3253 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3254 /* only need to process channel if in use */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3255 if(ALmixer_Channel_List[channel].channel_in_use) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3256 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3257 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3258 /* What should I do? Do I just rewind the channel |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3259 * or also rewind the data? Since the data is |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3260 * shared, let's make it the user's responsibility |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3261 * to rewind the data. |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3262 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3263 if(ALmixer_Channel_List[channel].almixer_data->decoded_all) |
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 /* convert milliseconds to seconds */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3266 ALfloat sec_offset = msec / 1000.0f; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3267 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3268 alGetSourcei( |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3269 ALmixer_Channel_List[channel].alsource, |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3270 AL_SOURCE_STATE, &state |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3271 ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3272 if((error = alGetError()) != AL_NO_ERROR) |
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 fprintf(stderr, "25Testing error: %s\n", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3275 alGetString(error)); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3276 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3277 /* OpenAL seek */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3278 alSourcef(ALmixer_Channel_List[channel].alsource, AL_SEC_OFFSET, sec_offset); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3279 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3280 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3281 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3282 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3283 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3284 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3285 /* Need to resume playback if it was originally playing */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3286 if(AL_PLAYING == state) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3287 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3288 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3289 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3290 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3291 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3292 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3293 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3294 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3295 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3296 else if(AL_PAUSED == state) |
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 /* HACK: The problem is that when paused, after |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3299 * the Rewind, I can't get it off the INITIAL |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3300 * state without restarting |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3301 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3302 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3303 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3304 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3305 fprintf(stderr, "25Testing error: %s\n", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3306 alGetString(error)); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3307 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3308 alSourcePause(ALmixer_Channel_List[channel].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3309 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3310 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3311 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3312 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3313 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3314 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3315 } |
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 else |
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 /* Streamed data is different. Rewinding the channel |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3320 * does no good. Rewinding the data will have an |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3321 * effect, but it will be lagged based on how |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3322 * much data is queued. Recommend users call Halt |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3323 * before rewind if they want immediate results. |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3324 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3325 retval = Internal_SeekData(ALmixer_Channel_List[channel].almixer_data, msec); |
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 } |
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 /* The user wants to rewind all channels */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3330 else |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3331 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3332 ALint i; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3333 ALfloat sec_offset = msec / 1000.0f; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3334 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3335 for(i=0; i<Number_of_Channels_global; i++) |
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 /* only need to process channel if in use */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3338 if(ALmixer_Channel_List[i].channel_in_use) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3339 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3340 /* What should I do? Do I just rewind the channel |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3341 * or also rewind the data? Since the data is |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3342 * shared, let's make it the user's responsibility |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3343 * to rewind the data. |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3344 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3345 if(ALmixer_Channel_List[i].almixer_data->decoded_all) |
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 alGetSourcei( |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3348 ALmixer_Channel_List[i].alsource, |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3349 AL_SOURCE_STATE, &state |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3350 ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3351 if((error = alGetError()) != AL_NO_ERROR) |
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 fprintf(stderr, "26Testing error: %s\n", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3354 alGetString(error)); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3355 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3356 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3357 alSourcef(ALmixer_Channel_List[channel].alsource, AL_SEC_OFFSET, sec_offset); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3358 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3359 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3360 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3361 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3362 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3363 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3364 /* Need to resume playback if it was originally playing */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3365 if(AL_PLAYING == state) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3366 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3367 alSourcePlay(ALmixer_Channel_List[i].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3368 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3369 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3370 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3371 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3372 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3373 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3374 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3375 else if(AL_PAUSED == state) |
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 /* HACK: The problem is that when paused, after |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3378 * the Rewind, I can't get it off the INITIAL |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3379 * state without restarting |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3380 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3381 alSourcePlay(ALmixer_Channel_List[i].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3382 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3383 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3384 fprintf(stderr, "27Testing error: %s\n", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3385 alGetString(error)); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3386 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3387 alSourcePause(ALmixer_Channel_List[i].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3388 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3389 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3390 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3391 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3392 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3393 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3394 } |
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 else |
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 /* Streamed data is different. Rewinding the channel |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3399 * does no good. Rewinding the data will have an |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3400 * effect, but it will be lagged based on how |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3401 * much data is queued. Recommend users call Halt |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3402 * before rewind if they want immediate results. |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3403 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3404 running_count += Internal_SeekData(ALmixer_Channel_List[i].almixer_data, msec); |
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 } |
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 if(-1 == retval) |
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 return -1; |
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 else |
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 return running_count; |
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 |
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 static ALint Internal_SeekSource(ALuint source, ALuint msec) |
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 ALint channel; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3423 if(0 == source) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3424 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3425 return Internal_SeekChannel(-1, msec); |
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 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3428 channel = Internal_GetChannel(source); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3429 if(-1 == channel) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3430 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3431 ALmixer_SetError("Cannot seek source: %s", ALmixer_GetError()); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3432 return 0; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3433 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3434 return Internal_SeekChannel(channel, msec); |
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 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3437 |
0 | 3438 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3439 static ALint Internal_FadeInChannelTimed(ALint channel, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 3440 { |
3441 ALfloat value; | |
3442 ALenum error; | |
3443 ALfloat original_value; | |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
3444 /* ALuint current_time = ALmixer_GetTicks(); */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3445 ALint retval; |
0 | 3446 |
3447 | |
3448 | |
3449 if(channel >= Number_of_Channels_global) | |
3450 { | |
3451 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); | |
3452 return -1; | |
3453 } | |
3454 /* Let's call PlayChannelTimed to do the job. | |
3455 * There are two catches: | |
3456 * First is that we must set the volumes before the play call(s). | |
3457 * Second is that we must initialize the channel values | |
3458 */ | |
3459 | |
3460 if(channel < 0) | |
3461 { | |
3462 /* This might cause a problem for threads/race conditions. | |
3463 * We need to set the volume on an unknown channel, | |
3464 * so we need to request a channel first. Remember | |
3465 * that requesting a channel doesn't lock and it | |
3466 * could be surrendered to somebody else before we claim it. | |
3467 */ | |
3468 channel = Internal_GetChannel(0); | |
3469 if(-1 == channel) | |
3470 { | |
3471 return -1; | |
3472 } | |
3473 } | |
3474 else if(ALmixer_Channel_List[channel].channel_in_use) | |
3475 { | |
3476 ALmixer_SetError("Channel %d is already in use", channel); | |
3477 return -1; | |
3478 } | |
3479 | |
3480 | |
3481 /* Get the original volume in case of a problem */ | |
3482 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
|
3483 AL_GAIN, &original_value); |
0 | 3484 |
3485 if((error = alGetError()) != AL_NO_ERROR) | |
3486 { | |
3487 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
|
3488 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3489 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3490 ALmixer_Channel_List[channel].fade_end_volume = original_value; |
0 | 3491 |
3492 /* Get the Min volume */ | |
3493 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3494 AL_MIN_GAIN, &value); | |
3495 if((error = alGetError()) != AL_NO_ERROR) | |
3496 { | |
3497 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
|
3498 alGetString(error)); |
0 | 3499 } |
3500 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3501 | |
3502 /* Set the actual volume */ | |
3503 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
|
3504 AL_GAIN, value); |
0 | 3505 if((error = alGetError()) != AL_NO_ERROR) |
3506 { | |
3507 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
|
3508 alGetString(error)); |
0 | 3509 } |
3510 | |
3511 | |
3512 /* Now call PlayChannelTimed */ | |
3513 retval = Internal_PlayChannelTimed(channel, data, loops, expire_ticks); | |
3514 if(-1 == retval) | |
3515 { | |
3516 /* Chance of failure is actually pretty high since | |
3517 * a channel might already be in use or streamed | |
3518 * data can be shared | |
3519 */ | |
3520 /* Restore the original value to avoid accidental | |
3521 * distruption of playback | |
3522 */ | |
3523 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
|
3524 AL_GAIN, original_value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3525 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3526 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3527 fprintf(stderr, "38Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3528 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3529 } |
0 | 3530 return retval; |
3531 } | |
3532 | |
3533 /* We can't accept 0 as a value because of div-by-zero. | |
3534 * If zero, just call PlayChannelTimed at normal | |
3535 * volume | |
3536 */ | |
3537 if(0 == fade_ticks) | |
3538 { | |
3539 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
|
3540 AL_GAIN, |
0 | 3541 ALmixer_Channel_List[channel].fade_end_volume |
3542 ); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3543 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3544 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3545 fprintf(stderr, "39Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3546 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3547 } |
0 | 3548 |
3549 return retval; | |
3550 } | |
3551 | |
3552 /* Enable fading effects via the flag */ | |
3553 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3554 /* Set fade start time */ | |
3555 ALmixer_Channel_List[channel].fade_start_time | |
3556 = ALmixer_Channel_List[channel].start_time; | |
3557 /* Set the fade expire ticks */ | |
3558 ALmixer_Channel_List[channel].fade_expire_ticks = fade_ticks; | |
3559 | |
3560 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3561 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / fade_ticks; | |
3562 | |
3563 return retval; | |
3564 | |
3565 } | |
3566 | |
3567 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3568 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
|
3569 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3570 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3571 ALint retval; |
0 | 3572 if(0 == source) |
3573 { | |
3574 retval = Internal_FadeInChannelTimed(-1, data, loops, fade_ticks, expire_ticks); | |
3575 if(-1 == retval) | |
3576 { | |
3577 return 0; | |
3578 } | |
3579 else | |
3580 { | |
3581 return Internal_GetSource(retval); | |
3582 } | |
3583 } | |
3584 | |
3585 channel = Internal_GetChannel(source); | |
3586 if(-1 == channel) | |
3587 { | |
3588 ALmixer_SetError("Cannot FadeIn source: %s", ALmixer_GetError()); | |
3589 return 0; | |
3590 } | |
3591 retval = Internal_FadeInChannelTimed(channel, data, loops, fade_ticks, expire_ticks); | |
3592 if(-1 == retval) | |
3593 { | |
3594 return 0; | |
3595 } | |
3596 else | |
3597 { | |
3598 return source; | |
3599 } | |
3600 /* make compiler happy */ | |
3601 return 0; | |
3602 } | |
3603 | |
3604 | |
3605 | |
3606 | |
3607 /* Will fade out currently playing channels. | |
3608 * 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
|
3609 static ALint Internal_FadeOutChannel(ALint channel, ALuint ticks) |
0 | 3610 { |
3611 ALfloat value; | |
3612 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3613 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3614 ALuint counter = 0; |
0 | 3615 |
3616 /* We can't accept 0 as a value because of div-by-zero. | |
3617 * If zero, just call Halt at normal | |
3618 * volume | |
3619 */ | |
3620 if(0 == ticks) | |
3621 { | |
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
|
3622 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 3623 } |
3624 | |
3625 | |
3626 if(channel >= Number_of_Channels_global) | |
3627 { | |
3628 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); | |
3629 return -1; | |
3630 } | |
3631 | |
3632 if(channel >= 0) | |
3633 { | |
3634 if(ALmixer_Channel_List[channel].channel_in_use) | |
3635 { | |
3636 /* Get the current volume */ | |
3637 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
|
3638 AL_GAIN, &value); |
0 | 3639 ALmixer_Channel_List[channel].fade_start_volume = value; |
3640 if((error = alGetError()) != AL_NO_ERROR) | |
3641 { | |
3642 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
|
3643 alGetString(error)); |
0 | 3644 } |
3645 | |
3646 /* Get the Min volume */ | |
3647 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3648 AL_MIN_GAIN, &value); | |
3649 if((error = alGetError()) != AL_NO_ERROR) | |
3650 { | |
3651 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
|
3652 alGetString(error)); |
0 | 3653 } |
3654 ALmixer_Channel_List[channel].fade_end_volume = value; | |
3655 | |
3656 /* Set expire start time */ | |
3657 ALmixer_Channel_List[channel].start_time = current_time; | |
3658 /* Set the expire ticks */ | |
3659 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
3660 /* Set fade start time */ | |
3661 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3662 /* Set the fade expire ticks */ | |
3663 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3664 /* Enable fading effects via the flag */ | |
3665 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3666 | |
3667 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3668 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3669 | |
3670 counter++; | |
3671 } | |
3672 } | |
3673 /* Else need to fade out all channels */ | |
3674 else | |
3675 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3676 ALint i; |
0 | 3677 for(i=0; i<Number_of_Channels_global; i++) |
3678 { | |
3679 if(ALmixer_Channel_List[i].channel_in_use) | |
3680 { | |
3681 /* Get the current volume */ | |
3682 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
|
3683 AL_GAIN, &value); |
0 | 3684 ALmixer_Channel_List[i].fade_start_volume = value; |
3685 if((error = alGetError()) != AL_NO_ERROR) | |
3686 { | |
3687 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
|
3688 alGetString(error)); |
0 | 3689 } |
3690 | |
3691 /* Get the Min volume */ | |
3692 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
3693 AL_MIN_GAIN, &value); | |
3694 if((error = alGetError()) != AL_NO_ERROR) | |
3695 { | |
3696 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
|
3697 alGetString(error)); |
0 | 3698 } |
3699 ALmixer_Channel_List[i].fade_end_volume = value; | |
3700 | |
3701 /* Set expire start time */ | |
3702 ALmixer_Channel_List[i].start_time = current_time; | |
3703 /* Set the expire ticks */ | |
3704 ALmixer_Channel_List[i].expire_ticks = ticks; | |
3705 /* Set fade start time */ | |
3706 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3707 /* Set the fade expire ticks */ | |
3708 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3709 /* Enable fading effects via the flag */ | |
3710 ALmixer_Channel_List[i].fade_enabled = 1; | |
3711 | |
3712 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3713 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3714 | |
3715 counter++; | |
3716 } | |
3717 } /* End for loop */ | |
3718 } | |
3719 return counter; | |
3720 } | |
3721 | |
3722 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3723 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
|
3724 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3725 ALint channel; |
0 | 3726 if(0 == source) |
3727 { | |
3728 return Internal_FadeOutChannel(-1, ticks); | |
3729 } | |
3730 | |
3731 channel = Internal_GetChannel(source); | |
3732 if(-1 == channel) | |
3733 { | |
3734 ALmixer_SetError("Cannot FadeOut source: %s", ALmixer_GetError()); | |
3735 return -1; | |
3736 } | |
3737 return Internal_FadeOutChannel(channel, ticks); | |
3738 } | |
3739 | |
3740 | |
3741 /* Will fade currently playing channels. | |
3742 * It starts at the current volume level and go to target | |
3743 * Only affects channels that are playing | |
3744 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3745 static ALint Internal_FadeChannel(ALint channel, ALuint ticks, ALfloat volume) |
0 | 3746 { |
3747 ALfloat value; | |
3748 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3749 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3750 ALuint counter = 0; |
0 | 3751 |
3752 if(channel >= Number_of_Channels_global) | |
3753 { | |
3754 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); | |
3755 return -1; | |
3756 } | |
3757 | |
3758 if(channel >= 0) | |
3759 { | |
3760 if(volume < ALmixer_Channel_List[channel].min_volume) | |
3761 { | |
3762 volume = ALmixer_Channel_List[channel].min_volume; | |
3763 } | |
3764 else if(volume > ALmixer_Channel_List[channel].max_volume) | |
3765 { | |
3766 volume = ALmixer_Channel_List[channel].max_volume; | |
3767 } | |
3768 | |
3769 if(ALmixer_Channel_List[channel].channel_in_use) | |
3770 { | |
3771 if(ticks > 0) | |
3772 { | |
3773 /* Get the current volume */ | |
3774 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
|
3775 AL_GAIN, &value); |
0 | 3776 if((error = alGetError()) != AL_NO_ERROR) |
3777 { | |
3778 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
|
3779 alGetString(error)); |
0 | 3780 } |
3781 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3782 | |
3783 /* Set the target volume */ | |
3784 ALmixer_Channel_List[channel].fade_end_volume = volume; | |
3785 | |
3786 /* Set fade start time */ | |
3787 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3788 /* Set the fade expire ticks */ | |
3789 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3790 /* Enable fading effects via the flag */ | |
3791 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3792 | |
3793 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3794 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3795 } | |
3796 else | |
3797 { | |
3798 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
|
3799 AL_GAIN, volume); |
0 | 3800 if((error = alGetError()) != AL_NO_ERROR) |
3801 { | |
3802 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
|
3803 alGetString(error)); |
0 | 3804 } |
3805 } | |
3806 counter++; | |
3807 } | |
3808 } | |
3809 /* Else need to fade out all channels */ | |
3810 else | |
3811 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3812 ALint i; |
0 | 3813 for(i=0; i<Number_of_Channels_global; i++) |
3814 { | |
3815 if(volume < ALmixer_Channel_List[i].min_volume) | |
3816 { | |
3817 volume = ALmixer_Channel_List[i].min_volume; | |
3818 } | |
3819 else if(volume > ALmixer_Channel_List[i].max_volume) | |
3820 { | |
3821 volume = ALmixer_Channel_List[i].max_volume; | |
3822 } | |
3823 | |
3824 if(ALmixer_Channel_List[i].channel_in_use) | |
3825 { | |
3826 if(ticks > 0) | |
3827 { | |
3828 /* Get the current volume */ | |
3829 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
|
3830 AL_GAIN, &value); |
0 | 3831 if((error = alGetError()) != AL_NO_ERROR) |
3832 { | |
3833 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
|
3834 alGetString(error)); |
0 | 3835 } |
3836 ALmixer_Channel_List[i].fade_start_volume = value; | |
3837 | |
3838 /* Set target volume */ | |
3839 ALmixer_Channel_List[i].fade_end_volume = volume; | |
3840 | |
3841 /* Set fade start time */ | |
3842 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3843 /* Set the fade expire ticks */ | |
3844 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3845 /* Enable fading effects via the flag */ | |
3846 ALmixer_Channel_List[i].fade_enabled = 1; | |
3847 | |
3848 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3849 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3850 } | |
3851 else | |
3852 { | |
3853 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
|
3854 AL_GAIN, volume); |
0 | 3855 if((error = alGetError()) != AL_NO_ERROR) |
3856 { | |
3857 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
|
3858 alGetString(error)); |
0 | 3859 } |
3860 } | |
3861 counter++; | |
3862 } | |
3863 } /* End for loop */ | |
3864 } | |
3865 return counter; | |
3866 } | |
3867 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3868 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
|
3869 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3870 ALint channel; |
0 | 3871 if(0 == source) |
3872 { | |
3873 return Internal_FadeChannel(-1, ticks, volume); | |
3874 } | |
3875 | |
3876 channel = Internal_GetChannel(source); | |
3877 if(-1 == channel) | |
3878 { | |
3879 ALmixer_SetError("Cannot Fade source: %s", ALmixer_GetError()); | |
3880 return -1; | |
3881 } | |
3882 return Internal_FadeChannel(channel, ticks, volume); | |
3883 } | |
3884 | |
3885 | |
3886 | |
3887 | |
3888 /* Set a volume regardless if it's in use or not. | |
3889 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3890 static ALboolean Internal_SetVolumeChannel(ALint channel, ALfloat volume) |
0 | 3891 { |
3892 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3893 ALboolean retval = AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3894 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3895 if(channel >= Number_of_Channels_global) |
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 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
|
3898 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3899 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3900 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3901 if(channel >= 0) |
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(volume < 0.0f) |
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 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 else if(volume > 1.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 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 alSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3912 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3913 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3914 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3915 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3916 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3917 retval = AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3918 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3919 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3920 else |
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 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3923 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
|
3924 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3925 if(volume < 0.0f) |
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 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 else if(volume > 1.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 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 alSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3934 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3935 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3936 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3937 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3938 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3939 retval = AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3940 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3941 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3942 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3943 return retval; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3946 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
|
3947 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3948 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3949 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3950 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3951 return Internal_SetVolumeChannel(-1, volume); |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3954 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3955 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3956 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3957 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
|
3958 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3959 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3960 return Internal_SetVolumeChannel(channel, volume); |
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 |
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 static ALfloat Internal_GetVolumeChannel(ALint channel) |
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 ALfloat value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3967 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3968 ALfloat running_total = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3969 ALfloat retval = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3970 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3971 if(channel >= Number_of_Channels_global) |
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 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
|
3974 return -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3975 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3976 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3977 if(channel >= 0) |
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 alGetSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3980 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3981 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3982 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3983 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3984 retval = -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3985 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3986 else |
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 retval = value; |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3991 else |
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 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3994 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
|
3995 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3996 alGetSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3997 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3998 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3999 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4000 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4001 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4002 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4003 else |
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 running_total += value; |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4008 if(0 == Number_of_Channels_global) |
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 ALmixer_SetError("No channels are allocated"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4011 retval = -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4012 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4013 else |
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 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
|
4016 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4017 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4018 return retval; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4021 static ALfloat Internal_GetVolumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4022 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4023 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4024 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4025 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4026 return Internal_GetVolumeChannel(-1); |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4029 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4030 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4031 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4032 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
|
4033 return -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4034 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4035 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4036 return Internal_GetVolumeChannel(channel); |
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 |
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 /* 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
|
4042 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4043 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
|
4044 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4045 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4046 ALboolean retval = AL_TRUE; |
0 | 4047 |
4048 if(channel >= Number_of_Channels_global) | |
4049 { | |
4050 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
|
4051 return AL_FALSE; |
0 | 4052 } |
4053 | |
4054 if(channel >= 0) | |
4055 { | |
4056 if(volume < 0.0f) | |
4057 { | |
4058 volume = 0.0f; | |
4059 } | |
4060 else if(volume > 1.0f) | |
4061 { | |
4062 volume = 1.0f; | |
4063 } | |
4064 ALmixer_Channel_List[channel].max_volume = volume; | |
4065 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4066 AL_MAX_GAIN, volume); | |
4067 if((error = alGetError()) != AL_NO_ERROR) | |
4068 { | |
4069 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4070 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4071 retval = AL_FALSE; |
0 | 4072 } |
4073 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
4074 { | |
4075 ALmixer_Channel_List[channel].min_volume = volume; | |
4076 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4077 AL_MIN_GAIN, volume); | |
4078 if((error = alGetError()) != AL_NO_ERROR) | |
4079 { | |
4080 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4081 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4082 retval = AL_FALSE; |
0 | 4083 } |
4084 } | |
4085 } | |
4086 else | |
4087 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4088 ALint i; |
0 | 4089 for(i=0; i<Number_of_Channels_global; i++) |
4090 { | |
4091 if(volume < 0.0f) | |
4092 { | |
4093 volume = 0.0f; | |
4094 } | |
4095 else if(volume > 1.0f) | |
4096 { | |
4097 volume = 1.0f; | |
4098 } | |
4099 ALmixer_Channel_List[i].max_volume = volume; | |
4100 alSourcef(ALmixer_Channel_List[i].alsource, | |
4101 AL_MAX_GAIN, volume); | |
4102 if((error = alGetError()) != AL_NO_ERROR) | |
4103 { | |
4104 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4105 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4106 retval = AL_FALSE; |
0 | 4107 } |
4108 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
4109 { | |
4110 ALmixer_Channel_List[i].min_volume = volume; | |
4111 alSourcef(ALmixer_Channel_List[i].alsource, | |
4112 AL_MIN_GAIN, volume); | |
4113 if((error = alGetError()) != AL_NO_ERROR) | |
4114 { | |
4115 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4116 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4117 retval = AL_FALSE; |
0 | 4118 } |
4119 } | |
4120 } | |
4121 } | |
4122 return retval; | |
4123 } | |
4124 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4125 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
|
4126 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4127 ALint channel; |
0 | 4128 if(0 == source) |
4129 { | |
4130 return Internal_SetMaxVolumeChannel(-1, volume); | |
4131 } | |
4132 | |
4133 channel = Internal_GetChannel(source); | |
4134 if(-1 == channel) | |
4135 { | |
4136 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
|
4137 return AL_FALSE; |
0 | 4138 } |
4139 return Internal_SetMaxVolumeChannel(channel, volume); | |
4140 } | |
4141 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4142 static ALfloat Internal_GetMaxVolumeChannel(ALint channel) |
0 | 4143 { |
4144 /* | |
4145 ALfloat value; | |
4146 ALenum error; | |
4147 */ | |
4148 ALfloat running_total = 0.0f; | |
4149 ALfloat retval = 0.0f; | |
4150 | |
4151 if(channel >= Number_of_Channels_global) | |
4152 { | |
4153 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); | |
4154 return -1.0f; | |
4155 } | |
4156 | |
4157 if(channel >= 0) | |
4158 { | |
4159 /* | |
4160 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
4161 AL_GAIN, &value); | |
4162 if((error = alGetError()) != AL_NO_ERROR) | |
4163 { | |
4164 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4165 alGetString(error) ); |
0 | 4166 retval = -1.0f; |
4167 } | |
4168 else | |
4169 { | |
4170 retval = value; | |
4171 } | |
4172 */ | |
4173 retval = ALmixer_Channel_List[channel].max_volume; | |
4174 | |
4175 } | |
4176 else | |
4177 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4178 ALint i; |
0 | 4179 for(i=0; i<Number_of_Channels_global; i++) |
4180 { | |
4181 /* | |
4182 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
4183 AL_GAIN, &value); | |
4184 if((error = alGetError()) != AL_NO_ERROR) | |
4185 { | |
4186 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4187 alGetString(error) ); |
0 | 4188 retval = -1; |
4189 } | |
4190 else | |
4191 { | |
4192 running_total += value; | |
4193 } | |
4194 */ | |
4195 running_total += ALmixer_Channel_List[i].max_volume; | |
4196 } | |
4197 if(0 == Number_of_Channels_global) | |
4198 { | |
4199 ALmixer_SetError("No channels are allocated"); | |
4200 retval = -1.0f; | |
4201 } | |
4202 else | |
4203 { | |
4204 retval = running_total / Number_of_Channels_global; | |
4205 } | |
4206 } | |
4207 return retval; | |
4208 } | |
4209 | |
4210 static ALfloat Internal_GetMaxVolumeSource(ALuint source) | |
4211 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4212 ALint channel; |
0 | 4213 if(0 == source) |
4214 { | |
4215 return Internal_GetMaxVolumeChannel(-1); | |
4216 } | |
4217 | |
4218 channel = Internal_GetChannel(source); | |
4219 if(-1 == channel) | |
4220 { | |
4221 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
4222 return -1.0f; | |
4223 } | |
4224 | |
4225 return Internal_GetMaxVolumeChannel(channel); | |
4226 } | |
4227 | |
4228 | |
4229 /* Set a volume regardless if it's in use or not. | |
4230 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4231 static ALboolean Internal_SetMinVolumeChannel(ALint channel, ALfloat volume) |
0 | 4232 { |
4233 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4234 ALboolean retval = AL_TRUE; |
0 | 4235 |
4236 if(channel >= Number_of_Channels_global) | |
4237 { | |
4238 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
|
4239 return AL_FALSE; |
0 | 4240 } |
4241 | |
4242 if(channel >= 0) | |
4243 { | |
4244 if(volume < 0.0f) | |
4245 { | |
4246 volume = 0.0f; | |
4247 } | |
4248 else if(volume > 1.0f) | |
4249 { | |
4250 volume = 1.0f; | |
4251 } | |
4252 ALmixer_Channel_List[channel].min_volume = volume; | |
4253 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4254 AL_MIN_GAIN, volume); | |
4255 if((error = alGetError()) != AL_NO_ERROR) | |
4256 { | |
4257 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4258 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4259 retval = AL_FALSE; |
0 | 4260 } |
4261 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
4262 { | |
4263 ALmixer_Channel_List[channel].max_volume = volume; | |
4264 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4265 AL_MAX_GAIN, volume); | |
4266 if((error = alGetError()) != AL_NO_ERROR) | |
4267 { | |
4268 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4269 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4270 retval = AL_FALSE; |
0 | 4271 } |
4272 } | |
4273 } | |
4274 else | |
4275 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4276 ALint i; |
0 | 4277 for(i=0; i<Number_of_Channels_global; i++) |
4278 { | |
4279 if(volume < 0.0f) | |
4280 { | |
4281 volume = 0.0f; | |
4282 } | |
4283 else if(volume > 1.0f) | |
4284 { | |
4285 volume = 1.0f; | |
4286 } | |
4287 ALmixer_Channel_List[i].min_volume = volume; | |
4288 alSourcef(ALmixer_Channel_List[i].alsource, | |
4289 AL_MIN_GAIN, volume); | |
4290 if((error = alGetError()) != AL_NO_ERROR) | |
4291 { | |
4292 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4293 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4294 retval = AL_FALSE; |
0 | 4295 } |
4296 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
4297 { | |
4298 ALmixer_Channel_List[i].max_volume = volume; | |
4299 alSourcef(ALmixer_Channel_List[i].alsource, | |
4300 AL_MAX_GAIN, volume); | |
4301 if((error = alGetError()) != AL_NO_ERROR) | |
4302 { | |
4303 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4304 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4305 retval = AL_FALSE; |
0 | 4306 } |
4307 } | |
4308 } | |
4309 } | |
4310 return retval; | |
4311 } | |
4312 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4313 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
|
4314 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4315 ALint channel; |
0 | 4316 if(0 == source) |
4317 { | |
4318 return Internal_SetMinVolumeChannel(-1, volume); | |
4319 } | |
4320 | |
4321 channel = Internal_GetChannel(source); | |
4322 if(-1 == channel) | |
4323 { | |
4324 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
|
4325 return AL_FALSE; |
0 | 4326 } |
4327 return Internal_SetMinVolumeChannel(channel, volume); | |
4328 } | |
4329 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4330 static ALfloat Internal_GetMinVolumeChannel(ALint channel) |
0 | 4331 { |
4332 /* | |
4333 ALfloat value; | |
4334 ALenum error; | |
4335 */ | |
4336 ALfloat running_total = 0.0f; | |
4337 ALfloat retval = 0.0f; | |
4338 | |
4339 if(channel >= Number_of_Channels_global) | |
4340 { | |
4341 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); | |
4342 return -1.0f; | |
4343 } | |
4344 | |
4345 if(channel >= 0) | |
4346 { | |
4347 /* | |
4348 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
4349 AL_GAIN, &value); | |
4350 if((error = alGetError()) != AL_NO_ERROR) | |
4351 { | |
4352 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4353 alGetString(error) ); |
0 | 4354 retval = -1.0f; |
4355 } | |
4356 else | |
4357 { | |
4358 retval = value; | |
4359 } | |
4360 */ | |
4361 retval = ALmixer_Channel_List[channel].min_volume; | |
4362 | |
4363 } | |
4364 else | |
4365 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4366 ALint i; |
0 | 4367 for(i=0; i<Number_of_Channels_global; i++) |
4368 { | |
4369 /* | |
4370 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
4371 AL_GAIN, &value); | |
4372 if((error = alGetError()) != AL_NO_ERROR) | |
4373 { | |
4374 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4375 alGetString(error) ); |
0 | 4376 retval = -1; |
4377 } | |
4378 else | |
4379 { | |
4380 running_total += value; | |
4381 } | |
4382 */ | |
4383 running_total += ALmixer_Channel_List[i].min_volume; | |
4384 } | |
4385 if(0 == Number_of_Channels_global) | |
4386 { | |
4387 ALmixer_SetError("No channels are allocated"); | |
4388 retval = -1.0f; | |
4389 } | |
4390 else | |
4391 { | |
4392 retval = running_total / Number_of_Channels_global; | |
4393 } | |
4394 } | |
4395 return retval; | |
4396 } | |
4397 | |
4398 static ALfloat Internal_GetMinVolumeSource(ALuint source) | |
4399 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4400 ALint channel; |
0 | 4401 if(0 == source) |
4402 { | |
4403 return Internal_GetMinVolumeChannel(-1); | |
4404 } | |
4405 | |
4406 channel = Internal_GetChannel(source); | |
4407 if(-1 == channel) | |
4408 { | |
4409 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
4410 return -1.0f; | |
4411 } | |
4412 | |
4413 return Internal_GetMinVolumeChannel(channel); | |
4414 } | |
4415 | |
4416 | |
4417 /* Changes the listener volume */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4418 static ALboolean Internal_SetMasterVolume(ALfloat volume) |
0 | 4419 { |
4420 ALenum error; | |
4421 alListenerf(AL_GAIN, volume); | |
4422 if((error = alGetError()) != AL_NO_ERROR) | |
4423 { | |
4424 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4425 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4426 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4427 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4428 return AL_TRUE; |
0 | 4429 } |
4430 | |
4431 static ALfloat Internal_GetMasterVolume() | |
4432 { | |
4433 ALenum error; | |
4434 ALfloat volume; | |
4435 alGetListenerf(AL_GAIN, &volume); | |
4436 if((error = alGetError()) != AL_NO_ERROR) | |
4437 { | |
4438 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4439 alGetString(error) ); |
0 | 4440 return -1.0f; |
4441 } | |
4442 return volume; | |
4443 } | |
4444 | |
4445 | |
4446 | |
4447 | |
4448 /* Will fade out currently playing channels. | |
4449 * 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
|
4450 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
|
4451 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4452 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4453 ALuint counter = 0; |
0 | 4454 |
4455 /* We can't accept 0 as a value because of div-by-zero. | |
4456 * If zero, just call Halt at normal | |
4457 * volume | |
4458 */ | |
4459 if(0 == ticks) | |
4460 { | |
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
|
4461 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 4462 } |
4463 if(ticks < -1) | |
4464 { | |
4465 ticks = -1; | |
4466 } | |
4467 | |
4468 | |
4469 if(channel >= Number_of_Channels_global) | |
4470 { | |
4471 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); | |
4472 return -1; | |
4473 } | |
4474 | |
4475 if(channel >= 0) | |
4476 { | |
4477 if(ALmixer_Channel_List[channel].channel_in_use) | |
4478 { | |
4479 /* Set expire start time */ | |
4480 ALmixer_Channel_List[channel].start_time = current_time; | |
4481 /* Set the expire ticks */ | |
4482 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
4483 | |
4484 counter++; | |
4485 } | |
4486 } | |
4487 /* Else need to fade out all channels */ | |
4488 else | |
4489 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4490 ALint i; |
0 | 4491 for(i=0; i<Number_of_Channels_global; i++) |
4492 { | |
4493 if(ALmixer_Channel_List[i].channel_in_use) | |
4494 { | |
4495 /* Set expire start time */ | |
4496 ALmixer_Channel_List[i].start_time = current_time; | |
4497 /* Set the expire ticks */ | |
4498 ALmixer_Channel_List[i].expire_ticks = ticks; | |
4499 | |
4500 counter++; | |
4501 } | |
4502 } /* End for loop */ | |
4503 } | |
4504 return counter; | |
4505 } | |
4506 | |
4507 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4508 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
|
4509 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4510 ALint channel; |
0 | 4511 if(0 == source) |
4512 { | |
4513 return Internal_ExpireChannel(-1, ticks); | |
4514 } | |
4515 | |
4516 channel = Internal_GetChannel(source); | |
4517 if(-1 == channel) | |
4518 { | |
4519 ALmixer_SetError("Cannot Expire source: %s", ALmixer_GetError()); | |
4520 return -1; | |
4521 } | |
4522 return Internal_ExpireChannel(channel, ticks); | |
4523 } | |
4524 | |
4525 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4526 static ALint Internal_QueryChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4527 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4528 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4529 ALint counter = 0; |
0 | 4530 if(channel >= Number_of_Channels_global) |
4531 { | |
4532 ALmixer_SetError("Invalid channel: %d", channel); | |
4533 return -1; | |
4534 } | |
4535 | |
4536 if(channel >= 0) | |
4537 { | |
4538 return ALmixer_Channel_List[channel].channel_in_use; | |
4539 } | |
4540 | |
4541 /* Else, return the number of channels in use */ | |
4542 for(i=0; i<Number_of_Channels_global; i++) | |
4543 { | |
4544 if(ALmixer_Channel_List[i].channel_in_use) | |
4545 { | |
4546 counter++; | |
4547 } | |
4548 } | |
4549 return counter; | |
4550 } | |
4551 | |
4552 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4553 static ALint Internal_QuerySource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4554 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4555 ALint channel; |
0 | 4556 if(0 == source) |
4557 { | |
4558 return Internal_QueryChannel(-1); | |
4559 } | |
4560 | |
4561 channel = Internal_GetChannel(source); | |
4562 if(-1 == channel) | |
4563 { | |
4564 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4565 return -1; | |
4566 } | |
4567 | |
4568 return Internal_QueryChannel(channel); | |
4569 } | |
4570 | |
4571 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4572 static ALuint Internal_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4573 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4574 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4575 ALuint counter = 0; |
0 | 4576 |
4577 | |
4578 /* Else, return the number of channels in use */ | |
4579 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4580 { | |
4581 if(ALmixer_Channel_List[i].channel_in_use) | |
4582 { | |
4583 counter++; | |
4584 } | |
4585 } | |
4586 return counter; | |
4587 } | |
4588 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4589 static ALuint Internal_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4590 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4591 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4592 ALuint counter = 0; |
0 | 4593 |
4594 | |
4595 /* Else, return the number of channels in use */ | |
4596 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4597 { | |
4598 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4599 { | |
4600 counter++; | |
4601 } | |
4602 } | |
4603 return counter; | |
4604 } | |
4605 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4606 static ALuint Internal_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4607 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4608 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4609 ALuint counter = 0; |
0 | 4610 |
4611 | |
4612 /* Else, return the number of channels in use */ | |
4613 for(i=0; i<Number_of_Channels_global; i++) | |
4614 { | |
4615 if(ALmixer_Channel_List[i].channel_in_use) | |
4616 { | |
4617 counter++; | |
4618 } | |
4619 } | |
4620 return counter; | |
4621 } | |
4622 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4623 static ALuint Internal_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4624 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4625 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4626 ALuint counter = 0; |
0 | 4627 |
4628 | |
4629 /* Else, return the number of channels in use */ | |
4630 for(i=0; i<Number_of_Channels_global; i++) | |
4631 { | |
4632 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4633 { | |
4634 counter++; | |
4635 } | |
4636 } | |
4637 return counter; | |
4638 } | |
4639 | |
4640 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4641 static ALint Internal_PlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4642 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4643 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4644 ALint counter = 0; |
0 | 4645 ALint state; |
4646 | |
4647 if(channel >= Number_of_Channels_global) | |
4648 { | |
4649 ALmixer_SetError("Invalid channel: %d", channel); | |
4650 return -1; | |
4651 } | |
4652 | |
4653 if(channel >= 0) | |
4654 { | |
4655 if(ALmixer_Channel_List[channel].channel_in_use) | |
4656 { | |
4657 alGetSourcei( | |
4658 ALmixer_Channel_List[channel].alsource, | |
4659 AL_SOURCE_STATE, &state | |
4660 ); | |
4661 if(AL_PLAYING == state) | |
4662 { | |
4663 return 1; | |
4664 } | |
4665 } | |
4666 return 0; | |
4667 } | |
4668 | |
4669 /* Else, return the number of channels in use */ | |
4670 for(i=0; i<Number_of_Channels_global; i++) | |
4671 { | |
4672 if(ALmixer_Channel_List[i].channel_in_use) | |
4673 { | |
4674 alGetSourcei( | |
4675 ALmixer_Channel_List[i].alsource, | |
4676 AL_SOURCE_STATE, &state | |
4677 ); | |
4678 if(AL_PLAYING == state) | |
4679 { | |
4680 counter++; | |
4681 } | |
4682 } | |
4683 } | |
4684 return counter; | |
4685 } | |
4686 | |
4687 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4688 static ALint Internal_PlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4689 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4690 ALint channel; |
0 | 4691 if(0 == source) |
4692 { | |
4693 return Internal_PlayingChannel(-1); | |
4694 } | |
4695 | |
4696 channel = Internal_GetChannel(source); | |
4697 if(-1 == channel) | |
4698 { | |
4699 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4700 return -1; | |
4701 } | |
4702 | |
4703 return Internal_PlayingChannel(channel); | |
4704 } | |
4705 | |
4706 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4707 static ALint Internal_PausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4708 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4709 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4710 ALint counter = 0; |
0 | 4711 ALint state; |
4712 | |
4713 if(channel >= Number_of_Channels_global) | |
4714 { | |
4715 ALmixer_SetError("Invalid channel: %d", channel); | |
4716 return -1; | |
4717 } | |
4718 | |
4719 if(channel >= 0) | |
4720 { | |
4721 if(ALmixer_Channel_List[channel].channel_in_use) | |
4722 { | |
4723 alGetSourcei( | |
4724 ALmixer_Channel_List[channel].alsource, | |
4725 AL_SOURCE_STATE, &state | |
4726 ); | |
4727 if(AL_PAUSED == state) | |
4728 { | |
4729 return 1; | |
4730 } | |
4731 } | |
4732 return 0; | |
4733 } | |
4734 | |
4735 /* Else, return the number of channels in use */ | |
4736 for(i=0; i<Number_of_Channels_global; i++) | |
4737 { | |
4738 if(ALmixer_Channel_List[i].channel_in_use) | |
4739 { | |
4740 alGetSourcei( | |
4741 ALmixer_Channel_List[i].alsource, | |
4742 AL_SOURCE_STATE, &state | |
4743 ); | |
4744 if(AL_PAUSED == state) | |
4745 { | |
4746 counter++; | |
4747 } | |
4748 } | |
4749 } | |
4750 return counter; | |
4751 } | |
4752 | |
4753 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4754 static ALint Internal_PausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4755 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4756 ALint channel; |
0 | 4757 if(0 == source) |
4758 { | |
4759 return Internal_PausedChannel(-1); | |
4760 } | |
4761 | |
4762 channel = Internal_GetChannel(source); | |
4763 if(-1 == channel) | |
4764 { | |
4765 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4766 return -1; | |
4767 } | |
4768 | |
4769 return Internal_PausedChannel(channel); | |
4770 } | |
4771 | |
4772 | |
4773 | |
4774 | |
4775 | |
4776 | |
4777 /* Private function for Updating ALmixer. | |
4778 * This is a very big and ugly function. | |
4779 * It should return the number of buffers that were | |
4780 * queued during the call. The value might be | |
4781 * used to guage how long you might wait to | |
4782 * call the next update loop in case you are worried | |
4783 * about preserving CPU cycles. The idea is that | |
4784 * when a buffer is queued, there was probably some | |
4785 * CPU intensive looping which took awhile. | |
4786 * 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
|
4787 * Timing the call with ALmixer_GetTicks() would produce |
0 | 4788 * more accurate information. |
4789 * Returns a negative value if there was an error, | |
4790 * the value being the number of errors. | |
4791 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4792 static ALint Update_ALmixer(void* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4793 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4794 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4795 ALint error_flag = 0; |
0 | 4796 ALenum error; |
4797 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4798 ALint i=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4799 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4800 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4801 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4802 #endif |
0 | 4803 if(0 == ALmixer_Initialized) |
4804 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4805 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4806 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4807 #endif |
0 | 4808 return 0; |
4809 } | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4810 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4811 /* Bypass if in interruption event */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4812 if(NULL == alcGetCurrentContext()) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4813 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4814 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4815 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4816 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4817 return 0; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4818 } |
0 | 4819 |
4820 /* Check the quick flag to see if anything needs updating */ | |
4821 /* If anything is playing, then we have to do work */ | |
4822 if( 0 == Is_Playing_global) | |
4823 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4824 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4825 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4826 #endif |
0 | 4827 return 0; |
4828 } | |
4829 /* Clear error */ | |
4830 if((error = alGetError()) != AL_NO_ERROR) | |
4831 { | |
4832 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
|
4833 alGetString(error)); |
0 | 4834 } |
4835 alGetError(); | |
4836 | |
4837 for(i=0; i<Number_of_Channels_global; i++) | |
4838 { | |
4839 if( ALmixer_Channel_List[i].channel_in_use ) | |
4840 { | |
4841 | |
4842 /* For simplicity, before we do anything else, | |
4843 * we can check the timeout and fading values | |
4844 * and do the appropriate things | |
4845 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4846 ALuint current_time = ALmixer_GetTicks(); |
0 | 4847 |
4848 /* Check to see if we need to halt due to Timed play */ | |
4849 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
4850 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4851 ALuint target_time = (ALuint)ALmixer_Channel_List[i].expire_ticks |
0 | 4852 + ALmixer_Channel_List[i].start_time; |
4853 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4854 AL_SOURCE_STATE, &state); | |
4855 if((error = alGetError()) != AL_NO_ERROR) | |
4856 { | |
4857 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
|
4858 alGetString(error)); |
0 | 4859 } |
4860 | |
4861 /* Check the time, and also make sure that it is not | |
4862 * paused (if paused, we don't want to make the | |
4863 * evaluation because when resumed, we will adjust | |
4864 * the times to compensate for the pause). | |
4865 */ | |
4866 if( (current_time >= target_time) | |
4867 && (state != AL_PAUSED) ) | |
4868 { | |
4869 /* 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
|
4870 Internal_HaltChannel(i, AL_FALSE); |
0 | 4871 if((error = alGetError()) != AL_NO_ERROR) |
4872 { | |
4873 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
|
4874 alGetString(error)); |
0 | 4875 } |
4876 | |
4877 /* Everything should be done so go on to the next loop */ | |
4878 continue; | |
4879 } | |
4880 } /* End if time expired check */ | |
4881 | |
4882 /* Check to see if we need to adjust the volume for fading */ | |
4883 if( ALmixer_Channel_List[i].fade_enabled ) | |
4884 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4885 ALuint target_time = ALmixer_Channel_List[i].fade_expire_ticks |
0 | 4886 + ALmixer_Channel_List[i].fade_start_time; |
4887 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4888 AL_SOURCE_STATE, &state); | |
4889 if((error = alGetError()) != AL_NO_ERROR) | |
4890 { | |
4891 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
|
4892 alGetString(error)); |
0 | 4893 } |
4894 | |
4895 /* Check the time, and also make sure that it is not | |
4896 * paused (if paused, we don't want to make the | |
4897 * evaluation because when resumed, we will adjust | |
4898 * the times to compensate for the pause). | |
4899 */ | |
4900 if(state != AL_PAUSED) | |
4901 { | |
4902 ALfloat t; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4903 ALuint delta_time; |
0 | 4904 ALfloat current_volume; |
4905 if(current_time >= target_time) | |
4906 { | |
4907 /* Need to constrain value to the end time | |
4908 * (can't go pass the value for calculations) | |
4909 */ | |
4910 current_time = target_time; | |
4911 /* We can disable the fade flag now */ | |
4912 ALmixer_Channel_List[i].fade_enabled = 0; | |
4913 } | |
4914 /* Use the linear interpolation formula: | |
4915 * X = (1-t)x0 + tx1 | |
4916 * where x0 would be the start value | |
4917 * and x1 is the final value | |
4918 * and t is delta_time*inv_time (adjusts 0 <= time <= 1) | |
4919 * delta_time = current_time-start_time | |
4920 * inv_time = 1/ (end_time-start_time) | |
4921 * so t = current_time-start_time / (end_time-start_time) | |
4922 * | |
4923 */ | |
4924 delta_time = current_time - ALmixer_Channel_List[i].fade_start_time; | |
4925 t = (ALfloat) delta_time * ALmixer_Channel_List[i].fade_inv_time; | |
4926 current_volume = (1.0f-t) * ALmixer_Channel_List[i].fade_start_volume | |
4927 + t * ALmixer_Channel_List[i].fade_end_volume; | |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
4928 /* |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
4929 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
|
4930 */ |
0 | 4931 /* Set the volume */ |
4932 alSourcef(ALmixer_Channel_List[i].alsource, | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
4933 AL_GAIN, current_volume); |
0 | 4934 if((error = alGetError()) != AL_NO_ERROR) |
4935 { | |
4936 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
|
4937 alGetString(error)); |
0 | 4938 } |
4939 | |
4940 /* | |
4941 fprintf(stderr, "Current time =%d\n", current_time); | |
4942 fprintf(stderr, "Current vol=%f on channel %d\n", current_volume, i); | |
4943 */ | |
4944 } /* End if not PAUSED */ | |
4945 } /* End if fade_enabled */ | |
4946 | |
4947 | |
4948 /* Okay, now that the time expired and fading stuff | |
4949 * is done, do the rest of the hard stuff | |
4950 */ | |
4951 | |
4952 | |
4953 /* For predecoded, check to see if done */ | |
4954 if( ALmixer_Channel_List[i].almixer_data->decoded_all ) | |
4955 { | |
4956 | |
4957 #if 0 | |
4958 /********* Remove this **********/ | |
4959 ALint buffers_processed; | |
4960 ALint buffers_still_queued; | |
4961 fprintf(stderr, "For Predecoded\n"); | |
4962 | |
4963 alGetSourcei( | |
4964 ALmixer_Channel_List[i].alsource, | |
4965 AL_SOURCE_STATE, &state | |
4966 ); | |
4967 switch(state) { | |
4968 case AL_PLAYING: | |
4969 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
4970 break; | |
4971 case AL_PAUSED: | |
4972 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
4973 break; | |
4974 case AL_STOPPED: | |
4975 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
4976 break; | |
4977 case AL_INITIAL: | |
4978 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
4979 break; | |
4980 default: | |
4981 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
4982 break; | |
4983 } | |
4984 | |
4985 alGetSourcei( | |
4986 ALmixer_Channel_List[i].alsource, | |
4987 AL_BUFFERS_PROCESSED, &buffers_processed | |
4988 ); | |
4989 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
4990 | |
4991 alGetSourcei( | |
4992 ALmixer_Channel_List[i].alsource, | |
4993 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4994 ); | |
4995 | |
4996 /******** END REMOVE *******/ | |
4997 #endif | |
4998 /* FIXME: Ugh! Somewhere an alError is being thrown ("Invalid Enum Value"), but I can't | |
4999 * find it. It only seems to be thrown for OS X. I placed error messages after every al* | |
5000 * command I could find in the above loops, but the error doesn't seem to show | |
5001 * up until around here. I mistook it for a get queued buffers | |
5002 * error in OS X. I don't think there's an error down there. | |
5003 * For now, I'm clearing the error here. | |
5004 */ | |
5005 | |
5006 if((error = alGetError()) != AL_NO_ERROR) | |
5007 { | |
5008 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
|
5009 alGetString(error)); |
0 | 5010 } |
5011 | |
5012 | |
5013 alGetSourcei( | |
5014 ALmixer_Channel_List[i].alsource, | |
5015 AL_SOURCE_STATE, &state | |
5016 ); | |
5017 if((error = alGetError()) != AL_NO_ERROR) | |
5018 { | |
5019 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
|
5020 alGetString(error)); |
0 | 5021 } |
5022 | |
5023 | |
5024 if(AL_STOPPED == state) | |
5025 { | |
5026 /* Playback has ended. | |
5027 * Loop if necessary, or launch callback | |
5028 * and clear channel (or clear channel and | |
5029 * then launch callback?) | |
5030 */ | |
5031 | |
5032 | |
5033 /* Need to check for loops */ | |
5034 if(ALmixer_Channel_List[i].loops != 0) | |
5035 { | |
5036 /* Corner Case: If the buffer has | |
5037 * been modified using Seek, | |
5038 * the loop will start at the seek | |
5039 * position. | |
5040 */ | |
5041 if(ALmixer_Channel_List[i].loops != -1) | |
5042 { | |
5043 ALmixer_Channel_List[i].loops--; | |
5044 } | |
5045 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5046 if((error = alGetError()) != AL_NO_ERROR) | |
5047 { | |
5048 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
|
5049 alGetString(error)); |
0 | 5050 } |
5051 continue; | |
5052 } | |
5053 /* No loops. End play. */ | |
5054 else | |
5055 { | |
5056 /* Problem: It seems that when mixing | |
5057 * streamed and predecoded sources, | |
5058 * the previous instance lingers, | |
5059 * so we need to force remove | |
5060 * the data from the source. | |
5061 * The sharing problem | |
5062 * occurs when a previous predecoded buffer is played on | |
5063 * a source, and then a streamed source is played later | |
5064 * on that same source. OpenAL isn't consistently | |
5065 * removing the previous buffer so both get played. | |
5066 * (Different dists seem to have different quirks. | |
5067 * The problem might lead to crashes in the worst case.) | |
5068 */ | |
5069 /* Additional problem: There is another | |
5070 * inconsistency among OpenAL distributions. | |
5071 * Both Loki and Creative Windows seem to keep | |
5072 * the buffer queued which requires removing. | |
5073 * But the Creative Macintosh version does | |
5074 * not have any buffer queued after play | |
5075 * and it returns the error: Invalid Enum Value | |
5076 * if I try to unqueue it. | |
5077 * So I'm going to put in a check to see if I | |
5078 * can detect any buffers queued first | |
5079 * and then unqueue them if I can see them. | |
5080 * Additional note: The new CoreAudio based | |
5081 * implementation leaves it's buffer queued | |
5082 * like Loki and Creative Windows. But | |
5083 * considering all the problems I'm having | |
5084 * with the different distributions, this | |
5085 * check seems reasonable. | |
5086 */ | |
5087 ALint buffers_still_queued; | |
5088 if((error = alGetError()) != AL_NO_ERROR) | |
5089 { | |
5090 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
|
5091 alGetString(error)); |
0 | 5092 } |
5093 | |
5094 alGetSourcei( | |
5095 ALmixer_Channel_List[i].alsource, | |
5096 AL_BUFFERS_QUEUED, &buffers_still_queued | |
5097 ); | |
5098 if((error = alGetError()) != AL_NO_ERROR) | |
5099 { | |
5100 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
|
5101 alGetString(error)); |
0 | 5102 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
|
5103 alGetString(error) ); |
0 | 5104 error_flag--; |
5105 } | |
5106 if(buffers_still_queued > 0) | |
5107 { | |
1 | 5108 |
5109 #if 0 /* This triggers an error in OS X Core Audio. */ | |
5110 alSourceUnqueueBuffers( | |
5111 ALmixer_Channel_List[i].alsource, | |
5112 1, | |
5113 ALmixer_Channel_List[i].almixer_data->buffer | |
5114 ); | |
5115 #else | |
5116 /* fprintf(stderr, "In the Bob Aron section...about to clear source\n"); | |
0 | 5117 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 5118 */ |
0 | 5119 /* Rather than force unqueuing the buffer, let's see if |
5120 * setting the buffer to none works (the OpenAL 1.0 | |
5121 * Reference Annotation suggests this should work). | |
5122 */ | |
5123 alSourcei(ALmixer_Channel_List[i].alsource, | |
5124 AL_BUFFER, AL_NONE); | |
5125 /* | |
5126 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5127 */ | |
1 | 5128 #endif |
0 | 5129 if((error = alGetError()) != AL_NO_ERROR) |
5130 { | |
5131 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
|
5132 alGetString(error)); |
0 | 5133 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
|
5134 alGetString(error) ); |
0 | 5135 error_flag--; |
5136 } | |
5137 | |
5138 } | |
5139 | |
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
|
5140 /* 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
|
5141 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
|
5142 |
0 | 5143 Clean_Channel(i); |
5144 /* Subtract counter */ | |
5145 Is_Playing_global--; | |
5146 | |
5147 | |
5148 /* We're done for this loop. | |
5149 * Go to next channel | |
5150 */ | |
5151 continue; | |
5152 } | |
5153 continue; | |
5154 } | |
5155 } /* End if decoded_all */ | |
5156 /* For streamed */ | |
5157 else | |
5158 { | |
5159 ALint buffers_processed; | |
5160 ALint buffers_still_queued; | |
5161 ALint current_buffer_id; | |
5162 | |
5163 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
|
5164 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
|
5165 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
|
5166 |
0 | 5167 #if 0 |
5168 /********* Remove this **********/ | |
5169 fprintf(stderr, "For Streamed\n"); | |
5170 | |
5171 alGetSourcei( | |
5172 ALmixer_Channel_List[i].alsource, | |
5173 AL_SOURCE_STATE, &state | |
5174 ); | |
5175 switch(state) { | |
5176 case AL_PLAYING: | |
5177 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
5178 break; | |
5179 case AL_PAUSED: | |
5180 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
5181 break; | |
5182 case AL_STOPPED: | |
5183 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
5184 break; | |
5185 case AL_INITIAL: | |
5186 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
5187 break; | |
5188 default: | |
5189 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
5190 break; | |
5191 } | |
5192 /******** END REMOVE *******/ | |
5193 #endif | |
5194 /* Get the number of buffers still queued */ | |
5195 alGetSourcei( | |
5196 ALmixer_Channel_List[i].alsource, | |
5197 AL_BUFFERS_QUEUED, &buffers_still_queued | |
5198 ); | |
5199 if((error = alGetError()) != AL_NO_ERROR) | |
5200 { | |
5201 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
|
5202 alGetString(error)); |
0 | 5203 } |
5204 /* Get the number of buffers processed | |
5205 * so we know if we need to refill | |
5206 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5207 /* 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
|
5208 * 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
|
5209 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5210 // fprintf(stderr, "calling AL_BUFFERS_PROCESSED on source:%d", ALmixer_Channel_List[i].alsource); |
0 | 5211 alGetSourcei( |
5212 ALmixer_Channel_List[i].alsource, | |
5213 AL_BUFFERS_PROCESSED, &buffers_processed | |
5214 ); | |
5215 if((error = alGetError()) != AL_NO_ERROR) | |
5216 { | |
5217 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
|
5218 alGetString(error)); |
0 | 5219 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5220 // fprintf(stderr, "finished AL_BUFFERS_PROCESSED, buffers_processed=%d", buffers_processed); |
0 | 5221 |
5222 /* WTF!!! The Nvidia distribution is failing on the alGetSourcei(source, AL_BUFFER, buf_id) call. | |
5223 * I need this call to figure out which buffer OpenAL is currently playing. | |
5224 * It keeps returning an "Invalid Enum" error. | |
5225 * This is totally inane! It's a basic query. | |
5226 * By the spec, this functionality is not explicitly defined so Nvidia refuses to | |
5227 * fix this behavior, even though all other distributions work fine with this. | |
5228 * The only workaround for this is for | |
5229 * a significant rewrite of my code which requires me to | |
5230 * duplicate the OpenAL queued buffers state with my own | |
5231 * code and try to derive what the current playing buffer is by indirect observation of | |
5232 * looking at buffers_processed. But of course this has a ton of downsides since my | |
5233 * queries do not give me perfect timing of what OpenAL is actually doing and | |
5234 * the fact that some of the distributions seem to have buffer queuing problems | |
5235 * with their query results (CoreAudio). This also means a ton of extra code | |
5236 * on my side. The lack of support of a 1 line call has required me to | |
5237 * implement yet another entire state machine. <sigh> | |
5238 */ | |
5239 #if 0 /* This code will not work until possibly OpenAL 1.1 because of Nvidia */ | |
5240 /* Get the id to the current buffer playing */ | |
5241 alGetSourcei( | |
5242 ALmixer_Channel_List[i].alsource, | |
5243 AL_BUFFER, ¤t_buffer_id | |
5244 ); | |
5245 if((error = alGetError()) != AL_NO_ERROR) | |
5246 { | |
5247 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
|
5248 alGetString(error)); |
0 | 5249 } |
5250 | |
5251 /* Before the hard stuff, check to see if the | |
5252 * current queued AL buffer has changed. | |
5253 * If it has, we should launch a data callback if | |
5254 * necessary | |
5255 */ | |
5256 if( ((ALuint)current_buffer_id) != | |
5257 ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5258 { | |
5259 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5260 = (ALuint)current_buffer_id; | |
5261 | |
5262 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5263 } | |
5264 #else | |
5265 /* Only do this if "access_data" was requested (i.e. the circular_buffer!=NULL) | |
5266 * And if one of the two are true: | |
5267 * Either buffers_processed > 0 (because the current_buffer might have changed) | |
5268 * or if the current_buffer==0 (because we are in an initial state or recovering from | |
5269 * a buffer underrun) | |
5270 */ | |
5271 if((ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5272 && ( | |
5273 (buffers_processed > 0) || (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5274 ) | |
5275 ) | |
5276 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5277 ALint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5278 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5279 ALubyte is_out_of_sync = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5280 ALuint my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
1 | 5281 /* Ugh, I have to deal with signed/unsigned mismatch here. */ |
5282 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
|
5283 ALuint unplayed_buffers; |
1 | 5284 if(buffers_unplayed_int < 0) |
5285 { | |
5286 unplayed_buffers = 0; | |
5287 } | |
5288 else | |
5289 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5290 unplayed_buffers = (ALuint)buffers_unplayed_int; |
1 | 5291 } |
0 | 5292 /* |
5293 fprintf(stderr, "Queue in processed check, before pop, buffers_processed=%d\n", buffers_processed); | |
5294 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5295 */ | |
5296 /* We can't make any determinations solely based on the number of buffers_processed | |
5297 * because currently, we only unqueue 1 buffer per loop. That means if 2 or more | |
5298 * buffers became processed in one loop, the following loop, we would have | |
5299 * at least that_many-1 buffers_processed (plus possible new processed). | |
5300 * If we tried to just remove 1 buffer from our queue, we would be incorrect | |
5301 * because we would not actually reflect the current playing buffer. | |
5302 * So the solution seems to be to make sure our queue is the same size | |
5303 * as the number of buffers_queued-buffers_processed, and return the head of our queue | |
5304 * as the current playing buffer. | |
5305 */ | |
5306 /* Also, we have a corner case. When we first start playing or if we have | |
5307 * a buffer underrun, we have not done a data callback. | |
5308 * In this case, we need to see if there is any new data in our queue | |
5309 * and if so, launch that data callback. | |
5310 */ | |
5311 /* Warning, this code risks the possibility of no data callback being fired if | |
5312 * the system is really late (or skipped buffers). | |
5313 */ | |
5314 | |
5315 /* First, let's syncronize our queue with the OpenAL queue */ | |
5316 #if 0 | |
5317 fprintf(stderr, "inside, Buffers processed=%d, Buffers queued=%d, my queue=%d\n", | |
5318 buffers_processed, buffers_still_queued, my_queue_size); | |
1 | 5319 #endif |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5320 is_out_of_sync = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5321 for(k=0; k<buffers_processed; k++) |
0 | 5322 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5323 queue_ret_flag = CircularQueueUnsignedInt_PopFront( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5324 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5325 if(0 == queue_ret_flag) |
0 | 5326 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5327 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
|
5328 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5329 } |
0 | 5330 my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
5331 /* We have several possibilities we need to handle: | |
5332 * 1) We are in an initial state or underrun and need to do a data callback on the head. | |
5333 * 2) We were out of sync and need to do a new data callback on the new head. | |
5334 * 3) We were not out of sync but just had left over processed buffers which caused us to | |
5335 * fall in this block of code. (Don't do anything.) | |
5336 */ | |
5337 if( (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) || (1 == is_out_of_sync) ) | |
5338 { | |
5339 if(my_queue_size > 0) | |
5340 { | |
5341 current_buffer_id = CircularQueueUnsignedInt_Front( | |
5342 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5343 if(0 == current_buffer_id) | |
5344 { | |
5345 fprintf(stderr, "53a Internal Error, current_buffer_id=0 when it shouldn't be 0\n"); | |
5346 } | |
5347 /* | |
5348 else | |
5349 { | |
5350 fprintf(stderr, "Queue in processed check, after pop\n"); | |
5351 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5352 } | |
5353 */ | |
5354 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5355 = (ALuint)current_buffer_id; | |
5356 | |
5357 #if 0 | |
5358 /* Remove me...only for checking...doesn't work on Nvidia */ | |
5359 { | |
5360 ALuint real_id; | |
5361 alGetSourcei( | |
5362 ALmixer_Channel_List[i].alsource, | |
5363 AL_BUFFER, &real_id | |
5364 ); | |
5365 alGetError(); | |
5366 fprintf(stderr, "Callback fired on data buffer=%d, real_id shoud be=%d\n", current_buffer_id, real_id); | |
5367 } | |
5368 #endif | |
5369 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5370 } | |
5371 else | |
5372 { | |
1 | 5373 /* |
0 | 5374 fprintf(stderr, "53b, Notice/Warning:, OpenAL queue has been depleted.\n"); |
1 | 5375 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
5376 */ | |
0 | 5377 /* In this case, we might either be in an underrun or finished with playback */ |
5378 ALmixer_Channel_List[i].almixer_data->current_buffer = 0; | |
5379 } | |
5380 } | |
5381 } | |
5382 #endif | |
5383 | |
5384 | |
5385 | |
5386 /* Just a test - remove | |
5387 if( ALmixer_Channel_List[i].loops > 0) | |
5388 { | |
5389 fprintf(stderr, ">>>>>>>>>>>>>>>Loops = %d\n", | |
5390 ALmixer_Channel_List[i].loops); | |
5391 } | |
5392 */ | |
5393 #if 0 | |
5394 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
5395 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5396 #endif | |
5397 /* We've used up a buffer so we need to unqueue and replace */ | |
5398 /* Okay, it gets more complicated here: | |
5399 * We need to Queue more data | |
5400 * if buffers_processed > 0 or | |
5401 * if num_of_buffers_in_use < NUMBER_OF_QUEUE_BUFFERS | |
5402 * but we don't do this if at EOF, | |
5403 * except when there is looping | |
5404 */ | |
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
|
5405 |
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
|
5406 /* 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
|
5407 /* 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
|
5408 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
|
5409 { |
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 |
0 | 5411 /* For this to work, we must rely on EVERYTHING |
5412 * else to unset the EOF if there is looping. | |
5413 * Remember, even Play() must do this | |
5414 */ | |
5415 | |
5416 /* If not EOF, then we are still playing. | |
5417 * Inside, we might find num_of_buffers < NUM...QUEUE_BUF.. | |
5418 * or buffers_process > 0 | |
5419 * in which case we queue up. | |
5420 * We also might find no buffers we need to fill, | |
5421 * in which case we just keep going | |
5422 */ | |
5423 if( ! ALmixer_Channel_List[i].almixer_data->eof) | |
5424 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5425 ALuint bytes_returned; |
0 | 5426 /* We have a priority. We first must assign |
5427 * unused buffers in reserve. If there is nothing | |
5428 * left, then we may unqueue buffers. We can't | |
5429 * do it the other way around because we will | |
5430 * lose the pointer to the unqueued buffer | |
5431 */ | |
5432 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5433 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5434 { | |
1 | 5435 #if 0 |
0 | 5436 fprintf(stderr, "Getting more data in NOT_EOF and num_buffers_in_use (%d) < max_queue (%d)\n", |
5437 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5438 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5439 #endif |
0 | 5440 /* Going to add an unused packet. |
5441 * Grab next packet */ | |
5442 bytes_returned = GetMoreData( | |
5443 ALmixer_Channel_List[i].almixer_data, | |
5444 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5445 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5446 ); | |
5447 } | |
5448 /* For processed > 0 */ | |
5449 else if(buffers_processed > 0) | |
5450 { | |
5451 /* Unqueue only 1 buffer for now. | |
5452 * If there are more than one, | |
5453 * let the next Update pass deal with it | |
5454 * so we don't stall the program for too long. | |
5455 */ | |
5456 #if 0 | |
5457 fprintf(stderr, "About to Unqueue, Buffers processed = %d\n", buffers_processed); | |
5458 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5459 fprintf(stderr, "Unqueuing a buffer\n"); | |
5460 #endif | |
5461 alSourceUnqueueBuffers( | |
5462 ALmixer_Channel_List[i].alsource, | |
5463 1, &unqueued_buffer_id | |
5464 ); | |
5465 if((error = alGetError()) != AL_NO_ERROR) | |
5466 { | |
5467 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
|
5468 alGetString(error)); |
0 | 5469 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
|
5470 alGetString(error) ); |
0 | 5471 error_flag--; |
5472 } | |
5473 /* | |
5474 fprintf(stderr, "Right after unqueue..."); | |
5475 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5476 fprintf(stderr, "Getting more data for NOT_EOF, max_buffers filled\n"); | |
5477 */ | |
5478 /* Grab unqueued packet */ | |
5479 bytes_returned = GetMoreData( | |
5480 ALmixer_Channel_List[i].almixer_data, | |
5481 unqueued_buffer_id); | |
5482 } | |
5483 /* We are still streaming, but currently | |
5484 * don't need to fill any buffers */ | |
5485 else | |
5486 { | |
5487 /* Might want to check state */ | |
5488 /* In case the playback stopped, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5489 * we need to resume |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5490 * a.k.a. buffer underrun |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5491 */ |
1 | 5492 #if 1 |
5493 /* Try not refetching the state here because I'm getting a duplicate | |
5494 buffer playback (hiccup) */ | |
0 | 5495 alGetSourcei( |
5496 ALmixer_Channel_List[i].alsource, | |
5497 AL_SOURCE_STATE, &state | |
5498 ); | |
1 | 5499 if((error = alGetError()) != AL_NO_ERROR) |
5500 { | |
5501 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
|
5502 alGetString(error)); |
1 | 5503 } |
5504 /* Get the number of buffers processed | |
5505 */ | |
5506 alGetSourcei( | |
5507 ALmixer_Channel_List[i].alsource, | |
5508 AL_BUFFERS_PROCESSED, | |
5509 &buffers_processed | |
5510 ); | |
5511 if((error = alGetError()) != AL_NO_ERROR) | |
5512 { | |
5513 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
|
5514 alGetString(error)); |
1 | 5515 } |
5516 #endif | |
0 | 5517 if(AL_STOPPED == state) |
5518 { | |
5519 /* Resuming in not eof, but nothing to buffer */ | |
1 | 5520 |
5521 /* Okay, here's another lately discovered problem: | |
5522 * I can't find it in the spec, but for at least some of the | |
5523 * implementations, if I call play on a stopped source that | |
5524 * has processed buffers, all those buffers get marked as unprocessed | |
5525 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5526 * processed, on resume, the earlier 24 buffers will get replayed, | |
5527 * causing a "hiccup" like sound in the playback. | |
5528 * To avoid this, I must unqueue all processed buffers before | |
5529 * calling play. But to complicate things, I need to worry about resyncing | |
5530 * the circular queue with this since I designed this thing | |
5531 * with some correlation between the two. However, I might | |
5532 * have already handled this, so I will try writing this code without | |
5533 * syncing for now. | |
5534 * There is currently an assumption that a buffer | |
5535 * was queued above so I actually have something | |
5536 * to play. | |
5537 */ | |
5538 ALint temp_count; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5539 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5540 fprintf(stderr, "STOPPED1, need to clear processed=%d, status is:\n", buffers_processed); |
1 | 5541 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
|
5542 #endif |
1 | 5543 for(temp_count=0; temp_count<buffers_processed; temp_count++) |
5544 { | |
5545 alSourceUnqueueBuffers( | |
5546 ALmixer_Channel_List[i].alsource, | |
5547 1, &unqueued_buffer_id | |
5548 ); | |
5549 if((error = alGetError()) != AL_NO_ERROR) | |
5550 { | |
5551 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
|
5552 alGetString(error)); |
1 | 5553 error_flag--; |
5554 } | |
5555 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5556 #if 0 |
1 | 5557 fprintf(stderr, "After unqueue clear...:\n"); |
5558 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
|
5559 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5560 /* 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
|
5561 * 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
|
5562 * 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
|
5563 * 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
|
5564 * no buffers in queue. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5565 * 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
|
5566 * Then we need to resume playing. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5567 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5568 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5569 int buffers_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5570 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5571 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5572 AL_BUFFERS_QUEUED, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5573 &buffers_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5574 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5575 |
1 | 5576 if((error = alGetError()) != AL_NO_ERROR) |
5577 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5578 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
|
5579 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5580 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5581 assert(buffers_queued == 0); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5582 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
|
5583 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5584 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5585 /* 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
|
5586 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
|
5587 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5588 /* 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
|
5589 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5590 ALmixer_Channel_List[i].almixer_data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5591 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
|
5592 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5593 /* 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
|
5594 * 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
|
5595 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5596 if(bytes_returned > 0) |
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 /* Queue up the new data */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5599 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5600 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5601 1, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5602 &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
|
5603 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5604 if((error = alGetError()) != AL_NO_ERROR) |
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 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
|
5607 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5608 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5609 /* 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
|
5610 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
|
5611 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5612 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5613 /* 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
|
5614 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
|
5615 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5616 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5617 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
|
5618 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5619 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 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
|
5621 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5622 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5623 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5624 fprintf(stderr, "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
|
5625 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
|
5626 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5627 } |
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 /* Resume playback from underrun */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5633 alSourcePlay(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5634 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5635 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5636 fprintf(stderr, "55Tbesting error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5637 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5638 } |
1 | 5639 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5640 |
0 | 5641 } |
5642 /* Let's escape to the next loop. | |
5643 * All code below this point is for queuing up | |
5644 */ | |
5645 /* | |
1 | 5646 fprintf(stderr, "Entry: Nothing to do...continue\n\n"); |
5647 */ | |
0 | 5648 continue; |
5649 } | |
5650 /* We now know we have to fill an available | |
5651 * buffer. | |
5652 */ | |
5653 | |
5654 /* In the previous branch, we just grabbed more data. | |
5655 * Let's check it to make sure it's okay, | |
5656 * and then queue it up | |
5657 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5658 /* This check doesn't work anymore because it is now ALuint */ |
0 | 5659 #if 0 |
5660 if(-1 == bytes_returned) | |
5661 { | |
5662 /* Problem occurred...not sure what to do */ | |
5663 /* Go to next loop? */ | |
5664 error_flag--; | |
5665 /* Set the eof flag to force a quit so | |
5666 * we don't get stuck in an infinite loop | |
5667 */ | |
5668 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5669 continue; | |
5670 } | |
5671 #endif | |
5672 /* This is a special case where we've run | |
5673 * out of data. We should check for loops | |
5674 * and get more data. If there is no loop, | |
5675 * then do nothing and wait for future | |
5676 * update passes to handle the EOF. | |
5677 * The advantage of handling the loop here | |
5678 * instead of waiting for play to stop is | |
5679 * that we should be able to keep the buffer | |
5680 * filled. | |
5681 */ | |
5682 #if 0 | |
5683 else if(0 == bytes_returned) | |
5684 #endif | |
5685 if(0 == bytes_returned) | |
5686 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5687 /* |
0 | 5688 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
|
5689 */ |
0 | 5690 /* Check for loops */ |
5691 if( ALmixer_Channel_List[i].loops != 0 ) | |
5692 { | |
5693 /* We have to loop, so rewind | |
5694 * and fetch more data | |
5695 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5696 /* |
0 | 5697 fprintf(stderr, "Rewinding data\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5698 */ |
0 | 5699 if(0 == Sound_Rewind( |
5700 ALmixer_Channel_List[i].almixer_data->sample)) | |
5701 { | |
5702 fprintf(stderr, "Rewinding failed\n"); | |
5703 ALmixer_SetError( Sound_GetError() ); | |
5704 ALmixer_Channel_List[i].loops = 0; | |
5705 error_flag--; | |
5706 /* We'll continue on because we do have some valid data */ | |
5707 continue; | |
5708 } | |
5709 /* Remember to reset the data->eof flag */ | |
5710 ALmixer_Channel_List[i].almixer_data->eof = 0; | |
5711 if(ALmixer_Channel_List[i].loops > 0) | |
5712 { | |
5713 ALmixer_Channel_List[i].loops--; | |
5714 } | |
5715 /* Try grabbing another packet now. | |
5716 * Since we may have already unqueued a | |
5717 * buffer, we don't want to lose it. | |
5718 */ | |
5719 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5720 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5721 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5722 /* |
0 | 5723 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
|
5724 */ |
0 | 5725 /* Grab next packet */ |
5726 bytes_returned = GetMoreData( | |
5727 ALmixer_Channel_List[i].almixer_data, | |
5728 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5729 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5730 ); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5731 /* |
0 | 5732 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
|
5733 */ |
0 | 5734 } |
5735 /* Refilling unqueued packet */ | |
5736 else | |
5737 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5738 /* |
0 | 5739 fprintf(stderr, "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
|
5740 */ |
0 | 5741 /* Grab next packet */ |
5742 bytes_returned = GetMoreData( | |
5743 ALmixer_Channel_List[i].almixer_data, | |
5744 unqueued_buffer_id); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5745 /* |
0 | 5746 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
|
5747 */ |
0 | 5748 } |
5749 /* Another error check */ | |
5750 /* | |
5751 if(bytes_returned <= 0) | |
5752 */ | |
5753 if(0 == bytes_returned) | |
5754 { | |
5755 fprintf(stderr, "??????????ERROR\n"); | |
5756 ALmixer_SetError("Could not loop because after rewind, no data could be retrieved"); | |
5757 /* Problem occurred...not sure what to do */ | |
5758 /* Go to next loop? */ | |
5759 error_flag--; | |
5760 /* Set the eof flag to force a quit so | |
5761 * we don't get stuck in an infinite loop | |
5762 */ | |
5763 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5764 continue; | |
5765 } | |
5766 /* We made it to the end. We still need | |
5767 * to BufferData, so let this branch | |
5768 * fall into the next piece of | |
5769 * code below which will handle that | |
5770 */ | |
5771 | |
5772 | |
5773 } /* END loop check */ | |
5774 else | |
5775 { | |
5776 /* No more loops to do. | |
5777 * EOF flag should be set. | |
5778 * Just go to next loop and | |
5779 * let things be handled correctly | |
5780 * in future update calls | |
5781 */ | |
1 | 5782 /* |
0 | 5783 fprintf(stderr, "SHOULD BE EOF\n"); |
5784 | |
5785 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
1 | 5786 */ |
0 | 5787 continue; |
5788 } | |
5789 } /* END if bytes_returned == 0 */ | |
5790 /********* Possible trouble point. I might be queueing empty buffers on the mac. | |
5791 * This check doesn't say if the buffer is valid. Only the EOF assumption is a clue at this point | |
5792 */ | |
5793 /* Fall here */ | |
5794 /* Everything is normal. We aren't | |
5795 * at an EOF, but need to simply | |
5796 * queue more data. The data is already checked for good, | |
5797 * so queue it up */ | |
5798 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5799 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5800 { | |
5801 /* Keep count of how many buffers we have | |
5802 * to queue so we can return the value | |
5803 */ | |
5804 retval++; | |
1 | 5805 /* |
0 | 5806 fprintf(stderr, "NOT_EOF???, about to Queue more data for num_buffers (%d) < max_queue (%d)\n", |
5807 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5808 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5809 */ |
0 | 5810 alSourceQueueBuffers( |
5811 ALmixer_Channel_List[i].alsource, | |
5812 1, | |
5813 &ALmixer_Channel_List[i].almixer_data->buffer[ | |
5814 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5815 ); | |
5816 if((error = alGetError()) != AL_NO_ERROR) | |
5817 { | |
5818 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
|
5819 alGetString(error)); |
0 | 5820 } |
5821 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5822 * which buffer to show during callbacks (for things like | |
5823 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5824 * data structure. This code will be called only if | |
5825 * "access_data" was set, indicated by whether the queue is NULL. | |
5826 */ | |
5827 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5828 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5829 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5830 // fprintf(stderr, "56d: CircularQueue_PushBack.\n"); |
0 | 5831 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5832 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5833 ALmixer_Channel_List[i].almixer_data->buffer[ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5834 ); | |
5835 if(0 == queue_ret_flag) | |
5836 { | |
5837 fprintf(stderr, "56aSerious internal error: CircularQueue could not push into queue.\n"); | |
5838 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5839 } | |
5840 /* | |
5841 else | |
5842 { | |
5843 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5844 } | |
5845 */ | |
5846 } | |
5847 } | |
5848 /* for processed > 0 */ | |
5849 else | |
5850 { | |
5851 /* Keep count of how many buffers we have | |
5852 * to queue so we can return the value | |
5853 */ | |
5854 retval++; | |
5855 /* | |
5856 fprintf(stderr, "NOT_EOF, about to Queue more data for filled max_queue (%d)\n", | |
5857 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
5858 */ | |
5859 alSourceQueueBuffers( | |
5860 ALmixer_Channel_List[i].alsource, | |
5861 1, &unqueued_buffer_id); | |
5862 if((error = alGetError()) != AL_NO_ERROR) | |
5863 { | |
5864 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
|
5865 alGetString(error) ); |
0 | 5866 error_flag--; |
5867 continue; | |
5868 } | |
5869 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5870 * which buffer to show during callbacks (for things like | |
5871 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5872 * data structure. This code will be called only if | |
5873 * "access_data" was set, indicated by whether the queue is NULL. | |
5874 */ | |
5875 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5876 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5877 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5878 // fprintf(stderr, "56e: CircularQueue_PushBack.\n"); |
0 | 5879 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5880 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5881 unqueued_buffer_id | |
5882 ); | |
5883 if(0 == queue_ret_flag) | |
5884 { | |
5885 fprintf(stderr, "56bSerious internal error: CircularQueue could not push into queue.\n"); | |
5886 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5887 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5888 #if 0 |
0 | 5889 else |
5890 { | |
5891 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5892 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5893 #endif |
0 | 5894 } |
5895 } | |
5896 /* If we used an available buffer queue, | |
5897 * then we need to update the number of them in use | |
5898 */ | |
5899 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5900 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5901 { | |
5902 /* Increment the number of buffers in use */ | |
5903 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use++; | |
5904 } | |
5905 /* Might want to check state */ | |
5906 /* In case the playback stopped, | |
5907 * we need to resume */ | |
1 | 5908 #if 1 |
5909 /* Try not refetching the state here because I'm getting a duplicate | |
5910 buffer playback (hiccup) */ | |
0 | 5911 alGetSourcei( |
5912 ALmixer_Channel_List[i].alsource, | |
5913 AL_SOURCE_STATE, &state | |
5914 ); | |
1 | 5915 if((error = alGetError()) != AL_NO_ERROR) |
5916 { | |
5917 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
|
5918 alGetString(error)); |
1 | 5919 } |
5920 /* Get the number of buffers processed | |
5921 */ | |
5922 alGetSourcei( | |
5923 ALmixer_Channel_List[i].alsource, | |
5924 AL_BUFFERS_PROCESSED, | |
5925 &buffers_processed | |
5926 ); | |
5927 if((error = alGetError()) != AL_NO_ERROR) | |
5928 { | |
5929 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
|
5930 alGetString(error)); |
1 | 5931 } |
5932 #endif | |
0 | 5933 if(AL_STOPPED == state) |
5934 { | |
1 | 5935 /* |
0 | 5936 fprintf(stderr, "Resuming in not eof\n"); |
1 | 5937 */ |
5938 /* Okay, here's another lately discovered problem: | |
5939 * I can't find it in the spec, but for at least some of the | |
5940 * implementations, if I call play on a stopped source that | |
5941 * has processed buffers, all those buffers get marked as unprocessed | |
5942 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5943 * processed, on resume, the earlier 24 buffers will get replayed, | |
5944 * causing a "hiccup" like sound in the playback. | |
5945 * To avoid this, I must unqueue all processed buffers before | |
5946 * calling play. But to complicate things, I need to worry about resyncing | |
5947 * the circular queue with this since I designed this thing | |
5948 * with some correlation between the two. However, I might | |
5949 * have already handled this, so I will try writing this code without | |
5950 * syncing for now. | |
5951 * There is currently an assumption that a buffer | |
5952 * was queued above so I actually have something | |
5953 * to play. | |
5954 */ | |
5955 ALint temp_count; | |
5956 /* | |
5957 fprintf(stderr, "STOPPED2, need to clear processed, status is:\n"); | |
5958 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5959 */ | |
5960 | |
5961 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5962 { | |
5963 alSourceUnqueueBuffers( | |
5964 ALmixer_Channel_List[i].alsource, | |
5965 1, &unqueued_buffer_id | |
5966 ); | |
5967 if((error = alGetError()) != AL_NO_ERROR) | |
5968 { | |
5969 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
|
5970 alGetString(error)); |
1 | 5971 error_flag--; |
5972 } | |
5973 } | |
5974 /* | |
5975 fprintf(stderr, "After unqueue clear...:\n"); | |
5976 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5977 */ | |
5978 | |
5979 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5980 if((error = alGetError()) != AL_NO_ERROR) | |
5981 { | |
5982 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
|
5983 alGetString(error)); |
1 | 5984 } |
0 | 5985 } |
5986 continue; | |
5987 } /* END if( ! eof) */ | |
5988 /* We have hit EOF in the SDL_Sound sample and there | |
5989 * are no more loops. However, there may still be | |
5990 * buffers in the OpenAL queue which still need to | |
5991 * be played out. The following body of code will | |
5992 * determine if play is still happening or | |
5993 * initiate the stop/cleanup sequenece. | |
5994 */ | |
5995 else | |
5996 { | |
5997 /* Let's continue to remove the used up | |
5998 * buffers as they come in. */ | |
5999 if(buffers_processed > 0) | |
6000 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6001 ALint temp_count; |
0 | 6002 /* Do as a for-loop because I don't want |
6003 * to have to create an array for the | |
6004 * unqueued_buffer_id's | |
6005 */ | |
6006 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
6007 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6008 /* |
0 | 6009 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
|
6010 */ |
0 | 6011 alSourceUnqueueBuffers( |
6012 ALmixer_Channel_List[i].alsource, | |
6013 1, &unqueued_buffer_id | |
6014 ); | |
6015 if((error = alGetError()) != AL_NO_ERROR) | |
6016 { | |
6017 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
|
6018 alGetString(error)); |
0 | 6019 } |
6020 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6021 /* |
0 | 6022 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
|
6023 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6024 |
0 | 6025 /* Need to update counts since we removed everything. |
6026 * If we don't update the counts here, we end up in the | |
6027 * "Shouldn't be here section, but maybe it's okay due to race conditions" | |
6028 */ | |
6029 alGetSourcei( | |
6030 ALmixer_Channel_List[i].alsource, | |
6031 AL_BUFFERS_QUEUED, &buffers_still_queued | |
6032 ); | |
6033 if((error = alGetError()) != AL_NO_ERROR) | |
6034 { | |
6035 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
|
6036 alGetString(error)); |
0 | 6037 } |
6038 /* Get the number of buffers processed | |
6039 * so we know if we need to refill | |
6040 */ | |
6041 alGetSourcei( | |
6042 ALmixer_Channel_List[i].alsource, | |
6043 AL_BUFFERS_PROCESSED, &buffers_processed | |
6044 ); | |
6045 if((error = alGetError()) != AL_NO_ERROR) | |
6046 { | |
6047 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
|
6048 alGetString(error)); |
0 | 6049 } |
6050 } | |
6051 | |
6052 | |
6053 /* Else if buffers_processed == 0 | |
6054 * and buffers_still_queued == 0. | |
6055 * then we check to see if the source | |
6056 * is still playing. Quit if stopped | |
6057 * We shouldn't need to worry about | |
6058 * looping because that should have | |
6059 * been handled above. | |
6060 */ | |
6061 if(0 == buffers_still_queued) | |
6062 { | |
6063 /* Make sure playback has stopped before | |
6064 * we shutdown. | |
6065 */ | |
6066 alGetSourcei( | |
6067 ALmixer_Channel_List[i].alsource, | |
6068 AL_SOURCE_STATE, &state | |
6069 ); | |
6070 if((error = alGetError()) != AL_NO_ERROR) | |
6071 { | |
6072 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
|
6073 alGetString(error)); |
0 | 6074 } |
6075 if(AL_STOPPED == state) | |
6076 { | |
6077 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use = 0; | |
6078 /* Playback has ended. | |
6079 * Loop if necessary, or launch callback | |
6080 * and clear channel (or clear channel and | |
6081 * 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
|
6082 * Update: Need to do callback first because I reference the mixer_data and source |
0 | 6083 */ |
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 |
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
|
6085 /* 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
|
6086 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
|
6087 |
0 | 6088 Clean_Channel(i); |
6089 /* Subtract counter */ | |
6090 Is_Playing_global--; | |
6091 | |
6092 | |
6093 /* We're done for this loop. | |
6094 * Go to next channel | |
6095 */ | |
6096 continue; | |
6097 } | |
6098 } /* End end-playback */ | |
6099 else | |
6100 { | |
6101 /* Need to run out buffer */ | |
6102 #if 1 | |
6103 /* Might want to check state */ | |
6104 /* In case the playback stopped, | |
6105 * we need to resume */ | |
6106 alGetSourcei( | |
6107 ALmixer_Channel_List[i].alsource, | |
6108 AL_SOURCE_STATE, &state | |
6109 ); | |
6110 if((error = alGetError()) != AL_NO_ERROR) | |
6111 { | |
6112 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
|
6113 alGetString(error)); |
0 | 6114 } |
6115 if(AL_STOPPED == state) | |
6116 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6117 /* |
0 | 6118 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
|
6119 */ |
1 | 6120 /* |
0 | 6121 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 6122 */ |
0 | 6123 /* Rather than force unqueuing the buffer, let's see if |
6124 * setting the buffer to none works (the OpenAL 1.0 | |
6125 * Reference Annotation suggests this should work). | |
6126 */ | |
6127 alSourcei(ALmixer_Channel_List[i].alsource, | |
6128 AL_BUFFER, AL_NONE); | |
6129 /* | |
6130 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
6131 */ | |
6132 /* This doesn't work because in some cases, I think | |
6133 * it causes the sound to be replayed | |
6134 */ | |
6135 /* | |
6136 fprintf(stderr, "Resuming in eof (trying to run out buffers\n"); | |
6137 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
6138 */ | |
6139 } | |
6140 #endif | |
6141 } /* End trap section */ | |
6142 } /* 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
|
6143 |
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
|
6144 } /* 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
|
6145 |
0 | 6146 } /* END Streamed section */ |
6147 } /* END channel in use */ | |
6148 } /* END for-loop for each channel */ | |
6149 | |
6150 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6151 alcProcessContext(alcGetCurrentContext()); | |
6152 if((error = alGetError()) != AL_NO_ERROR) | |
6153 { | |
6154 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
|
6155 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6156 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6157 #endif |
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 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6160 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6161 #endif |
0 | 6162 /* Return the number of errors */ |
6163 if(error_flag < 0) | |
6164 { | |
6165 return error_flag; | |
6166 } | |
6167 /* Return the number of buffers that were queued */ | |
6168 return retval; | |
6169 } | |
6170 | |
6171 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6172 /* 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
|
6173 static void my_dummy_audio_callback(void* userdata, ALbyte* stream, int len) |
0 | 6174 { |
6175 } | |
6176 #endif | |
6177 | |
6178 | |
6179 | |
6180 | |
6181 #ifdef ENABLE_ALMIXER_THREADS | |
6182 /* We might need threads. We | |
6183 * must constantly poll OpenAL to find out | |
6184 * if sound is being streamed, if play has | |
6185 * ended, etc. Without threads, this must | |
6186 * be explicitly done by the user. | |
6187 * We could try to do it for them if we | |
6188 * finish the threads. | |
6189 */ | |
6190 | |
6191 static int Stream_Data_Thread_Callback(void* data) | |
6192 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6193 ALint retval; |
0 | 6194 |
6195 while(ALmixer_Initialized) | |
6196 { | |
6197 retval = Update_ALmixer(data); | |
6198 /* 0 means that nothing needed updating and | |
6199 * the function returned quickly | |
6200 */ | |
6201 if(0 == retval) | |
6202 { | |
6203 /* Let's be nice and make the thread sleep since | |
6204 * little work was done in update | |
6205 */ | |
6206 /* Make sure times are multiples of 10 | |
6207 * for optimal performance and accuracy in Linux | |
6208 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6209 ALmixer_Delay(10); |
0 | 6210 } |
6211 else | |
6212 { | |
6213 /* 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
|
6214 ALmixer_Delay(0); |
0 | 6215 } |
6216 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6217 /* |
0 | 6218 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
|
6219 */ |
0 | 6220 return 0; |
6221 } | |
6222 #endif /* End of ENABLE_ALMIXER_THREADS */ | |
6223 | |
6224 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6225 /* 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
|
6226 * 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
|
6227 * so SDL_mixer porting people beware. |
0 | 6228 * Warning: SDL_QuitSubSystem(SDL_INIT_AUDIO) is called which |
6229 * means the SDL audio system will be disabled. It will not | |
6230 * be restored (in case SDL is not actually being used) so | |
6231 * the user will need to restart it if they need it after | |
6232 * OpenAL shuts down. | |
6233 */ | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6234 ALboolean ALmixer_Init(ALuint frequency, ALuint num_sources, ALuint refresh) |
0 | 6235 { |
6236 ALCdevice* dev; | |
6237 ALCcontext* context; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6238 ALint i; |
0 | 6239 ALenum error; |
6240 ALuint* source; | |
6241 | |
6242 #ifdef USING_LOKI_AL_DIST | |
6243 /* The Loki dist requires that I set both the | |
6244 * device and context frequency values separately | |
6245 */ | |
6246 /* Hope this won't overflow */ | |
6247 char device_string[256]; | |
6248 #endif | |
6249 | |
6250 /* (Venting frustration) Damn it! Nobody bothered | |
6251 * documenting how you're supposed to use an attribute | |
6252 * list. In fact, the not even the Loki test program | |
6253 * writers seem to know because they use it inconsistently. | |
6254 * For example, how do you terminate that attribute list? | |
6255 * The Loki test code does it 3 different ways. They | |
6256 * set the last value to 0, or they set it to ALC_INVALID, | |
6257 * or they set two final values: ALC_INVALID, 0 | |
6258 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6259 * but with Creative Labs ALC_INVALID is -1. | |
6260 * So something's going to break. Loki's source | |
6261 * code says to terminate with ALC_INVALID. But I | |
6262 * don't know if that's really true, or it happens | |
6263 * to be a coinicidence because it's defined to 0. | |
6264 * Creative provides no source code, so I can't look at how | |
6265 * they terminate it. | |
6266 * So this is really, really ticking me off... | |
6267 * For now, I'm going to use ALC_INVALID. | |
6268 * (Update...after further review of the API spec, | |
6269 * it seems that a NULL terminated string is the correct | |
6270 * termination value to use, so 0 it is.) | |
6271 */ | |
6272 #if 0 | |
6273 ALint attrlist[] = { | |
6274 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6275 /* Don't know anything about these values. | |
6276 * Trust defaults? */ | |
6277 /* Supposed to be the refresh rate in Hz. | |
6278 * I think 15-120 are supposed to be good | |
6279 * values. Though I haven't gotten any effect except | |
6280 * for one strange instance on a Mac. But it was | |
6281 * unrepeatable. | |
6282 */ | |
6283 #if 0 | |
6284 ALC_REFRESH, 15, | |
6285 #endif | |
6286 /* Sync requires a alcProcessContext() call | |
6287 * for every cycle. By default, this is | |
6288 * not used and the value is AL_FALSE | |
6289 * because it will probably perform | |
6290 * pretty badly for me. | |
6291 */ | |
6292 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6293 ALC_SYNC, AL_TRUE, | |
6294 #else | |
6295 ALC_SYNC, AL_FALSE, | |
6296 #endif | |
6297 /* Looking at the API spec, it implies | |
6298 * that the list be a NULL terminated string | |
6299 * so it's probably not safe to use ALC_INVALID | |
6300 */ | |
6301 /* | |
6302 ALC_INVALID }; | |
6303 */ | |
6304 '\0'}; | |
6305 #endif | |
6306 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6307 * However, if no value is specified, I don't | |
6308 * want it in the list so I can get the OpenAL defaults | |
6309 */ | |
6310 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6311 ALsizei current_attrlist_index = 0; |
0 | 6312 |
6313 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6314 /* More problems: I'm getting bit by endian/signedness issues on | |
6315 * different platforms. I can find the endianess easily enough, | |
6316 * but I don't know how to determine what the correct signedness | |
6317 * is (if such a thing exists). I do know that if I try using | |
6318 * unsigned on OSX with an originally signed sample, I get | |
6319 * distortion. However, I don't have any native unsigned samples | |
6320 * to test. But I'm assuming that the platform must be in the | |
6321 * correct signedness no matter what. | |
6322 * I can either assume everybody is signed, or I can try to | |
6323 * determine the value. If I try to determine the values, | |
6324 * I think my only ability to figure it out will be to open | |
6325 * SDL_Audio, and read what the obtained settings were. | |
6326 * Then shutdown everything. However, I don't even know how | |
6327 * reliable this is. | |
6328 * Update: I think I resolved the issues...forgot to update | |
6329 * these comments when it happened. I should check the revision control | |
6330 * log... Anyway, I think the issue was partly related to me not | |
6331 * doing something correctly with the AudioInfo or some kind | |
6332 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6333 * revision control, I think I might have assumed that SDL_Sound would | |
6334 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6335 * and had to fill one out myself. | |
6336 */ | |
6337 SDL_AudioSpec desired; | |
6338 SDL_AudioSpec obtained; | |
6339 #endif | |
6340 | |
6341 | |
6342 /* Make sure ALmixer isn't already initialized */ | |
6343 if(ALmixer_Initialized) | |
6344 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6345 return AL_FALSE; |
0 | 6346 } |
6347 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6348 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6349 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6350 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6351 /* 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
|
6352 /* 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
|
6353 * 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
|
6354 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6355 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6356 if(NULL == s_ALmixerErrorPool) |
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 s_ALmixerErrorPool = TError_CreateErrorPool(); |
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 if(NULL == s_ALmixerErrorPool) |
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 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6363 } |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6364 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6365 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6366 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6367 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
|
6368 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
|
6369 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6370 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6371 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6372 |
0 | 6373 /* Set the defaults */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6374 /* |
0 | 6375 attrlist[0] = ALC_FREQUENCY; |
6376 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6377 attrlist[2] = ALC_SYNC; | |
6378 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6379 attrlist[3] = ALC_TRUE; | |
6380 #else | |
6381 attrlist[3] = ALC_FALSE; | |
6382 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6383 */ |
0 | 6384 /* Set frequency value if it is not 0 */ |
6385 if(0 != frequency) | |
6386 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6387 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6388 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6389 attrlist[current_attrlist_index] = (ALint)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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6392 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6393 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6394 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6395 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6396 attrlist[current_attrlist_index] = ALC_TRUE; |
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 #endif |
0 | 6399 |
6400 /* If the user specifies a refresh value, | |
6401 * make room for it | |
6402 */ | |
6403 if(0 != refresh) | |
6404 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6405 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
|
6406 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6407 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6408 current_attrlist_index++; |
0 | 6409 } |
6410 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6411 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6412 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6413 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6414 |
0 | 6415 /* Initialize SDL_Sound */ |
6416 if(! Sound_Init() ) | |
6417 { | |
6418 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6419 return AL_FALSE; |
0 | 6420 } |
6421 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6422 /* Here is the paranoid check that opens | |
6423 * SDL audio in an attempt to find the correct | |
6424 * system values. | |
6425 */ | |
6426 /* Doesn't have to be the actual value I think | |
6427 * (as long as it doesn't influence format, in | |
6428 * which case I'm probably screwed anyway because OpenAL | |
6429 * may easily choose to do something else). | |
6430 */ | |
6431 desired.freq = 44100; | |
6432 desired.channels = 2; | |
6433 desired.format = AUDIO_S16SYS; | |
6434 desired.callback = my_dummy_audio_callback; | |
6435 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6436 { | |
6437 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6438 /* Now to get really paranoid, we should probably | |
6439 * also assume that the 8bit format is also the | |
6440 * same sign type and set that value | |
6441 */ | |
6442 if(AUDIO_S16SYS == obtained.format) | |
6443 { | |
6444 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6445 } | |
6446 /* Should be AUDIO_U16SYS */ | |
6447 else | |
6448 { | |
6449 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6450 } | |
6451 SDL_CloseAudio(); | |
6452 } | |
6453 else | |
6454 { | |
6455 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6456 */ | |
6457 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6458 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6459 } | |
6460 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6461 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6462 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6463 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
6464 * causes OpenAL and SMPEG to conflict. For some reason | |
6465 * if SDL_Init on audio is active, then all the SMPEG | |
6466 * decoded sound comes out silent. Unfortunately, | |
6467 * Sound_Init() invokes SDL_Init on audio. I'm | |
6468 * not sure why it actually needs it... | |
6469 * But we'll attempt to disable it here after the | |
6470 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
6471 */ | |
6472 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6473 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6474 |
0 | 6475 /* I'm told NULL will call the default string |
6476 * and hopefully do the right thing for each platform | |
6477 */ | |
6478 /* | |
6479 dev = alcOpenDevice( NULL ); | |
6480 */ | |
6481 /* Now I'm told I need to set both the device and context | |
6482 * to have the same sampling rate, so I must pass a string | |
6483 * to OpenDevice(). I don't know how portable these strings are. | |
6484 * I don't even know if the format for strings is | |
6485 * compatible | |
6486 * From the testattrib.c in the Loki test section | |
6487 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
6488 */ | |
6489 | |
6490 #ifdef USING_LOKI_AL_DIST | |
6491 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
6492 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
6493 #else | |
6494 dev = alcOpenDevice( NULL ); | |
6495 #endif | |
6496 if(NULL == dev) | |
6497 { | |
6498 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
|
6499 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6500 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6501 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6502 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6503 /* 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
|
6504 /* 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
|
6505 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6506 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6507 Internal_alcMacOSXMixerOutputRate((ALdouble)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 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
|
6510 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6511 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
|
6512 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6513 #endif |
0 | 6514 |
6515 context = alcCreateContext(dev, attrlist); | |
6516 if(NULL == context) | |
6517 { | |
6518 ALmixer_SetError("Cannot create a context OpenAL"); | |
6519 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6520 return AL_FALSE; |
0 | 6521 } |
6522 | |
6523 | |
6524 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6525 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6526 * According to Garin Hiebert, this is actually an inconsistency | |
6527 * in the Loki version. The function should return a boolean. | |
6528 * instead of ALC_NO_ERROR. Garin suggested I check via | |
6529 * alcGetError(). | |
6530 */ | |
6531 /* clear the error */ | |
6532 alcGetError(dev); | |
6533 alcMakeContextCurrent(context); | |
6534 | |
6535 error = alcGetError(dev); | |
6536 if( (ALC_NO_ERROR != error) ) | |
6537 { | |
6538 ALmixer_SetError("Could not MakeContextCurrent"); | |
6539 alcDestroyContext(context); | |
6540 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6541 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6542 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6543 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6544 /* 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
|
6545 * 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
|
6546 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6547 * 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
|
6548 * 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
|
6549 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6550 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6551 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6552 ALmixer_Frequency_global = frequency; |
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 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6555 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
|
6556 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6557 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
|
6558 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6559 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6560 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6561 |
0 | 6562 #if 0 |
6563 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
6564 if(alcGetCurrentContext() != context) | |
6565 { | |
6566 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6567 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6568 * I think this is a bug in the OpenAL implementation. | |
6569 */ | |
6570 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
6571 | |
6572 fprintf(stderr, "Making context current\n"); | |
6573 #ifndef __APPLE__ | |
6574 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
6575 #else | |
6576 if(!alcMakeContextCurrent(context)) | |
6577 #endif | |
6578 { | |
6579 ALmixer_SetError("Could not MakeContextCurrent"); | |
6580 alcDestroyContext(context); | |
6581 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6582 return AL_FALSE; |
0 | 6583 } |
6584 } | |
6585 #endif | |
6586 | |
6587 | |
6588 /* #endif */ | |
6589 /* Saw this in the README with the OS X OpenAL distribution. | |
6590 * It looked interesting and simple, so I thought I might | |
6591 * try it out. | |
6592 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
6593 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
6594 * Audio format, the audio data passed to the | |
6595 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
6596 * usage by removing an audio data conversion | |
6597 * (per source) at render timem at the expense of a larger memory footprint. | |
6598 * | |
6599 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
6600 * setting will be applied to all subsequent | |
6601 * calls to alBufferData(). | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6602 * |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6603 * 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
|
6604 * Rather than deal with it right now, I think I am going to make it an opt-in thing. |
0 | 6605 */ |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6606 #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
|
6607 /* |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6608 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
|
6609 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6610 #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
|
6611 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6612 #else |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6613 /* 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
|
6614 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
|
6615 /* |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6616 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
|
6617 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6618 if(0 != 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 alEnable(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 if( (AL_NO_ERROR != alGetError()) ) |
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 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
|
6625 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
|
6626 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6627 #endif |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6628 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6629 #endif /* __APPLE__ */ |
0 | 6630 |
6631 | |
6632 | |
6633 | |
6634 ALmixer_Initialized = 1; | |
6635 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6636 if(num_sources == 0) |
0 | 6637 { |
6638 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
6639 } | |
6640 else | |
6641 { | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6642 /* 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
|
6643 Number_of_Channels_global = (ALint)num_sources; |
0 | 6644 } |
6645 Number_of_Reserve_Channels_global = 0; | |
6646 Is_Playing_global = 0; | |
6647 /* Set to Null in case system quit and was reinitialized */ | |
6648 Channel_Done_Callback = NULL; | |
6649 Channel_Done_Callback_Userdata = NULL; | |
6650 Channel_Data_Callback = NULL; | |
1 | 6651 Channel_Data_Callback_Userdata = NULL; |
0 | 6652 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6653 /* Allocate memory for linked list of ALmixerData. */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6654 s_listOfALmixerData = LinkedList_Create(); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6655 if(NULL == s_listOfALmixerData) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6656 { |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6657 ALmixer_SetError("Couldn't create linked list"); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6658 alcDestroyContext(context); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6659 alcCloseDevice(dev); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6660 ALmixer_Initialized = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6661 Number_of_Channels_global = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6662 return AL_FALSE; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6663 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6664 |
0 | 6665 /* Allocate memory for the list of channels */ |
6666 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
6667 if(NULL == ALmixer_Channel_List) | |
6668 { | |
6669 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
|
6670 LinkedList_Free(s_listOfALmixerData); |
0 | 6671 alcDestroyContext(context); |
6672 alcCloseDevice(dev); | |
6673 ALmixer_Initialized = 0; | |
6674 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6675 return AL_FALSE; |
0 | 6676 } |
6677 | |
6678 /* Allocate memory for the list of sources that map to the channels */ | |
6679 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
6680 if(NULL == Source_Map_List) | |
6681 { | |
6682 ALmixer_SetError("Out of Memory for Source Map List"); | |
6683 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6684 LinkedList_Free(s_listOfALmixerData); |
0 | 6685 alcDestroyContext(context); |
6686 alcCloseDevice(dev); | |
6687 ALmixer_Initialized = 0; | |
6688 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6689 return AL_FALSE; |
0 | 6690 } |
6691 | |
6692 /* Create array that will hold the sources */ | |
6693 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
6694 if(NULL == source) | |
6695 { | |
6696 ALmixer_SetError("Out of Memory for sources"); | |
6697 free(Source_Map_List); | |
6698 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6699 LinkedList_Free(s_listOfALmixerData); |
0 | 6700 alcDestroyContext(context); |
6701 alcCloseDevice(dev); | |
6702 ALmixer_Initialized = 0; | |
6703 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6704 return AL_FALSE; |
0 | 6705 } |
6706 | |
6707 /* Clear the error state */ | |
6708 alGetError(); | |
6709 /* Generate the OpenAL sources */ | |
6710 alGenSources(Number_of_Channels_global, source); | |
6711 if( (error=alGetError()) != AL_NO_ERROR) | |
6712 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6713 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 6714 free(ALmixer_Channel_List); |
6715 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6716 LinkedList_Free(s_listOfALmixerData); |
0 | 6717 alcDestroyContext(context); |
6718 alcCloseDevice(dev); | |
6719 ALmixer_Initialized = 0; | |
6720 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6721 return AL_FALSE; |
0 | 6722 } |
6723 | |
6724 /* Initialize each channel and associate one source to one channel */ | |
6725 for(i=0; i<Number_of_Channels_global; i++) | |
6726 { | |
6727 if(0 == source[i]) | |
6728 { | |
6729 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"); | |
6730 } | |
6731 | |
6732 Init_Channel(i); | |
6733 /* Keeping the source allocation out of the Init function | |
6734 * in case I want to reuse the Init | |
6735 * function for resetting data | |
6736 */ | |
6737 ALmixer_Channel_List[i].alsource = source[i]; | |
6738 /* Now also keep a copy of the source to channel mapping | |
6739 * in case we need to look up a channel from the source | |
6740 * instead of a source from a channel | |
6741 */ | |
6742 Source_Map_List[i].source = source[i]; | |
6743 Source_Map_List[i].channel = i; | |
6744 /* Clean the channel because there are some things that need to | |
6745 * be done that can't happen until the source is set | |
6746 */ | |
6747 Clean_Channel(i); | |
6748 } | |
6749 | |
6750 /* The Source_Map_List must be sorted by source for binary searches | |
6751 */ | |
6752 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
6753 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6754 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6755 ALmixer_OutputDecoders(); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6756 */ |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6757 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6758 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6759 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6760 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6761 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6762 if(NULL == s_simpleLock) |
0 | 6763 { |
6764 /* SDL sets the error message already? */ | |
6765 free(source); | |
6766 free(ALmixer_Channel_List); | |
6767 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6768 LinkedList_Free(s_listOfALmixerData); |
0 | 6769 alcDestroyContext(context); |
6770 alcCloseDevice(dev); | |
6771 ALmixer_Initialized = 0; | |
6772 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6773 return AL_FALSE; |
0 | 6774 } |
6775 | |
6776 | |
6777 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
6778 if(NULL == Stream_Thread_global) | |
6779 { | |
6780 /* 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
|
6781 SDL_DestroyMutex(s_simpleLock); |
0 | 6782 free(source); |
6783 free(ALmixer_Channel_List); | |
6784 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6785 LinkedList_Free(s_listOfALmixerData); |
0 | 6786 alcDestroyContext(context); |
6787 alcCloseDevice(dev); | |
6788 ALmixer_Initialized = 0; | |
6789 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6790 return AL_FALSE; |
0 | 6791 } |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
6792 |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
6793 /* 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
|
6794 Internal_LowerThreadPriority(Stream_Thread_global); |
0 | 6795 |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6796 /* |
0 | 6797 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6798 */ |
0 | 6799 #endif /* End of ENABLE_ALMIXER_THREADS */ |
6800 | |
6801 /* We don't need this array any more because all the sources | |
6802 * are connected to channels | |
6803 */ | |
6804 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6805 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6806 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6807 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6808 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6809 ALboolean ALmixer_InitContext(ALuint frequency, ALuint refresh) |
0 | 6810 { |
6811 ALCdevice* dev; | |
6812 ALCcontext* context; | |
6813 ALCenum error; | |
6814 | |
6815 #ifdef USING_LOKI_AL_DIST | |
6816 /* The Loki dist requires that I set both the | |
6817 * device and context frequency values separately | |
6818 */ | |
6819 /* Hope this won't overflow */ | |
6820 char device_string[256]; | |
6821 #endif | |
6822 | |
6823 /* (Venting frustration) Damn it! Nobody bothered | |
6824 * documenting how you're supposed to use an attribute | |
6825 * list. In fact, the not even the Loki test program | |
6826 * writers seem to know because they use it inconsistently. | |
6827 * For example, how do you terminate that attribute list? | |
6828 * The Loki test code does it 3 different ways. They | |
6829 * set the last value to 0, or they set it to ALC_INVALID, | |
6830 * or they set two final values: ALC_INVALID, 0 | |
6831 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6832 * but with Creative Labs ALC_INVALID is -1. | |
6833 * So something's going to break. Loki's source | |
6834 * code says to terminate with ALC_INVALID. But I | |
6835 * don't know if that's really true, or it happens | |
6836 * to be a coinicidence because it's defined to 0. | |
6837 * Creative provides no source code, so I can't look at how | |
6838 * they terminate it. | |
6839 * So this is really, really ticking me off... | |
6840 * For now, I'm going to use ALC_INVALID. | |
6841 * (Update...after further review of the API spec, | |
6842 * it seems that a NULL terminated string is the correct | |
6843 * termination value to use, so 0 it is.) | |
6844 */ | |
6845 #if 0 | |
6846 ALint attrlist[] = { | |
6847 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6848 /* Don't know anything about these values. | |
6849 * Trust defaults? */ | |
6850 /* Supposed to be the refresh rate in Hz. | |
6851 * I think 15-120 are supposed to be good | |
6852 * values. Though I haven't gotten any effect except | |
6853 * for one strange instance on a Mac. But it was | |
6854 * unrepeatable. | |
6855 */ | |
6856 #if 0 | |
6857 ALC_REFRESH, 15, | |
6858 #endif | |
6859 /* Sync requires a alcProcessContext() call | |
6860 * for every cycle. By default, this is | |
6861 * not used and the value is AL_FALSE | |
6862 * because it will probably perform | |
6863 * pretty badly for me. | |
6864 */ | |
6865 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6866 ALC_SYNC, AL_TRUE, | |
6867 #else | |
6868 ALC_SYNC, AL_FALSE, | |
6869 #endif | |
6870 /* Looking at the API spec, it implies | |
6871 * that the list be a NULL terminated string | |
6872 * so it's probably not safe to use ALC_INVALID | |
6873 */ | |
6874 /* | |
6875 ALC_INVALID }; | |
6876 */ | |
6877 '\0'}; | |
6878 #endif | |
6879 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6880 * However, if no value is specified, I don't | |
6881 * want it in the list so I can get the OpenAL defaults | |
6882 */ | |
6883 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6884 ALsizei current_attrlist_index = 0; |
0 | 6885 |
6886 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6887 /* More problems: I'm getting bit by endian/signedness issues on | |
6888 * different platforms. I can find the endianess easily enough, | |
6889 * but I don't know how to determine what the correct signedness | |
6890 * is (if such a thing exists). I do know that if I try using | |
6891 * unsigned on OSX with an originally signed sample, I get | |
6892 * distortion. However, I don't have any native unsigned samples | |
6893 * to test. But I'm assuming that the platform must be in the | |
6894 * correct signedness no matter what. | |
6895 * I can either assume everybody is signed, or I can try to | |
6896 * determine the value. If I try to determine the values, | |
6897 * I think my only ability to figure it out will be to open | |
6898 * SDL_Audio, and read what the obtained settings were. | |
6899 * Then shutdown everything. However, I don't even know how | |
6900 * reliable this is. | |
6901 * Update: I think I resolved the issues...forgot to update | |
6902 * these comments when it happened. I should check the revision control | |
6903 * log... Anyway, I think the issue was partly related to me not | |
6904 * doing something correctly with the AudioInfo or some kind | |
6905 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6906 * revision control, I think I might have assumed that SDL_Sound would | |
6907 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6908 * and had to fill one out myself. | |
6909 */ | |
6910 SDL_AudioSpec desired; | |
6911 SDL_AudioSpec obtained; | |
6912 #endif | |
6913 | |
6914 | |
6915 | |
6916 | |
6917 /* Make sure ALmixer isn't already initialized */ | |
6918 if(ALmixer_Initialized) | |
6919 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6920 return AL_FALSE; |
0 | 6921 } |
6922 | |
6923 /* Set the defaults */ | |
6924 attrlist[0] = ALC_FREQUENCY; | |
6925 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6926 attrlist[2] = ALC_SYNC; | |
6927 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6928 attrlist[3] = ALC_TRUE; | |
6929 #else | |
6930 attrlist[3] = ALC_FALSE; | |
6931 #endif | |
6932 /* Set frequency value if it is not 0 */ | |
6933 if(0 != frequency) | |
6934 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6935 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6936 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6937 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6938 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6939 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6940 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6941 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6942 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6943 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6944 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6945 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6946 #endif |
0 | 6947 |
6948 /* If the user specifies a refresh value, | |
6949 * make room for it | |
6950 */ | |
6951 if(0 != refresh) | |
6952 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6953 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
|
6954 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6955 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6956 current_attrlist_index++; |
0 | 6957 } |
6958 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6959 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6960 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6961 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6962 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6963 |
0 | 6964 /* Initialize SDL_Sound */ |
6965 if(! Sound_Init() ) | |
6966 { | |
6967 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6968 return AL_FALSE; |
0 | 6969 } |
6970 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6971 /* Here is the paranoid check that opens | |
6972 * SDL audio in an attempt to find the correct | |
6973 * system values. | |
6974 */ | |
6975 /* Doesn't have to be the actual value I think | |
6976 * (as long as it doesn't influence format, in | |
6977 * which case I'm probably screwed anyway because OpenAL | |
6978 * may easily choose to do something else). | |
6979 */ | |
6980 desired.freq = 44100; | |
6981 desired.channels = 2; | |
6982 desired.format = AUDIO_S16SYS; | |
6983 desired.callback = my_dummy_audio_callback; | |
6984 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6985 { | |
6986 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6987 /* Now to get really paranoid, we should probably | |
6988 * also assume that the 8bit format is also the | |
6989 * same sign type and set that value | |
6990 */ | |
6991 if(AUDIO_S16SYS == obtained.format) | |
6992 { | |
6993 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6994 } | |
6995 /* Should be AUDIO_U16SYS */ | |
6996 else | |
6997 { | |
6998 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6999 } | |
7000 SDL_CloseAudio(); | |
7001 } | |
7002 else | |
7003 { | |
7004 /* Well, I guess I'm in trouble. I guess it's my best guess | |
7005 */ | |
7006 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
7007 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
7008 } | |
7009 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7010 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7011 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 7012 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
7013 * causes OpenAL and SMPEG to conflict. For some reason | |
7014 * if SDL_Init on audio is active, then all the SMPEG | |
7015 * decoded sound comes out silent. Unfortunately, | |
7016 * Sound_Init() invokes SDL_Init on audio. I'm | |
7017 * not sure why it actually needs it... | |
7018 * But we'll attempt to disable it here after the | |
7019 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
7020 */ | |
7021 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7022 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7023 |
0 | 7024 /* I'm told NULL will call the default string |
7025 * and hopefully do the right thing for each platform | |
7026 */ | |
7027 /* | |
7028 dev = alcOpenDevice( NULL ); | |
7029 */ | |
7030 /* Now I'm told I need to set both the device and context | |
7031 * to have the same sampling rate, so I must pass a string | |
7032 * to OpenDevice(). I don't know how portable these strings are. | |
7033 * I don't even know if the format for strings is | |
7034 * compatible | |
7035 * From the testattrib.c in the Loki test section | |
7036 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
7037 */ | |
7038 | |
7039 #ifdef USING_LOKI_AL_DIST | |
7040 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
7041 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
7042 #else | |
7043 dev = alcOpenDevice( NULL ); | |
7044 #endif | |
7045 if(NULL == dev) | |
7046 { | |
7047 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
|
7048 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7049 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7050 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7051 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7052 /* 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
|
7053 /* 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
|
7054 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7055 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7056 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7057 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7058 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
|
7059 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7060 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
|
7061 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7062 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7063 |
0 | 7064 |
7065 context = alcCreateContext(dev, attrlist); | |
7066 if(NULL == context) | |
7067 { | |
7068 ALmixer_SetError("Cannot create a context OpenAL"); | |
7069 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7070 return AL_FALSE; |
0 | 7071 } |
7072 | |
7073 | |
7074 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
7075 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
7076 * According to Garin Hiebert, this is actually an inconsistency | |
7077 * in the Loki version. The function should return a boolean. | |
7078 * instead of ALC_NO_ERROR. Garin suggested I check via | |
7079 * alcGetError(). | |
7080 */ | |
7081 /* clear the error */ | |
7082 alcGetError(dev); | |
7083 alcMakeContextCurrent(context); | |
7084 | |
7085 error = alcGetError(dev); | |
7086 if( (ALC_NO_ERROR != error) ) | |
7087 { | |
7088 ALmixer_SetError("Could not MakeContextCurrent"); | |
7089 alcDestroyContext(context); | |
7090 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7091 return AL_FALSE; |
0 | 7092 } |
7093 | |
7094 | |
7095 #if 0 | |
7096 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
7097 if(alcGetCurrentContext() != context) | |
7098 { | |
7099 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
7100 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
7101 * I think this is a bug in the OpenAL implementation. | |
7102 */ | |
7103 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
7104 | |
7105 fprintf(stderr, "Making context current\n"); | |
7106 #ifndef __APPLE__ | |
7107 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
7108 #else | |
7109 if(!alcMakeContextCurrent(context)) | |
7110 #endif | |
7111 { | |
7112 ALmixer_SetError("Could not MakeContextCurrent"); | |
7113 alcDestroyContext(context); | |
7114 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7115 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7116 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7117 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7118 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7119 #endif |
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 /* 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
|
7122 * 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
|
7123 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7124 * 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
|
7125 * 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
|
7126 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7127 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7128 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7129 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
|
7130 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7131 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
|
7132 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7133 #endif |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7134 |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7135 |
0 | 7136 |
7137 /* Saw this in the README with the OS X OpenAL distribution. | |
7138 * It looked interesting and simple, so I thought I might | |
7139 * try it out. | |
7140 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
7141 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
7142 * Audio format, the audio data passed to the | |
7143 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
7144 * usage by removing an audio data conversion | |
7145 * (per source) at render timem at the expense of a larger memory footprint. | |
7146 * | |
7147 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
7148 * setting will be applied to all subsequent | |
7149 * calls to alBufferData(). | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7150 * 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
|
7151 * Rather than deal with it right now, I think I am going to make it an opt-in thing. |
0 | 7152 */ |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7153 #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
|
7154 /* |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7155 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
|
7156 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7157 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7158 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7159 #else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7160 /* 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
|
7161 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
|
7162 /* |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7163 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
|
7164 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7165 if(0 != convert_data_enum) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7166 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7167 alEnable(convert_data_enum); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7168 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7169 if( (AL_NO_ERROR != alGetError()) ) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7170 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7171 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
|
7172 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
|
7173 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7174 #endif |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7175 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7176 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7177 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7178 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7179 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7180 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7181 ALboolean ALmixer_InitMixer(ALuint num_sources) |
0 | 7182 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7183 ALint i; |
0 | 7184 ALenum error; |
7185 ALuint* source; | |
7186 | |
7187 | |
7188 ALmixer_Initialized = 1; | |
7189 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7190 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7191 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7192 ALmixer_InitTime(); |
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 /* 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
|
7195 /* 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
|
7196 * 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
|
7197 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7198 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7199 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7200 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7201 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7202 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7203 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7204 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7205 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7206 } |
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 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7209 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7210 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
|
7211 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
|
7212 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7213 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7214 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7215 if(num_sources == 0) |
0 | 7216 { |
7217 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
7218 } | |
7219 else | |
7220 { | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7221 Number_of_Channels_global = (ALint)num_sources; |
0 | 7222 } |
7223 Number_of_Reserve_Channels_global = 0; | |
7224 Is_Playing_global = 0; | |
7225 /* Set to Null in case system quit and was reinitialized */ | |
7226 Channel_Done_Callback = NULL; | |
7227 Channel_Done_Callback_Userdata = NULL; | |
7228 Channel_Data_Callback = NULL; | |
1 | 7229 Channel_Data_Callback_Userdata = NULL; |
0 | 7230 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7231 /* Allocate memory for linked list of ALmixerData. */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7232 s_listOfALmixerData = LinkedList_Create(); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7233 if(NULL == s_listOfALmixerData) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7234 { |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7235 ALmixer_SetError("Couldn't create linked list"); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7236 ALmixer_Initialized = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7237 Number_of_Channels_global = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7238 return AL_FALSE; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7239 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7240 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7241 |
0 | 7242 /* Allocate memory for the list of channels */ |
7243 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
7244 if(NULL == ALmixer_Channel_List) | |
7245 { | |
7246 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
|
7247 LinkedList_Free(s_listOfALmixerData); |
0 | 7248 ALmixer_Initialized = 0; |
7249 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7250 return AL_FALSE; |
0 | 7251 } |
7252 | |
7253 /* Allocate memory for the list of sources that map to the channels */ | |
7254 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
7255 if(NULL == Source_Map_List) | |
7256 { | |
7257 ALmixer_SetError("Out of Memory for Source Map List"); | |
7258 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7259 LinkedList_Free(s_listOfALmixerData); |
0 | 7260 ALmixer_Initialized = 0; |
7261 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7262 return AL_FALSE; |
0 | 7263 } |
7264 | |
7265 /* Create array that will hold the sources */ | |
7266 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
7267 if(NULL == source) | |
7268 { | |
7269 ALmixer_SetError("Out of Memory for sources"); | |
7270 free(Source_Map_List); | |
7271 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7272 LinkedList_Free(s_listOfALmixerData); |
0 | 7273 ALmixer_Initialized = 0; |
7274 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7275 return AL_FALSE; |
0 | 7276 } |
7277 | |
7278 /* Clear the error state */ | |
7279 alGetError(); | |
7280 /* Generate the OpenAL sources */ | |
7281 alGenSources(Number_of_Channels_global, source); | |
7282 if( (error=alGetError()) != AL_NO_ERROR) | |
7283 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7284 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 7285 free(ALmixer_Channel_List); |
7286 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7287 LinkedList_Free(s_listOfALmixerData); |
0 | 7288 ALmixer_Initialized = 0; |
7289 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7290 return AL_FALSE; |
0 | 7291 } |
7292 | |
7293 /* Initialize each channel and associate one source to one channel */ | |
7294 for(i=0; i<Number_of_Channels_global; i++) | |
7295 { | |
7296 Init_Channel(i); | |
7297 /* Keeping the source allocation out of the Init function | |
7298 * in case I want to reuse the Init | |
7299 * function for resetting data | |
7300 */ | |
7301 ALmixer_Channel_List[i].alsource = source[i]; | |
7302 /* Now also keep a copy of the source to channel mapping | |
7303 * in case we need to look up a channel from the source | |
7304 * instead of a source from a channel | |
7305 */ | |
7306 Source_Map_List[i].source = source[i]; | |
7307 Source_Map_List[i].channel = i; | |
7308 /* Clean the channel because there are some things that need to | |
7309 * be done that can't happen until the source is set | |
7310 */ | |
7311 Clean_Channel(i); | |
7312 } | |
7313 | |
7314 /* The Source_Map_List must be sorted by source for binary searches | |
7315 */ | |
7316 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
7317 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7318 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7319 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7320 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7321 if(NULL == s_simpleLock) |
0 | 7322 { |
7323 /* SDL sets the error message already? */ | |
7324 free(source); | |
7325 free(ALmixer_Channel_List); | |
7326 free(Source_Map_List); | |
7327 ALmixer_Initialized = 0; | |
7328 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7329 return AL_FALSE; |
0 | 7330 } |
7331 | |
7332 | |
7333 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
7334 if(NULL == Stream_Thread_global) | |
7335 { | |
7336 /* 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
|
7337 SDL_DestroyMutex(s_simpleLock); |
0 | 7338 free(source); |
7339 free(ALmixer_Channel_List); | |
7340 free(Source_Map_List); | |
7341 ALmixer_Initialized = 0; | |
7342 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7343 return AL_FALSE; |
0 | 7344 } |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
7345 |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
7346 /* 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
|
7347 Internal_LowerThreadPriority(Stream_Thread_global); |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
7348 |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7349 /* |
0 | 7350 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7351 */ |
0 | 7352 #endif /* End of ENABLE_ALMIXER_THREADS */ |
7353 | |
7354 /* We don't need this array any more because all the sources | |
7355 * are connected to channels | |
7356 */ | |
7357 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7358 return AL_TRUE; |
0 | 7359 } |
7360 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7361 void ALmixer_BeginInterruption() |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7362 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7363 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7364 SDL_LockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7365 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7366 s_interruptionContext = alcGetCurrentContext(); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7367 if(NULL != s_interruptionContext) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7368 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7369 /* iOS alcSuspendContext is a no-op */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7370 alcSuspendContext(s_interruptionContext); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7371 alcMakeContextCurrent(NULL); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7372 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7373 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7374 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7375 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7376 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7377 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7378 void ALmixer_EndInterruption() |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7379 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7380 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7381 SDL_LockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7382 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7383 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7384 /* Note: iOS, you need to set the AudioSession active. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7385 * But if the AudioSession is not initialized, this SetActive |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7386 * call fails. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7387 * 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
|
7388 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7389 /* |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7390 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7391 OSStatus the_error = AudioSessionSetActive(true); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7392 if(noErr != the_error) |
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 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
|
7395 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7396 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7397 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7398 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7399 if(NULL != s_interruptionContext) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7400 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7401 alcMakeContextCurrent(s_interruptionContext); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7402 alcProcessContext(s_interruptionContext); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7403 s_interruptionContext = NULL; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7404 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7405 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7406 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7407 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7408 } |
0 | 7409 |
7410 /* Keep the return value void to allow easy use with | |
7411 * atexit() | |
7412 */ | |
7413 void ALmixer_Quit() | |
7414 { | |
7415 ALCcontext* context; | |
7416 ALCdevice* dev; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7417 ALint i; |
0 | 7418 |
7419 if( ! ALmixer_Initialized) | |
7420 { | |
7421 return; | |
7422 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7423 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7424 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7425 #endif |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7426 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7427 /* Several things we need to do: |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7428 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
|
7429 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
|
7430 Next, we should delete the OpenAL sources. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7431 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
|
7432 Finally, we can delete the OpenAL context. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7433 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7434 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7435 context = alcGetCurrentContext(); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7436 if(NULL == context) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7437 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7438 /* 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
|
7439 if(NULL == s_interruptionContext) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7440 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7441 /* Nothing left to try. I think we're done. */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7442 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
|
7443 return; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7444 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7445 else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7446 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7447 context = s_interruptionContext; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7448 /* reactivate the context so we can call OpenAL functions */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7449 alcMakeContextCurrent(context); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7450 s_interruptionContext = NULL; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7451 } |
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 |
0 | 7454 /* Shutdown everything before closing context */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7455 Internal_HaltChannel(-1, AL_FALSE); |
0 | 7456 |
7457 /* This flag will cause the thread to terminate */ | |
7458 ALmixer_Initialized = 0; | |
7459 #ifdef ENABLE_ALMIXER_THREADS | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7460 SDL_UnlockMutex(s_simpleLock); |
0 | 7461 SDL_WaitThread(Stream_Thread_global, NULL); |
7462 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7463 SDL_DestroyMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7464 #endif |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7465 |
0 | 7466 /* Delete all the OpenAL sources */ |
7467 for(i=0; i<Number_of_Channels_global; i++) | |
7468 { | |
7469 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
7470 } | |
7471 /* Delete all the channels */ | |
7472 free(ALmixer_Channel_List); | |
7473 free(Source_Map_List); | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7474 |
0 | 7475 /* Reset the Number_of_Channels just in case somebody |
7476 * tries using a ALmixer function. | |
7477 * I probably should put "Initialized" checks everywhere, | |
7478 * but I'm too lazy at the moment. | |
7479 */ | |
7480 Number_of_Channels_global = 0; | |
7481 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7482 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7483 /* 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
|
7484 * 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
|
7485 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7486 while(LinkedList_Size(s_listOfALmixerData) > 0) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7487 { |
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
|
7488 /* 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
|
7489 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
|
7490 ALmixer_FreeData(almixer_data); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7491 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7492 LinkedList_Free(s_listOfALmixerData); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7493 s_listOfALmixerData = NULL; |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7494 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7495 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7496 /* 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
|
7497 dev = alcGetContextsDevice(context); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7498 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7499 alcMakeContextCurrent(NULL); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7500 alcDestroyContext(context); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7501 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7502 if(NULL == dev) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7503 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7504 return; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7505 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7506 alcCloseDevice(dev); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7507 |
0 | 7508 Sound_Quit(); |
7509 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7510 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7511 /* 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
|
7512 TError_FreeErrorPool(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7513 s_ALmixerErrorPool = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7514 #endif |
0 | 7515 return; |
7516 } | |
7517 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7518 ALboolean ALmixer_IsInitialized() |
0 | 7519 { |
7520 return ALmixer_Initialized; | |
7521 } | |
7522 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7523 ALuint ALmixer_GetFrequency() |
0 | 7524 { |
7525 return ALmixer_Frequency_global; | |
7526 } | |
7527 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7528 const ALmixer_version* ALmixer_GetLinkedVersion() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7529 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7530 static ALmixer_version linked_mixver; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7531 ALMIXER_GET_COMPILED_VERSION(&linked_mixver); |
0 | 7532 return(&linked_mixver); |
7533 } | |
7534 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7535 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7536 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7537 const char* ALmixer_GetError() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7538 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7539 const char* error_string = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7540 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7541 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7542 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
|
7543 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7544 error_string = TError_GetLastErrorStr(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7545 /* 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
|
7546 if(NULL == error_string) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7547 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7548 return ""; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7549 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7550 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7551 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7552 return error_string; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7553 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7554 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7555 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7556 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
|
7557 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7558 if(NULL == s_ALmixerErrorPool) |
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 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
|
7561 return; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7562 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7563 va_list argp; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7564 va_start(argp, err_str); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7565 // 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
|
7566 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
|
7567 va_end(argp); |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7570 #endif |
0 | 7571 |
7572 | |
7573 | |
7574 | |
7575 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7576 void ALmixer_OutputAttributes() |
0 | 7577 { |
7578 ALint num_flags = 0; | |
7579 ALint* flags = 0; | |
7580 int i; | |
7581 ALCdevice* dev = alcGetContextsDevice( alcGetCurrentContext() ); | |
7582 | |
7583 | |
7584 printf("custom context\n"); | |
7585 | |
7586 alcGetIntegerv(dev, ALC_ATTRIBUTES_SIZE, | |
7587 sizeof num_flags, &num_flags ); | |
7588 | |
7589 printf("Number of Flags: %d\n", num_flags); | |
7590 | |
7591 if(num_flags) | |
7592 { | |
7593 flags = malloc(sizeof(num_flags) * sizeof(ALint)); | |
7594 | |
7595 alcGetIntegerv(dev, ALC_ALL_ATTRIBUTES, | |
7596 sizeof num_flags * sizeof(ALint), | |
7597 flags ); | |
7598 } | |
7599 for(i = 0; i < num_flags-1; i += 2) | |
7600 { | |
7601 printf("key 0x%x : value %d\n", | |
7602 flags[i], flags[i+1]); | |
7603 } | |
7604 free(flags); | |
7605 } | |
7606 #endif | |
7607 | |
7608 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7609 void ALmixer_OutputDecoders() |
0 | 7610 { |
7611 Sound_Version sound_compile_version; | |
7612 Sound_Version sound_link_version; | |
7613 | |
7614 const Sound_DecoderInfo **rc = Sound_AvailableDecoders(); | |
7615 const Sound_DecoderInfo **i; | |
7616 const char **ext; | |
7617 FILE* stream = stdout; | |
7618 | |
7619 | |
7620 fprintf(stream, "SDL_sound Information:\n"); | |
7621 | |
7622 SOUND_VERSION(&sound_compile_version); | |
7623 fprintf(stream, "\tCompiled with SDL_sound version: %d.%d.%d\n", | |
7624 sound_compile_version.major, | |
7625 sound_compile_version.minor, | |
7626 sound_compile_version.patch); | |
7627 | |
7628 Sound_GetLinkedVersion(&sound_link_version); | |
7629 fprintf(stream, "\tRunning (linked) with SDL_sound version: %d.%d.%d\n", | |
7630 sound_link_version.major, | |
7631 sound_link_version.minor, | |
7632 sound_link_version.patch); | |
7633 | |
7634 fprintf(stream, "Supported sound formats:\n"); | |
7635 if (rc == NULL) | |
7636 fprintf(stream, " * Apparently, NONE!\n"); | |
7637 else | |
7638 { | |
7639 for (i = rc; *i != NULL; i++) | |
7640 { | |
7641 fprintf(stream, " * %s\n", (*i)->description); | |
7642 | |
7643 for (ext = (*i)->extensions; *ext != NULL; ext++) | |
7644 fprintf(stream, " File extension \"%s\"\n", *ext); | |
7645 | |
7646 fprintf(stream, " Written by %s.\n %s\n\n", | |
7647 (*i)->author, (*i)->url); | |
7648 } /* for */ | |
7649 } /* else */ | |
7650 | |
7651 fprintf(stream, "\n"); | |
7652 } | |
7653 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7654 void ALmixer_OutputOpenALInfo() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7655 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7656 ALmixer_version mixer_compile_version; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7657 const ALmixer_version * mixer_link_version=ALmixer_GetLinkedVersion(); |
0 | 7658 FILE* stream = stdout; |
7659 | |
7660 fprintf(stream, "OpenAL Information:\n"); | |
7661 fprintf(stream, "\tAL_VENDOR: %s\n", alGetString( AL_VENDOR ) ); | |
7662 fprintf(stream, "\tAL_VERSION: %s\n", alGetString( AL_VERSION ) ); | |
7663 fprintf(stream, "\tAL_RENDERER: %s\n", alGetString( AL_RENDERER ) ); | |
7664 fprintf(stream, "\tAL_EXTENSIONS: %s\n", alGetString( AL_EXTENSIONS ) ); | |
7665 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7666 ALMIXER_GET_COMPILED_VERSION(&mixer_compile_version); |
0 | 7667 fprintf(stream, "\nSDL_ALmixer Information:\n"); |
7668 fprintf(stream, "\tCompiled with SDL_ALmixer version: %d.%d.%d\n", | |
7669 mixer_compile_version.major, | |
7670 mixer_compile_version.minor, | |
7671 mixer_compile_version.patch); | |
7672 | |
7673 fprintf(stream, "\tRunning (linked) with SDL_ALmixer version: %d.%d.%d\n", | |
7674 mixer_link_version->major, | |
7675 mixer_link_version->minor, | |
7676 mixer_link_version->patch); | |
7677 | |
7678 fprintf(stream, "\tCompile flags: "); | |
7679 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
7680 fprintf(stream, "ENABLE_LOKI_QUEUE_FIX_HACK "); | |
7681 #endif | |
7682 #ifdef ENABLE_ALMIXER_THREADS | |
7683 fprintf(stream, "ENABLE_ALMIXER_THREADS "); | |
7684 #endif | |
7685 #ifdef ENABLE_ALC_SYNC | |
7686 fprintf(stream, "ENABLE_ALC_SYNC "); | |
7687 #endif | |
7688 fprintf(stream, "\n"); | |
7689 } | |
7690 | |
7691 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7692 ALint ALmixer_AllocateChannels(ALint numchans) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7693 { |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7694 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7695 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7696 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7697 } |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7698 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7699 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7700 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7701 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7702 #endif |
0 | 7703 retval = Internal_AllocateChannels(numchans); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7704 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7705 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7706 #endif |
0 | 7707 return retval; |
7708 } | |
7709 | |
7710 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7711 ALint ALmixer_ReserveChannels(ALint num) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7712 { |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7713 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7714 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7715 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7716 } |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
7717 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7718 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7719 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7720 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7721 #endif |
0 | 7722 retval = Internal_ReserveChannels(num); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7723 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7724 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7725 #endif |
0 | 7726 return retval; |
7727 } | |
7728 | |
7729 | |
7730 | |
7731 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7732 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
|
7733 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7734 ALuint bytes_decoded; |
0 | 7735 ALmixer_Data* ret_data; |
7736 ALenum error; | |
7737 | |
7738 /* Allocate memory */ | |
7739 ret_data = (ALmixer_Data *)malloc(sizeof(ALmixer_Data)); | |
7740 if (NULL == ret_data) | |
7741 { | |
7742 ALmixer_SetError("Out of memory"); | |
7743 return(NULL); | |
7744 } | |
7745 | |
7746 /* Initialize the data fields */ | |
7747 | |
7748 /* Set the Sound_Sample pointer */ | |
7749 ret_data->sample = sample; | |
7750 | |
7751 /* Flag the data to note that it is not in use */ | |
7752 ret_data->in_use = 0; | |
7753 | |
7754 /* Initialize remaining flags */ | |
7755 ret_data->total_time = -1; | |
7756 ret_data->eof = 0; | |
7757 | |
7758 /* Just initialize */ | |
7759 ret_data->num_buffers_in_use = 0; | |
7760 | |
7761 /* Just initialize */ | |
7762 ret_data->total_bytes = 0; | |
7763 | |
7764 /* Just initialize */ | |
7765 ret_data->loaded_bytes = 0; | |
7766 | |
7767 /* Set the max queue buffers (minimum must be 2) */ | |
7768 if(max_queue_buffers < 2) | |
7769 { | |
7770 max_queue_buffers = ALMIXER_DEFAULT_QUEUE_BUFFERS; | |
7771 } | |
7772 ret_data->max_queue_buffers = max_queue_buffers; | |
7773 /* Set up the start up buffers */ | |
7774 if(0 == num_startup_buffers) | |
7775 { | |
7776 num_startup_buffers = ALMIXER_DEFAULT_STARTUP_BUFFERS; | |
7777 } | |
7778 /* Make sure start up buffers is less or equal to max_queue_buffers */ | |
7779 if(num_startup_buffers > max_queue_buffers) | |
7780 { | |
7781 num_startup_buffers = max_queue_buffers; | |
7782 } | |
7783 ret_data->num_startup_buffers = num_startup_buffers; | |
7784 | |
7785 ret_data->buffer_map_list = NULL; | |
7786 ret_data->current_buffer = 0; | |
7787 | |
7788 ret_data->circular_buffer_queue = NULL; | |
7789 | |
7790 /* Now decode and load the data into a data chunk */ | |
7791 /* Different cases for Streamed and Predecoded | |
7792 * Streamed might turn into a predecoded if buffersize | |
7793 * is large enough */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7794 if(AL_FALSE == decode_mode_is_predecoded) |
0 | 7795 { |
7796 bytes_decoded = Sound_Decode(sample); | |
7797 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7798 { | |
7799 ALmixer_SetError(Sound_GetError()); | |
7800 Sound_FreeSample(sample); | |
7801 free(ret_data); | |
7802 return NULL; | |
7803 } | |
7804 | |
7805 /* If no data, return an error */ | |
7806 if(0 == bytes_decoded) | |
7807 { | |
7808 ALmixer_SetError("File has no data"); | |
7809 Sound_FreeSample(sample); | |
7810 free(ret_data); | |
7811 return NULL; | |
7812 } | |
7813 | |
7814 /* Note, currently, my Ogg conservative modifications | |
7815 * prevent EOF from being detected in the first read | |
7816 * because of the weird packet behavior of ov_read(). | |
7817 * The EAGAIN will get set, but not the EOF. | |
7818 * I don't know the best way to handle this, | |
7819 * so for now, Ogg's can only be explicitly | |
7820 * predecoded. | |
7821 */ | |
7822 | |
7823 /* Correction: Since we no longer actually keep the | |
7824 * streamed data we read here (we rewind and throw | |
7825 * it away, and start over on Play), it is | |
7826 * safe to read another chunk to see if we've hit EOF | |
7827 */ | |
7828 if(sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
7829 { | |
7830 bytes_decoded = Sound_Decode(sample); | |
7831 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7832 { | |
7833 ALmixer_SetError(Sound_GetError()); | |
7834 Sound_FreeSample(sample); | |
7835 free(ret_data); | |
7836 return NULL; | |
7837 } | |
7838 } | |
7839 | |
7840 | |
7841 /* If we found an EOF, the entire file was | |
7842 * decoded, so we can treat it like one. | |
7843 */ | |
7844 | |
7845 if(sample->flags & SOUND_SAMPLEFLAG_EOF) | |
7846 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7847 /* |
0 | 7848 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
|
7849 */ |
0 | 7850 ret_data->decoded_all = 1; |
7851 /* Need to keep this information around for | |
7852 * seek and rewind abilities. | |
7853 */ | |
7854 ret_data->total_bytes = bytes_decoded; | |
7855 /* For now, the loaded bytes is the same as total bytes, but | |
7856 * this could change during a seek operation | |
7857 */ | |
7858 ret_data->loaded_bytes = bytes_decoded; | |
7859 | |
7860 /* Let's compute the total playing time | |
7861 * SDL_sound does not yet provide this (we're working on | |
7862 * that at the moment...) | |
7863 */ | |
7864 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
7865 | |
7866 /* Create one element in the buffer array for data for OpanAL */ | |
7867 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
7868 if(NULL == ret_data->buffer) | |
7869 { | |
7870 ALmixer_SetError("Out of Memory"); | |
7871 Sound_FreeSample(sample); | |
7872 free(ret_data); | |
7873 return NULL; | |
7874 } | |
7875 /* Clear the error code */ | |
7876 alGetError(); | |
7877 /* Now generate an OpenAL buffer using that first element */ | |
7878 alGenBuffers(1, ret_data->buffer); | |
7879 if( (error = alGetError()) != AL_NO_ERROR) | |
7880 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7881 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7882 Sound_FreeSample(sample); |
7883 free(ret_data->buffer); | |
7884 free(ret_data); | |
7885 return NULL; | |
7886 } | |
7887 | |
7888 | |
7889 /* Now copy the data to the OpenAL buffer */ | |
7890 /* We can't just set a pointer because the API needs | |
7891 * its own copy to assist hardware acceleration */ | |
7892 alBufferData(ret_data->buffer[0], | |
7893 TranslateFormat(&sample->desired), | |
7894 sample->buffer, | |
7895 bytes_decoded, | |
7896 sample->desired.rate | |
7897 ); | |
7898 if( (error = alGetError()) != AL_NO_ERROR) | |
7899 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7900 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 7901 Sound_FreeSample(sample); |
7902 alDeleteBuffers(1, ret_data->buffer); | |
7903 free(ret_data->buffer); | |
7904 free(ret_data); | |
7905 return NULL; | |
7906 } | |
7907 | |
7908 /* We should be done with the sample since it's all | |
7909 * predecoded. So we can free the memory */ | |
7910 | |
7911 /* Additional notes: | |
7912 * We need to keep data around in case Seek() is needed | |
7913 * or other Sound_AudioInfo is needed. | |
7914 * This can either be done by not deleting the sample, | |
7915 * or it can be done by dynamically recreating it | |
7916 * when we need it. | |
7917 */ | |
7918 /* Since OpenAL won't let us retrieve it | |
7919 * (aka dynamically), we have to keep the Sample | |
7920 * around because since the user requested | |
7921 * streamed and we offered predecoded, | |
7922 * we don't want to mess up the user who | |
7923 * was expecting seek support | |
7924 * So Don't Do anything | |
7925 */ | |
7926 /* | |
7927 if(0 == access_data) | |
7928 { | |
7929 Sound_FreeSample(sample); | |
7930 ret_data->sample = NULL; | |
7931 } | |
7932 */ | |
7933 /* Else, We keep a copy of the sample around. | |
7934 * so don't do anything. | |
7935 */ | |
7936 | |
7937 #if 0 | |
7938 #if defined(DISABLE_PREDECODED_SEEK) | |
7939 Sound_FreeSample(sample); | |
7940 ret_data->sample = NULL; | |
7941 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
7942 Sound_FreeSample(sample); | |
7943 ret_data->sample = NULL; | |
7944 #else | |
7945 /* We keep a copy of the sample around. | |
7946 * so don't do anything. | |
7947 */ | |
7948 #endif | |
7949 #endif | |
7950 /* okay we're done here */ | |
7951 | |
7952 } | |
7953 /* Else, we need to stream the data, so we'll | |
7954 * create multple buffers for queuing */ | |
7955 else | |
7956 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7957 /* |
0 | 7958 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
|
7959 */ |
0 | 7960 ret_data->decoded_all = 0; |
7961 | |
7962 /* This information is for predecoded. | |
7963 * Set to 0, since we don't know. | |
7964 */ | |
7965 ret_data->total_bytes = 0; | |
7966 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7967 ret_data->total_time = Sound_GetDuration(sample); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7968 |
0 | 7969 /* Create buffers for data |
7970 */ | |
7971 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) * max_queue_buffers); | |
7972 if(NULL == ret_data->buffer) | |
7973 { | |
7974 ALmixer_SetError("Out of Memory"); | |
7975 Sound_FreeSample(sample); | |
7976 free(ret_data); | |
7977 return NULL; | |
7978 } | |
7979 | |
7980 /* Clear the error code */ | |
7981 alGetError(); | |
7982 /* Now generate an OpenAL buffer using that first element */ | |
7983 alGenBuffers(max_queue_buffers, ret_data->buffer); | |
7984 if( (error = alGetError()) != AL_NO_ERROR) | |
7985 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7986 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7987 Sound_FreeSample(sample); |
7988 free(ret_data->buffer); | |
7989 free(ret_data); | |
7990 return NULL; | |
7991 } | |
7992 | |
7993 /* Redesign: Okay, because of the unqueuing problems and such, | |
7994 * I've decided to redesign where and how queuing is handled. | |
7995 * Before, everything was queued up here. However, this | |
7996 * placed a penalty on load and made performance inconsistent | |
7997 * when samples had to be rewound. It did make things easier | |
7998 * to queue because I could let OpenAL decide which buffer | |
7999 * needed to be queued next. | |
8000 * Now, I'm going to push off the queuing to the actual | |
8001 * Play() command. I'm going to add some book keeping, | |
8002 * and allow for additional buffers to be filled at later | |
8003 * times. | |
8004 */ | |
8005 | |
8006 | |
8007 /* So first of all, because of I already decoded the sample | |
8008 * for testing, I need to decide what to do with it. | |
8009 * The best thing would be be to alBufferData() it. | |
8010 * The problem is it may conflict with the rest of | |
8011 * the system because everything now assumes buffers | |
8012 * are entirely stripped (because of the unqueing | |
8013 * problem). | |
8014 * So it looks like I have to do the crappy thing | |
8015 * and throw away the data, and rewind. | |
8016 */ | |
8017 | |
8018 if(0 == Sound_Rewind(ret_data->sample)) | |
8019 { | |
8020 ALmixer_SetError("Cannot use sample for streamed data because it must be rewindable: %s", Sound_GetError() ); | |
8021 Sound_FreeSample(sample); | |
8022 free(ret_data->buffer); | |
8023 free(ret_data); | |
8024 return NULL; | |
8025 } | |
8026 | |
8027 | |
8028 /* If the user has selected access_data, we need to | |
8029 * keep copies of the queuing buffers around because | |
8030 * OpenAL won't let us access the data. | |
8031 * Allocate the memory for the buffers here | |
8032 * and initialize the albuffer-index map | |
8033 */ | |
8034 if(access_data) | |
8035 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8036 ALuint j; |
0 | 8037 /* Create buffers for data access |
8038 * Should be the same number as the number of queue buffers | |
8039 */ | |
1 | 8040 ret_data->buffer_map_list = (ALmixer_Buffer_Map*)malloc( sizeof(ALmixer_Buffer_Map) * max_queue_buffers); |
0 | 8041 if(NULL == ret_data->buffer_map_list) |
8042 { | |
8043 ALmixer_SetError("Out of Memory"); | |
8044 Sound_FreeSample(sample); | |
8045 free(ret_data->buffer); | |
8046 free(ret_data); | |
8047 return NULL; | |
8048 } | |
8049 | |
8050 ret_data->circular_buffer_queue = CircularQueueUnsignedInt_CreateQueue(max_queue_buffers); | |
8051 if(NULL == ret_data->circular_buffer_queue) | |
8052 { | |
8053 ALmixer_SetError("Out of Memory"); | |
8054 free(ret_data->buffer_map_list); | |
8055 Sound_FreeSample(sample); | |
8056 free(ret_data->buffer); | |
8057 free(ret_data); | |
8058 return NULL; | |
8059 } | |
8060 | |
8061 | |
8062 for(j=0; j<max_queue_buffers; j++) | |
8063 { | |
8064 ret_data->buffer_map_list[j].albuffer = ret_data->buffer[j]; | |
8065 ret_data->buffer_map_list[j].index = j; | |
8066 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
|
8067 ret_data->buffer_map_list[j].data = (ALbyte*)malloc( sizeof(ALbyte) * buffersize); |
0 | 8068 if(NULL == ret_data->buffer_map_list[j].data) |
8069 { | |
8070 ALmixer_SetError("Out of Memory"); | |
8071 break; | |
8072 } | |
8073 } | |
8074 /* If an error happened, we have to clean up the memory */ | |
8075 if(j < max_queue_buffers) | |
8076 { | |
8077 fprintf(stderr, "################## Buffer allocation failed\n"); | |
8078 for( ; j>=0; j--) | |
8079 { | |
8080 free(ret_data->buffer_map_list[j].data); | |
8081 } | |
8082 free(ret_data->buffer_map_list); | |
8083 CircularQueueUnsignedInt_FreeQueue(ret_data->circular_buffer_queue); | |
8084 Sound_FreeSample(sample); | |
8085 free(ret_data->buffer); | |
8086 free(ret_data); | |
8087 return NULL; | |
8088 } | |
8089 | |
8090 /* The Buffer_Map_List must be sorted by albuffer for binary searches | |
8091 */ | |
1 | 8092 qsort(ret_data->buffer_map_list, max_queue_buffers, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 8093 } /* End if access_data==true */ |
8094 | |
8095 | |
8096 } /* End of do stream */ | |
8097 } /* end of DECODE_STREAM */ | |
8098 /* 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
|
8099 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
|
8100 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8101 #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
|
8102 /* 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
|
8103 * 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
|
8104 * 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
|
8105 * so looping isn't needed. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8106 * 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
|
8107 * 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
|
8108 * 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
|
8109 * 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
|
8110 * 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
|
8111 * 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
|
8112 * to load a file. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8113 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8114 ALint sound_duration = Sound_GetDuration(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8115 if(sound_duration > 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8116 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8117 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
|
8118 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
|
8119 if(0 == buffer_resize_succeeded) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8120 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8121 ALmixer_SetError(Sound_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8122 Sound_FreeSample(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8123 free(ret_data); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8124 return NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8125 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8126 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8127 #endif /* ALMIXER_DISABLE_PREDECODED_PRECOMPUTE_BUFFER_SIZE_OPTIMIZATION */ |
0 | 8128 bytes_decoded = Sound_DecodeAll(sample); |
8129 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
8130 { | |
8131 ALmixer_SetError(Sound_GetError()); | |
8132 Sound_FreeSample(sample); | |
8133 free(ret_data); | |
8134 return NULL; | |
8135 } | |
8136 | |
8137 /* If no data, return an error */ | |
8138 if(0 == bytes_decoded) | |
8139 { | |
8140 ALmixer_SetError("File has no data"); | |
8141 Sound_FreeSample(sample); | |
8142 free(ret_data); | |
8143 return NULL; | |
8144 } | |
8145 | |
8146 | |
8147 ret_data->decoded_all = 1; | |
8148 /* Need to keep this information around for | |
8149 * seek and rewind abilities. | |
8150 */ | |
8151 ret_data->total_bytes = bytes_decoded; | |
8152 /* For now, the loaded bytes is the same as total bytes, but | |
8153 * this could change during a seek operation | |
8154 */ | |
8155 ret_data->loaded_bytes = bytes_decoded; | |
8156 | |
8157 /* Let's compute the total playing time | |
8158 * SDL_sound does not yet provide this (we're working on | |
8159 * that at the moment...) | |
8160 */ | |
8161 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
8162 | |
8163 /* Create one element in the buffer array for data for OpanAL */ | |
8164 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
8165 if(NULL == ret_data->buffer) | |
8166 { | |
8167 ALmixer_SetError("Out of Memory"); | |
8168 Sound_FreeSample(sample); | |
8169 free(ret_data); | |
8170 return NULL; | |
8171 } | |
8172 /* Clear the error code */ | |
8173 alGetError(); | |
8174 /* Now generate an OpenAL buffer using that first element */ | |
8175 alGenBuffers(1, ret_data->buffer); | |
8176 if( (error = alGetError()) != AL_NO_ERROR) | |
8177 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8178 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 8179 Sound_FreeSample(sample); |
8180 free(ret_data->buffer); | |
8181 free(ret_data); | |
8182 return NULL; | |
8183 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8184 /* |
0 | 8185 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
|
8186 */ |
0 | 8187 /* Now copy the data to the OpenAL buffer */ |
8188 /* We can't just set a pointer because the API needs | |
8189 * its own copy to assist hardware acceleration */ | |
8190 alBufferData(ret_data->buffer[0], | |
8191 TranslateFormat(&sample->desired), | |
8192 sample->buffer, | |
8193 bytes_decoded, | |
8194 sample->desired.rate | |
8195 ); | |
8196 if( (error = alGetError()) != AL_NO_ERROR) | |
8197 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8198 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 8199 Sound_FreeSample(sample); |
8200 alDeleteBuffers(1, ret_data->buffer); | |
8201 free(ret_data->buffer); | |
8202 free(ret_data); | |
8203 return NULL; | |
8204 } | |
8205 | |
8206 /* We should be done with the sample since it's all | |
8207 * predecoded. So we can free the memory */ | |
8208 /* Need to keep around because Seek() needs it */ | |
8209 | |
8210 /* Additional notes: | |
8211 * We need to keep data around in case Seek() is needed | |
8212 * or other Sound_AudioInfo is needed. | |
8213 * This can either be done by not deleting the sample, | |
8214 * or it can be done by dynamically recreating it | |
8215 * when we need it. | |
8216 * Update: I think now it's up to the user by passing the | |
8217 * access_data flag. If they set the flag, then they get | |
8218 * data callbacks and seek support. If not, then they can | |
8219 * get all that stuff at the expense of keeping extra memory | |
8220 * around. | |
8221 */ | |
8222 if(0 == access_data) | |
8223 { | |
8224 Sound_FreeSample(sample); | |
8225 ret_data->sample = NULL; | |
8226 } | |
8227 | |
8228 /* Else, We keep a copy of the sample around. | |
8229 * so don't do anything. | |
8230 */ | |
8231 #if 0 | |
8232 #if defined(DISABLE_PREDECODED_SEEK) | |
8233 Sound_FreeSample(sample); | |
8234 ret_data->sample = NULL; | |
8235 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
8236 Sound_FreeSample(sample); | |
8237 ret_data->sample = NULL; | |
8238 #else | |
8239 /* We keep a copy of the sample around. | |
8240 * so don't do anything. | |
8241 */ | |
8242 #endif | |
8243 #endif | |
8244 | |
8245 /* okay we're done here */ | |
8246 } | |
8247 else | |
8248 { | |
8249 /* Shouldn't get here */ | |
8250 ALmixer_SetError("Unknown decode mode"); | |
8251 Sound_FreeSample(sample); | |
8252 free(ret_data); | |
8253 return NULL; | |
8254 } | |
8255 | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8256 /* 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
|
8257 * 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
|
8258 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8259 LinkedList_PushBack(s_listOfALmixerData, ret_data); |
0 | 8260 return ret_data; |
8261 } | |
8262 | |
8263 | |
8264 /* This will load a sample for us. Most of the uglyness is | |
8265 * error checking and the fact that streamed/predecoded files | |
8266 * must be treated differently. | |
8267 * I don't like the AudioInfo parameter. I removed it once, | |
8268 * but the system will fail on RAW samples because the user | |
8269 * must specify it, so I had to bring it back. | |
8270 * Remember I must close the rwops if there is an error before NewSample() | |
8271 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8272 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 | 8273 { |
8274 Sound_Sample* sample = NULL; | |
8275 Sound_AudioInfo target; | |
8276 | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8277 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8278 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8279 return NULL; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8280 } |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8281 |
0 | 8282 /* Initialize target values to defaults |
8283 * 0 tells SDL_sound to use the "actual" values | |
8284 */ | |
8285 target.channels = 0; | |
8286 target.rate = 0; | |
8287 #if 0 | |
8288 /* This requires my new additions to SDL_sound. It will | |
8289 * convert the sample to the proper endian order. | |
8290 * If the actual is 8-bit, it will do unsigned, if | |
8291 * the actual is 16-bit, it will do signed. | |
8292 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
8293 * in this way. | |
8294 */ | |
8295 target.format = AUDIO_U8S16SYS; | |
8296 #else | |
8297 target.format = AUDIO_S16SYS; | |
8298 #endif | |
8299 | |
8300 /* Set a default buffersize if needed */ | |
8301 if(0 == buffersize) | |
8302 { | |
8303 buffersize = ALMIXER_DEFAULT_BUFFERSIZE; | |
8304 } | |
8305 | |
8306 sample = Sound_NewSample(rwops, fileext, &target, buffersize); | |
8307 if(NULL == sample) | |
8308 { | |
8309 ALmixer_SetError(Sound_GetError()); | |
8310 return NULL; | |
8311 } | |
8312 | |
1 | 8313 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8314 } |
8315 | |
8316 | |
8317 | |
8318 /* This will load a sample for us from | |
8319 * a file (instead of RWops). Most of the uglyness is | |
8320 * error checking and the fact that streamed/predecoded files | |
8321 * must be treated differently. | |
8322 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8323 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 | 8324 { |
8325 Sound_Sample* sample = NULL; | |
8326 Sound_AudioInfo target; | |
8327 | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8328 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8329 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8330 return NULL; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8331 } |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8332 |
0 | 8333 /* Initialize target values to defaults |
8334 * 0 tells SDL_sound to use the "actual" values | |
8335 */ | |
8336 target.channels = 0; | |
8337 target.rate = 0; | |
8338 | |
8339 #if 0 | |
8340 /* This requires my new additions to SDL_sound. It will | |
8341 * convert the sample to the proper endian order. | |
8342 * If the actual is 8-bit, it will do unsigned, if | |
8343 * the actual is 16-bit, it will do signed. | |
8344 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
8345 * in this way. | |
8346 */ | |
8347 target.format = AUDIO_U8S16SYS; | |
8348 #else | |
8349 target.format = AUDIO_S16SYS; | |
8350 #endif | |
8351 | |
8352 #if 0 | |
8353 /* Okay, here's a messy hack. The problem is that we need | |
8354 * to convert the sample to have the correct bitdepth, | |
8355 * endian order, and signedness values. | |
8356 * The bit depth is 8 or 16. | |
8357 * The endian order is the native order of the system. | |
8358 * The signedness depends on what the original value | |
8359 * of the sample. Unfortunately, we can't specify these | |
8360 * values until we after we already know what the original | |
8361 * values were for bitdepth and signedness. | |
8362 * So we must open the file once to get the values, | |
8363 * then close it, and then reopen it with the | |
8364 * correct desired target values. | |
8365 * I tried changing the sample->desired field after | |
8366 * the NewSample call, but it had no effect, so | |
8367 * it looks like it must be set on open. | |
8368 */ | |
8369 /* Pick a small buffersize for the first open to not | |
8370 * waste much time allocating memory */ | |
8371 sample = Sound_NewSampleFromFile(filename, NULL, 512); | |
8372 if(NULL == sample) | |
8373 { | |
8374 ALmixer_SetError(Sound_GetError()); | |
8375 return NULL; | |
8376 } | |
8377 | |
8378 bit_depth = GetBitDepth(sample->actual.format); | |
8379 signedness_value = GetSignednessValue(sample->actual.format); | |
8380 if(8 == bit_depth) | |
8381 { | |
8382 /* If 8 bit, then we don't have to worry about | |
8383 * endian issues. We can just use the actual format | |
8384 * value and it should do the right thing | |
8385 */ | |
8386 target.format = sample->actual.format; | |
8387 } | |
8388 else | |
8389 { | |
8390 /* We'll assume it's 16-bit, and if it's not | |
8391 * hopefully SDL_sound will return an error, | |
8392 * or let us convert to 16-bit | |
8393 */ | |
8394 /* Now we need to get the correct signedness */ | |
8395 if(ALMIXER_UNSIGNED_VALUE == signedness_value) | |
8396 { | |
8397 /* Set to Unsigned 16-bit, system endian order */ | |
8398 target.format = AUDIO_U16SYS; | |
8399 } | |
8400 else | |
8401 { | |
8402 /* Again, we'll assume it's Signed 16-bit system order | |
8403 * or force the conversion and hope it works out | |
8404 */ | |
8405 target.format = AUDIO_S16SYS; | |
8406 } | |
8407 } | |
8408 | |
8409 /* Now we have the correct info. We need to close and reopen */ | |
8410 Sound_FreeSample(sample); | |
8411 #endif | |
8412 | |
8413 sample = Sound_NewSampleFromFile(filename, &target, buffersize); | |
8414 if(NULL == sample) | |
8415 { | |
8416 ALmixer_SetError(Sound_GetError()); | |
8417 return NULL; | |
8418 } | |
8419 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8420 /* |
0 | 8421 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
|
8422 */ |
1 | 8423 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8424 } |
8425 | |
8426 | |
8427 /* This is a back door for RAW samples or if you need the | |
8428 * AudioInfo field. Use at your own risk. | |
8429 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8430 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 | 8431 { |
8432 Sound_Sample* sample = NULL; | |
1 | 8433 Sound_AudioInfo sound_desired; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8434 |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8435 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8436 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8437 return NULL; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8438 } |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8439 |
1 | 8440 /* Rather than copying the data from struct to struct, I could just |
8441 * cast the thing since the structs are meant to be identical. | |
8442 * But if SDL_sound changes it's implementation, bad things | |
8443 * will probably happen. (Or if I change my implementation and | |
8444 * forget about the cast, same bad scenario.) Since this is a load | |
8445 * function, performance of this is negligible. | |
8446 */ | |
8447 if(NULL == desired) | |
8448 { | |
8449 sample = Sound_NewSample(rwops, fileext, NULL, buffersize); | |
8450 } | |
8451 else | |
8452 { | |
8453 sound_desired.format = desired->format; | |
8454 sound_desired.channels = desired->channels; | |
8455 sound_desired.rate = desired->rate; | |
8456 sample = Sound_NewSample(rwops, fileext, &sound_desired, buffersize); | |
8457 } | |
0 | 8458 if(NULL == sample) |
8459 { | |
8460 ALmixer_SetError(Sound_GetError()); | |
8461 return NULL; | |
8462 } | |
1 | 8463 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8464 } |
8465 | |
8466 | |
8467 | |
8468 | |
8469 /* This is a back door for RAW samples or if you need the | |
8470 * AudioInfo field. Use at your own risk. | |
8471 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8472 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 | 8473 { |
8474 Sound_Sample* sample = NULL; | |
1 | 8475 Sound_AudioInfo sound_desired; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8476 |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8477 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8478 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8479 return; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8480 } |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8481 |
1 | 8482 /* Rather than copying the data from struct to struct, I could just |
8483 * cast the thing since the structs are meant to be identical. | |
8484 * But if SDL_sound changes it's implementation, bad things | |
8485 * will probably happen. (Or if I change my implementation and | |
8486 * forget about the cast, same bad scenario.) Since this is a load | |
8487 * function, performance of this is negligible. | |
8488 */ | |
8489 if(NULL == desired) | |
8490 { | |
8491 sample = Sound_NewSampleFromFile(filename, NULL, buffersize); | |
8492 } | |
8493 else | |
8494 { | |
8495 sound_desired.format = desired->format; | |
8496 sound_desired.channels = desired->channels; | |
8497 sound_desired.rate = desired->rate; | |
8498 sample = Sound_NewSampleFromFile(filename, &sound_desired, buffersize); | |
8499 } | |
8500 | |
0 | 8501 if(NULL == sample) |
8502 { | |
8503 ALmixer_SetError(Sound_GetError()); | |
8504 return NULL; | |
8505 } | |
1 | 8506 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8507 } |
8508 | |
8509 | |
8510 | |
8511 | |
8512 void ALmixer_FreeData(ALmixer_Data* data) | |
8513 { | |
8514 ALenum error; | |
8515 if(NULL == data) | |
8516 { | |
8517 return; | |
8518 } | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8519 |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8520 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8521 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8522 return; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8523 } |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8524 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8525 /* Bypass if in interruption event */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8526 if(NULL == alcGetCurrentContext()) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8527 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8528 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
|
8529 return; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8530 } |
0 | 8531 |
8532 if(data->decoded_all) | |
8533 { | |
8534 /* If access_data was enabled, then the Sound_Sample* | |
8535 * still exists. We need to free it | |
8536 */ | |
8537 if(data->sample != NULL) | |
8538 { | |
8539 Sound_FreeSample(data->sample); | |
8540 } | |
8541 alDeleteBuffers(1, data->buffer); | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8542 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8543 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8544 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
|
8545 } |
0 | 8546 } |
8547 else | |
8548 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8549 ALuint i; |
0 | 8550 |
8551 /* Delete buffer copies if access_data was enabled */ | |
8552 if(data->buffer_map_list != NULL) | |
8553 { | |
8554 for(i=0; i<data->max_queue_buffers; i++) | |
8555 { | |
8556 free(data->buffer_map_list[i].data); | |
8557 } | |
8558 free(data->buffer_map_list); | |
8559 } | |
8560 if(data->circular_buffer_queue != NULL) | |
8561 { | |
8562 CircularQueueUnsignedInt_FreeQueue(data->circular_buffer_queue); | |
8563 } | |
8564 | |
8565 Sound_FreeSample(data->sample); | |
8566 alDeleteBuffers(data->max_queue_buffers, data->buffer); | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8567 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8568 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8569 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
|
8570 } |
0 | 8571 } |
8572 free(data->buffer); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8573 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8574 LinkedList_Remove(s_listOfALmixerData, |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8575 LinkedList_Find(s_listOfALmixerData, data, NULL) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8576 ); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8577 |
0 | 8578 free(data); |
8579 } | |
8580 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8581 ALint ALmixer_GetTotalTime(ALmixer_Data* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8582 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8583 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8584 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8585 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8586 } |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8587 |
0 | 8588 return data->total_time; |
8589 } | |
8590 | |
8591 /* This function will look up the source for the corresponding channel */ | |
8592 /* 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
|
8593 ALuint ALmixer_GetSource(ALint channel) |
0 | 8594 { |
8595 ALuint retval; | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8596 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8597 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8598 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8599 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8600 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8601 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8602 #endif |
0 | 8603 retval = Internal_GetSource(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8604 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8605 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8606 #endif |
0 | 8607 return retval; |
8608 } | |
8609 | |
8610 /* 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
|
8611 ALint ALmixer_GetChannel(ALuint source) |
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 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8614 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8615 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8616 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8617 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8618 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8619 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8620 #endif |
0 | 8621 retval = Internal_GetChannel(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8622 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8623 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8624 #endif |
0 | 8625 return retval; |
8626 } | |
8627 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8628 ALint ALmixer_FindFreeChannel(ALint start_channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8629 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8630 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8631 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8632 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8633 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8634 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8635 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8636 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8637 #endif |
0 | 8638 retval = Internal_FindFreeChannel(start_channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8639 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8640 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8641 #endif |
0 | 8642 return retval; |
8643 } | |
8644 | |
8645 | |
8646 | |
8647 /* API update function. | |
8648 * It should return the number of buffers that were | |
8649 * queued during the call. The value might be | |
8650 * used to guage how long you might wait to | |
8651 * call the next update loop in case you are worried | |
8652 * about preserving CPU cycles. The idea is that | |
8653 * when a buffer is queued, there was probably some | |
8654 * CPU intensive looping which took awhile. | |
8655 * 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
|
8656 * Timing the call with ALmixer_GetTicks() would produce |
0 | 8657 * more accurate information. |
8658 * Returns a negative value if there was an error, | |
8659 * the value being the number of errors. | |
8660 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8661 ALint ALmixer_Update() |
0 | 8662 { |
8663 #ifdef ENABLE_ALMIXER_THREADS | |
8664 /* The thread will handle all updates by itself. | |
8665 * Don't allow the user to explicitly call update. | |
8666 */ | |
8667 return 0; | |
8668 #else | |
8669 return( Update_ALmixer(NULL) ); | |
8670 #endif | |
8671 } | |
8672 | |
8673 | |
8674 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8675 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
|
8676 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8677 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8678 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8679 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8680 Channel_Done_Callback = playback_finished_callback; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8681 Channel_Done_Callback_Userdata = user_data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8682 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8683 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8684 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8685 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8686 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8687 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8688 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
|
8689 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8690 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8691 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8692 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8693 Channel_Data_Callback = playback_data_callback; |
1 | 8694 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
|
8695 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8696 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8697 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8698 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8699 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8700 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8701 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8702 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8703 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8704 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
|
8705 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8706 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8707 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8708 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8709 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8710 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8711 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8712 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8713 #endif |
0 | 8714 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
|
8715 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8716 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8717 #endif |
0 | 8718 return retval; |
8719 } | |
8720 | |
8721 | |
8722 /* In case the user wants to specify a source instead of a channel, | |
8723 * they may use this function. This function will look up the | |
8724 * source-to-channel map, and convert the call into a | |
8725 * PlayChannelTimed() function call. | |
8726 * Returns the channel it's being played on. | |
8727 * Note: If you are prefer this method, then you need to be careful | |
8728 * about using PlayChannel, particularly if you request the | |
8729 * first available channels because source and channels have | |
8730 * a one-to-one mapping in this API. It is quite easy for | |
8731 * a channel/source to already be in use because of this. | |
8732 * In this event, an error message will be returned to you. | |
8733 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8734 ALuint ALmixer_PlaySourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALint ticks) |
0 | 8735 { |
8736 ALuint 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 0; |
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_PlaySourceTimed(source, 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 /* 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
|
8753 * or -1 for error |
0 | 8754 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8755 ALint ALmixer_HaltChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8756 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8757 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8758 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8759 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8760 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8761 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8762 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8763 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8764 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8765 retval = Internal_HaltChannel(channel, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8766 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8767 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8768 #endif |
0 | 8769 return retval; |
8770 } | |
8771 | |
8772 /* Will return the number of channels halted | |
8773 * or 0 for error | |
8774 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8775 ALint ALmixer_HaltSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8776 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8777 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8778 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8779 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8780 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8781 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8782 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8783 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8784 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8785 retval = Internal_HaltSource(source, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8786 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8787 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8788 #endif |
0 | 8789 return retval; |
8790 } | |
8791 | |
8792 | |
8793 /* This will rewind the SDL_Sound sample for streamed | |
8794 * samples and start buffering up the data for the next | |
8795 * playback. This may require samples to be halted | |
8796 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8797 ALboolean ALmixer_RewindData(ALmixer_Data* data) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8798 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8799 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8800 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8801 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8802 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8803 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8804 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8805 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8806 #endif |
0 | 8807 retval = Internal_RewindData(data); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8808 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8809 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8810 #endif |
0 | 8811 return retval; |
8812 } | |
8813 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8814 ALint ALmixer_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8815 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8816 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8817 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8818 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8819 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8820 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8821 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8822 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8823 #endif |
0 | 8824 retval = Internal_RewindChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8825 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8826 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8827 #endif |
0 | 8828 return retval; |
8829 } | |
8830 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8831 ALint ALmixer_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8832 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8833 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8834 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8835 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8836 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8837 } |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8840 #endif |
0 | 8841 retval = Internal_RewindSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8842 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8843 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8844 #endif |
0 | 8845 return retval; |
8846 } | |
8847 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8848 ALint ALmixer_PauseChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8849 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8850 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8851 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8852 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8853 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8854 } |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8857 #endif |
0 | 8858 retval = Internal_PauseChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8859 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8860 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8861 #endif |
0 | 8862 return retval; |
8863 } | |
8864 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8865 ALint ALmixer_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8866 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8867 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8868 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8869 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8870 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8871 } |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8874 #endif |
0 | 8875 retval = Internal_PauseSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8876 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8877 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8878 #endif |
0 | 8879 return retval; |
8880 } | |
8881 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8882 ALint ALmixer_ResumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8883 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8884 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8885 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8886 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8887 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8888 } |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8891 #endif |
0 | 8892 retval = Internal_ResumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8893 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8894 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8895 #endif |
0 | 8896 return retval; |
8897 } | |
8898 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8899 ALint ALmixer_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8900 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8901 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8902 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8903 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8904 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8905 } |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8908 #endif |
0 | 8909 retval = Internal_ResumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8910 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8911 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8912 #endif |
0 | 8913 return retval; |
8914 } | |
8915 | |
8916 /* Might consider setting eof to 0 as a "feature" | |
8917 * This will allow seek to end to stay there because | |
8918 * Play automatically rewinds if at the end */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8919 ALboolean ALmixer_SeekData(ALmixer_Data* data, ALuint msec) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8920 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8921 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8922 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8923 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8924 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8925 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8926 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8927 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8928 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8929 retval = Internal_SeekData(data, msec); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8930 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8931 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8932 #endif |
0 | 8933 return retval; |
8934 } | |
8935 | |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8936 ALint ALmixer_SeekChannel(ALint channel, ALuint msec) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8937 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8938 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8939 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8940 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8941 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8942 } |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8943 #ifdef ENABLE_ALMIXER_THREADS |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8944 SDL_LockMutex(s_simpleLock); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8945 #endif |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8946 retval = Internal_SeekChannel(channel, msec); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8947 #ifdef ENABLE_ALMIXER_THREADS |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8948 SDL_UnlockMutex(s_simpleLock); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8949 #endif |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8950 return retval; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8951 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8952 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8953 ALint ALmixer_SeekSource(ALuint source, ALuint msec) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8954 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8955 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8956 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8957 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8958 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8959 } |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8960 #ifdef ENABLE_ALMIXER_THREADS |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8961 SDL_LockMutex(s_simpleLock); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8962 #endif |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8963 retval = Internal_SeekSource(source, msec); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8964 #ifdef ENABLE_ALMIXER_THREADS |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8965 SDL_UnlockMutex(s_simpleLock); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8966 #endif |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8967 return retval; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8968 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8969 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8970 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
|
8971 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8972 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8973 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8974 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8975 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8976 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8977 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8978 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8979 #endif |
0 | 8980 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
|
8981 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8982 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8983 #endif |
0 | 8984 return retval; |
8985 } | |
8986 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8987 ALuint ALmixer_FadeInSourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 8988 { |
8989 ALuint retval; | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8990 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8991 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8992 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
8993 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8994 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8995 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8996 #endif |
0 | 8997 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
|
8998 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8999 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9000 #endif |
0 | 9001 return retval; |
9002 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9003 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9004 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
|
9005 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9006 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9007 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9008 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9009 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9010 } |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9013 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9014 retval = Internal_FadeOutChannel(channel, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9015 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9016 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9017 #endif |
0 | 9018 return retval; |
9019 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9020 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9021 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
|
9022 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9023 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9024 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9025 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9026 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9027 } |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9030 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9031 retval = Internal_FadeOutSource(source, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9032 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9033 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9034 #endif |
0 | 9035 return retval; |
9036 } | |
9037 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9038 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
|
9039 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9040 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9041 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9042 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9043 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9044 } |
2
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9047 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9048 retval = Internal_FadeChannel(channel, ticks, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9049 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9050 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9051 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9052 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9053 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9054 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9055 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
|
9056 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9057 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9058 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9059 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9060 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9061 } |
2
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9064 #endif |
0 | 9065 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
|
9066 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9067 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9068 #endif |
0 | 9069 return retval; |
9070 } | |
9071 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9072 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9073 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
|
9074 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9075 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9076 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9077 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9078 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9079 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9080 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9081 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9082 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9083 retval = Internal_SetVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9084 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9085 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9086 #endif |
0 | 9087 return retval; |
9088 } | |
9089 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9090 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
|
9091 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9092 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9093 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9094 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9095 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9096 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9097 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9098 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9099 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9100 retval = Internal_SetVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9101 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9102 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9103 #endif |
0 | 9104 return retval; |
9105 } | |
9106 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9107 ALfloat ALmixer_GetVolumeChannel(ALint channel) |
0 | 9108 { |
9109 ALfloat retval; | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9110 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9111 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9112 return -1.0f; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9113 } |
2
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9116 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9117 retval = Internal_GetVolumeChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9118 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9119 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9120 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9121 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9122 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9123 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9124 ALfloat ALmixer_GetVolumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9125 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9126 ALfloat retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9127 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9128 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9129 return -1.0f; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9130 } |
2
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9133 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9134 retval = Internal_GetVolumeSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9135 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9136 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9137 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9138 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9139 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9140 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9141 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
|
9142 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9143 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9144 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9145 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9146 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9147 } |
2
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_LockMutex(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 retval = Internal_SetMaxVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9152 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9153 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9154 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9155 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9156 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9157 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9158 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
|
9159 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9160 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9161 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9162 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9163 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9164 } |
2
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_LockMutex(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 retval = Internal_SetMaxVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9169 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9170 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9171 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9172 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9173 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9174 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9175 ALfloat ALmixer_GetMaxVolumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9176 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9177 ALfloat retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9178 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9179 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9180 return -1.0f; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9181 } |
2
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9184 #endif |
0 | 9185 retval = Internal_GetMaxVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9186 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9187 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9188 #endif |
0 | 9189 return retval; |
9190 } | |
9191 | |
9192 ALfloat ALmixer_GetMaxVolumeSource(ALuint source) | |
9193 { | |
9194 ALfloat retval; | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9195 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9196 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9197 return -1.0f; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9198 } |
2
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9201 #endif |
0 | 9202 retval = Internal_GetMaxVolumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9203 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9204 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9205 #endif |
0 | 9206 return retval; |
9207 } | |
9208 | |
9209 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9210 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
|
9211 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9212 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9213 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9214 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9215 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9216 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9217 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9218 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9219 #endif |
0 | 9220 retval = Internal_SetMinVolumeChannel(channel, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9221 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9222 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9223 #endif |
0 | 9224 return retval; |
9225 } | |
9226 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9227 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
|
9228 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9229 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9230 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9231 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9232 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9233 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9234 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9235 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9236 #endif |
0 | 9237 retval = Internal_SetMinVolumeSource(source, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9238 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9239 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9240 #endif |
0 | 9241 return retval; |
9242 } | |
9243 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9244 ALfloat ALmixer_GetMinVolumeChannel(ALint channel) |
0 | 9245 { |
9246 ALfloat retval; | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9247 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9248 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9249 return -1.0f; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9250 } |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9253 #endif |
0 | 9254 retval = Internal_GetMinVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9255 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9256 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9257 #endif |
0 | 9258 return retval; |
9259 } | |
9260 | |
9261 ALfloat ALmixer_GetMinVolumeSource(ALuint source) | |
9262 { | |
9263 ALfloat retval; | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9264 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9265 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9266 return -1.0f; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9267 } |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9270 #endif |
0 | 9271 retval = Internal_GetMinVolumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9272 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9273 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9274 #endif |
0 | 9275 return retval; |
9276 } | |
9277 | |
9278 | |
9279 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9280 ALboolean ALmixer_SetMasterVolume(ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9281 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9282 ALboolean retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9283 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9284 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9285 return AL_FALSE; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9286 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9287 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9288 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9289 #endif |
0 | 9290 retval = Internal_SetMasterVolume(volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9291 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9292 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9293 #endif |
0 | 9294 return retval; |
9295 } | |
9296 | |
9297 ALfloat ALmixer_GetMasterVolume() | |
9298 { | |
9299 ALfloat retval; | |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9300 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9301 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9302 return -1.0f; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9303 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9304 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9305 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9306 #endif |
0 | 9307 retval = Internal_GetMasterVolume(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9308 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9309 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9310 #endif |
0 | 9311 return retval; |
9312 } | |
9313 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9314 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
|
9315 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9316 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9317 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9318 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9319 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9320 } |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9323 #endif |
0 | 9324 retval = Internal_ExpireChannel(channel, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9325 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9326 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9327 #endif |
0 | 9328 return retval; |
9329 } | |
9330 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9331 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
|
9332 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9333 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9334 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9335 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9336 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9337 } |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9340 #endif |
0 | 9341 retval = Internal_ExpireSource(source, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9342 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9343 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9344 #endif |
0 | 9345 return retval; |
9346 } | |
9347 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9348 ALint ALmixer_IsActiveChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9349 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9350 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9351 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9352 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9353 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9354 } |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9357 #endif |
0 | 9358 retval = Internal_QueryChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9359 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9360 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9361 #endif |
0 | 9362 return retval; |
9363 } | |
9364 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9365 ALint ALmixer_IsActiveSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9366 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9367 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9368 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9369 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9370 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9371 } |
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9374 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9375 retval = Internal_QuerySource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9376 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9377 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9378 #endif |
0 | 9379 return retval; |
9380 } | |
9381 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9382 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9383 ALint ALmixer_IsPlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9384 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9385 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9386 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9387 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9388 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9389 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9390 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9391 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9392 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9393 retval = Internal_PlayingChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9394 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9395 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9396 #endif |
0 | 9397 return retval; |
9398 } | |
9399 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9400 ALint ALmixer_IsPlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9401 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9402 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9403 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9404 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9405 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9406 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9407 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9408 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9409 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9410 retval = Internal_PlayingSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9411 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9412 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9413 #endif |
0 | 9414 return retval; |
9415 } | |
9416 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9417 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9418 ALint ALmixer_IsPausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9419 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9420 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9421 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9422 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9423 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9424 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9425 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9426 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9427 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9428 retval = Internal_PausedChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9429 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9430 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9431 #endif |
0 | 9432 return retval; |
9433 } | |
9434 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9435 ALint ALmixer_IsPausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9436 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9437 ALint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9438 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9439 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9440 return -1; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9441 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9442 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9443 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9444 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9445 retval = Internal_PausedSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9446 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9447 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9448 #endif |
0 | 9449 return retval; |
9450 } | |
9451 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9452 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9453 ALuint ALmixer_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9454 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9455 ALuint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9456 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9457 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9458 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9459 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9460 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9461 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9462 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9463 retval = Internal_CountAllFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9464 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9465 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9466 #endif |
0 | 9467 return retval; |
9468 } | |
9469 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9470 ALuint ALmixer_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9471 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9472 ALuint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9473 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9474 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9475 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9476 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9477 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9478 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9479 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9480 retval = Internal_CountUnreservedFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9481 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9482 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9483 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9484 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9485 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9486 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9487 ALuint ALmixer_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9488 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9489 ALuint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9490 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9491 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9492 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9493 } |
2
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9496 #endif |
0 | 9497 retval = Internal_CountAllUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9498 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9499 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9500 #endif |
0 | 9501 return retval; |
9502 } | |
9503 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9504 ALuint ALmixer_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9505 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9506 ALuint retval; |
27
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9507 if(0 == ALmixer_Initialized) |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9508 { |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9509 return 0; |
9cf93a099f75
Added initialization checks to all API functions.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
26
diff
changeset
|
9510 } |
2
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_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9513 #endif |
0 | 9514 retval = Internal_CountUnreservedUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9515 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9516 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9517 #endif |
0 | 9518 return retval; |
9519 } | |
9520 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9521 ALboolean ALmixer_IsPredecoded(ALmixer_Data* data) |
1 | 9522 { |
9523 if(NULL == data) | |
9524 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9525 return AL_FALSE; |
1 | 9526 } |
9527 return data->decoded_all; | |
9528 } | |
9529 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9530 ALboolean ALmixer_CompiledWithThreadBackend() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9531 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9532 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9533 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9534 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9535 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9536 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9537 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9538 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9539 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9540 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9541 |