Mercurial > almixer_isolated
annotate ALmixer.c @ 26:884cce2515eb
Put LowerThreadPriority in ENABLE_ALMIXER_THREADS_BLOCK
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Fri, 24 Dec 2010 13:58:04 -0800 |
parents | 46e82b415520 |
children | 9cf93a099f75 |
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 */ |
1 | 420 |
421 /* This stuff is for streamed buffers that require data access */ | |
422 ALmixer_Buffer_Map* buffer_map_list; /* translate ALbuffer to index | |
423 and holds pointer to copy of data for | |
424 data access */ | |
425 ALuint current_buffer; /* The current playing buffer */ | |
426 | |
427 /* Nvidia distribution refuses to recognize a simple buffer query command | |
428 * unlike all other distributions. It's forcing me to redo the code | |
429 * to accomodate this Nvidia flaw by making me maintain a "best guess" | |
430 * copy of what I think the buffer queue state looks like. | |
431 * A circular queue would a helpful data structure for this task, | |
432 * but I wanted to avoid making an additional header requirement, | |
433 * so I'm making it a void* | |
434 */ | |
435 void* circular_buffer_queue; | |
436 | |
437 | |
438 }; | |
439 | |
0 | 440 static struct ALmixer_Channel |
441 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
442 ALboolean channel_in_use; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
443 ALboolean callback_update; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
444 ALboolean needs_stream; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
445 ALboolean halted; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
446 ALboolean paused; |
0 | 447 ALuint alsource; |
448 ALmixer_Data* almixer_data; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
449 ALint loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
450 ALint expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
451 ALuint start_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
452 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
453 ALboolean fade_enabled; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
454 ALuint fade_expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
455 ALuint fade_start_time; |
0 | 456 ALfloat fade_inv_time; |
457 ALfloat fade_start_volume; | |
458 ALfloat fade_end_volume; | |
459 ALfloat max_volume; | |
460 ALfloat min_volume; | |
461 | |
462 /* Do we need other flags? | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
463 ALbyte *samples; |
0 | 464 int volume; |
465 int looping; | |
466 int tag; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
467 ALuint expire; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
468 ALuint start_time; |
0 | 469 Mix_Fading fading; |
470 int fade_volume; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
471 ALuint fade_length; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
472 ALuint ticks_fade; |
0 | 473 effect_info *effects; |
474 */ | |
475 } *ALmixer_Channel_List = NULL; | |
476 | |
1 | 477 struct ALmixer_Buffer_Map |
478 { | |
479 ALuint albuffer; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
480 ALint index; /* might not need */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
481 ALbyte* data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
482 ALuint num_bytes; |
1 | 483 }; |
484 | |
0 | 485 /* This will be used to find a channel if the user supplies a source */ |
486 typedef struct Source_Map | |
487 { | |
488 ALuint source; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
489 ALint channel; |
0 | 490 } Source_Map; |
491 /* Keep an array of all sources with their associated channel */ | |
492 static Source_Map* Source_Map_List; | |
493 | |
494 static int Compare_Source_Map(const void* a, const void* b) | |
495 { | |
496 return ( ((Source_Map*)a)->source - ((Source_Map*)b)->source ); | |
497 } | |
498 | |
499 /* Sort by channel instead of source */ | |
500 static int Compare_Source_Map_by_channel(const void* a, const void* b) | |
501 { | |
502 return ( ((Source_Map*)a)->channel - ((Source_Map*)b)->channel ); | |
503 } | |
504 | |
505 /* Compare by albuffer */ | |
506 static int Compare_Buffer_Map(const void* a, const void* b) | |
507 { | |
1 | 508 return ( ((ALmixer_Buffer_Map*)a)->albuffer - ((ALmixer_Buffer_Map*)b)->albuffer ); |
0 | 509 } |
510 | |
511 /* This is for the user defined callback via | |
512 * ALmixer_ChannelFinished() | |
513 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
514 static void (*Channel_Done_Callback)(ALint which_channel, ALuint al_source, ALmixer_Data* almixer_data, ALboolean finished_naturally, void* user_data) = NULL; |
0 | 515 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
|
516 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 | 517 static void* Channel_Data_Callback_Userdata = NULL; |
0 | 518 |
519 | |
520 static void PrintQueueStatus(ALuint source) | |
521 { | |
522 ALint buffers_queued = 0; | |
523 ALint buffers_processed = 0; | |
524 ALenum error; | |
525 | |
526 /* Get the number of buffers still queued */ | |
527 alGetSourcei( | |
528 source, | |
529 AL_BUFFERS_QUEUED, | |
530 &buffers_queued | |
531 ); | |
532 | |
533 if((error = alGetError()) != AL_NO_ERROR) | |
534 { | |
535 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
|
536 alGetString(error)); |
0 | 537 } |
538 /* Get the number of buffers processed | |
539 * so we know if we need to refill | |
540 */ | |
541 alGetSourcei( | |
542 source, | |
543 AL_BUFFERS_PROCESSED, | |
544 &buffers_processed | |
545 ); | |
546 if((error = alGetError()) != AL_NO_ERROR) | |
547 { | |
548 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
|
549 alGetString(error)); |
0 | 550 } |
551 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
552 /* |
0 | 553 fprintf(stderr, "For source: %d, buffers_queued=%d, buffers_processed=%d\n", |
554 source, | |
555 buffers_queued, | |
556 buffers_processed); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
557 */ |
0 | 558 } |
559 | |
560 | |
561 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
562 static void Init_Channel(ALint channel) |
0 | 563 { |
564 ALmixer_Channel_List[channel].channel_in_use = 0; | |
565 ALmixer_Channel_List[channel].callback_update = 0; | |
566 ALmixer_Channel_List[channel].needs_stream = 0; | |
567 ALmixer_Channel_List[channel].paused = 0; | |
568 ALmixer_Channel_List[channel].halted = 0; | |
569 ALmixer_Channel_List[channel].loops = 0; | |
570 | |
571 ALmixer_Channel_List[channel].expire_ticks = 0; | |
572 ALmixer_Channel_List[channel].start_time = 0; | |
573 | |
574 ALmixer_Channel_List[channel].fade_enabled = 0; | |
575 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
576 ALmixer_Channel_List[channel].fade_start_time = 0; | |
577 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
578 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
579 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
580 ALmixer_Channel_List[channel].max_volume = 1.0f; | |
581 ALmixer_Channel_List[channel].min_volume = 0.0f; | |
582 | |
583 ALmixer_Channel_List[channel].almixer_data = NULL; | |
584 } | |
585 /* Quick helper function to clean up a channel | |
586 * after it's done playing */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
587 static void Clean_Channel(ALint channel) |
0 | 588 { |
589 ALenum error; | |
590 ALmixer_Channel_List[channel].channel_in_use = 0; | |
591 ALmixer_Channel_List[channel].callback_update = 0; | |
592 ALmixer_Channel_List[channel].needs_stream = 0; | |
593 ALmixer_Channel_List[channel].paused = 0; | |
594 ALmixer_Channel_List[channel].halted = 0; | |
595 ALmixer_Channel_List[channel].loops = 0; | |
596 | |
597 | |
598 ALmixer_Channel_List[channel].expire_ticks = 0; | |
599 ALmixer_Channel_List[channel].start_time = 0; | |
600 | |
601 ALmixer_Channel_List[channel].fade_enabled = 0; | |
602 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
603 ALmixer_Channel_List[channel].fade_start_time = 0; | |
604 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
605 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
606 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
607 | |
608 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MAX_GAIN, | |
609 ALmixer_Channel_List[channel].max_volume); | |
610 | |
611 if((error = alGetError()) != AL_NO_ERROR) | |
612 { | |
613 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
|
614 alGetString(error)); |
0 | 615 } |
616 | |
617 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MIN_GAIN, | |
618 ALmixer_Channel_List[channel].min_volume); | |
619 if((error = alGetError()) != AL_NO_ERROR) | |
620 { | |
621 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
|
622 alGetString(error)); |
0 | 623 } |
624 | |
625 if(ALmixer_Channel_List[channel].almixer_data != NULL) | |
626 { | |
627 if(ALmixer_Channel_List[channel].almixer_data->in_use > 0) | |
628 { | |
629 ALmixer_Channel_List[channel].almixer_data->in_use--; | |
630 } | |
631 } | |
632 /* Needed to determine if rewind is needed, can't reset */ | |
633 /* | |
634 ALmixer_Channel_List[channel].almixer_data->eof = 0; | |
635 */ | |
636 | |
637 ALmixer_Channel_List[channel].almixer_data = NULL; | |
638 } | |
639 | |
640 /* What shoud this return? | |
641 * 127 for signed, 255 for unsigned | |
642 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
643 static ALubyte GetSignednessValue(ALushort format) |
0 | 644 { |
645 switch(format) | |
646 { | |
647 case AUDIO_U8: | |
648 case AUDIO_U16LSB: | |
649 case AUDIO_U16MSB: | |
650 return ALMIXER_UNSIGNED_VALUE; | |
651 break; | |
652 case AUDIO_S8: | |
653 case AUDIO_S16LSB: | |
654 case AUDIO_S16MSB: | |
655 return ALMIXER_SIGNED_VALUE; | |
656 break; | |
657 default: | |
658 return 0; | |
659 } | |
660 return 0; | |
661 } | |
662 | |
663 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
664 static ALubyte GetBitDepth(ALushort format) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
665 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
666 ALubyte bit_depth = 16; |
0 | 667 |
668 switch(format) | |
669 { | |
670 case AUDIO_U8: | |
671 case AUDIO_S8: | |
672 bit_depth = 8; | |
673 break; | |
674 | |
675 case AUDIO_U16LSB: | |
676 /* | |
677 case AUDIO_U16: | |
678 */ | |
679 case AUDIO_S16LSB: | |
680 /* | |
681 case AUDIO_S16: | |
682 */ | |
683 case AUDIO_U16MSB: | |
684 case AUDIO_S16MSB: | |
685 /* | |
686 case AUDIO_U16SYS: | |
687 case AUDIO_S16SYS: | |
688 */ | |
689 bit_depth = 16; | |
690 break; | |
691 default: | |
692 bit_depth = 0; | |
693 } | |
694 return bit_depth; | |
695 } | |
696 | |
697 /* Need to translate between SDL/SDL_Sound audiospec | |
698 * and OpenAL conventions */ | |
699 static ALenum TranslateFormat(Sound_AudioInfo* info) | |
700 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
701 ALubyte bit_depth; |
0 | 702 |
703 bit_depth = GetBitDepth(info->format); | |
704 if(0 == bit_depth) | |
705 { | |
706 fprintf(stderr, "Warning: Unknown bit depth. Setting to 16\n"); | |
707 bit_depth = 16; | |
708 } | |
709 | |
710 if(2 == info->channels) | |
711 { | |
712 if(16 == bit_depth) | |
713 { | |
714 return AL_FORMAT_STEREO16; | |
715 } | |
716 else | |
717 { | |
718 return AL_FORMAT_STEREO8; | |
719 } | |
720 } | |
721 else | |
722 { | |
723 if(16 == bit_depth) | |
724 { | |
725 return AL_FORMAT_MONO16; | |
726 } | |
727 else | |
728 { | |
729 return AL_FORMAT_MONO8; | |
730 } | |
731 } | |
732 /* Make compiler happy. Shouldn't get here */ | |
733 return AL_FORMAT_STEREO16; | |
734 } | |
735 | |
1 | 736 |
737 /* This will compute the total playing time | |
738 * based upon the number of bytes and audio info. | |
739 * (In prinicple, it should compute the time for any given length) | |
740 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
741 static ALuint Compute_Total_Time_Decomposed(ALuint bytes_per_sample, ALuint frequency, ALubyte channels, size_t total_bytes) |
1 | 742 { |
743 double total_sec; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
744 ALuint total_msec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
745 ALuint bytes_per_sec; |
1 | 746 |
747 if(0 == total_bytes) | |
748 { | |
749 return 0; | |
750 } | |
751 /* To compute Bytes per second, do | |
752 * samples_per_sec * bytes_per_sample * number_of_channels | |
753 */ | |
754 bytes_per_sec = frequency * bytes_per_sample * channels; | |
755 | |
756 /* Now to get total time (sec), do | |
757 * total_bytes / bytes_per_sec | |
758 */ | |
759 total_sec = total_bytes / (double)bytes_per_sec; | |
760 | |
761 /* Now convert seconds to milliseconds | |
762 * Add .5 to the float to do rounding before the final cast | |
763 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
764 total_msec = (ALuint) ( (total_sec * 1000) + 0.5 ); |
1 | 765 /* |
766 fprintf(stderr, "freq=%d, bytes_per_sample=%d, channels=%d, total_msec=%d\n", frequency, bytes_per_sample, channels, total_msec); | |
767 */ | |
768 return total_msec; | |
769 } | |
770 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
771 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
|
772 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
773 ALuint bytes_per_sample; |
1 | 774 |
775 if(0 == total_bytes) | |
776 { | |
777 return 0; | |
778 } | |
779 /* 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
|
780 * 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
|
781 * 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
|
782 * 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
|
783 * 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
|
784 * 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
|
785 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
786 bytes_per_sample = (ALuint) ((info->format & 0xFF) / 8); |
1 | 787 |
788 return Compute_Total_Time_Decomposed(bytes_per_sample, info->rate, info->channels, total_bytes); | |
789 } /* End Compute_Total_Time */ | |
790 | |
791 | |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
792 #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
|
793 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
|
794 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
795 double total_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
796 ALuint bytes_per_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
797 size_t total_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
798 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
799 if(0 >= total_msec) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
800 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
801 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
802 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
803 /* To compute Bytes per second, do |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
804 * 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
|
805 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
806 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
|
807 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
808 /* convert milliseconds to seconds */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
809 total_sec = total_msec / 1000.0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
810 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
811 /* Now to get total bytes */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
812 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
|
813 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
814 /* 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
|
815 */ |
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 return total_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
818 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
819 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
820 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
|
821 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
822 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
823 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
824 if(0 >= total_msec) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
825 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
826 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
827 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
828 /* 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
|
829 * 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
|
830 * 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
|
831 * 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
|
832 * 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
|
833 * 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
|
834 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
835 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
|
836 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
837 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
|
838 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
839 |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
840 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
841 /* 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
|
842 * 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
|
843 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
844 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
|
845 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
846 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
847 ALuint bytes_per_frame; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
848 size_t evenly_divisible_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
849 size_t remainder_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
850 size_t return_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
851 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
852 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
|
853 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
854 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
|
855 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
856 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
|
857 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
858 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
|
859 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
|
860 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
861 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
|
862 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
863 /* 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
|
864 * 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
|
865 * 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
|
866 * 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
|
867 * 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
|
868 * 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
|
869 * 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
|
870 * 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
|
871 * 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
|
872 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
873 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
874 return_bytes += 64; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
875 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
876 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
877 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
|
878 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
879 return return_bytes; |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
880 } |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
881 #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
|
882 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
883 |
1 | 884 |
0 | 885 /**************** REMOVED ****************************/ |
886 /* This was removed because I originally thought | |
887 * OpenAL could return a pointer to the buffer data, | |
888 * but I was wrong. If something like that is ever | |
889 * implemented, then this might become useful. | |
890 */ | |
891 #if 0 | |
892 /* Reconstruct_Sound_Sample and Set_AudioInfo only | |
893 * are needed if the Seek memory optimization is | |
894 * used. Also, the Loki dist doesn't seem to support | |
895 * AL_DATA which I need for it. | |
896 */ | |
897 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION | |
898 | |
899 static void Set_AudioInfo(Sound_AudioInfo* info, ALint frequency, ALint bits, ALint channels) | |
900 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
901 info->rate = (ALuint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
902 info->channels = (ALubyte)channels; |
0 | 903 |
904 /* Not sure if it should be signed or unsigned. Hopefully | |
905 * that detail won't be needed. | |
906 */ | |
907 if(8 == bits) | |
908 { | |
909 info->format = AUDIO_U8; | |
910 } | |
911 else | |
912 { | |
913 info->format = AUDIO_U16SYS; | |
914 } | |
915 fprintf(stderr, "Audio info: freq=%d, chan=%d, format=%d\n", | |
916 info->rate, info->channels, info->format); | |
917 | |
918 } | |
919 | |
920 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
921 static ALint Reconstruct_Sound_Sample(ALmixer_Data* data) |
0 | 922 { |
923 ALenum error; | |
924 ALint* data_from_albuffer; | |
925 ALint freq; | |
926 ALint bits; | |
927 ALint channels; | |
928 ALint size; | |
929 | |
930 /* Create memory all initiallized to 0. */ | |
931 data->sample = (Sound_Sample*)calloc(1, sizeof(Sound_Sample)); | |
932 if(NULL == data->sample) | |
933 { | |
934 ALmixer_SetError("Out of memory for Sound_Sample"); | |
935 return -1; | |
936 } | |
937 | |
938 /* Clear errors */ | |
939 alGetError(); | |
940 | |
941 alGetBufferi(data->buffer[0], AL_FREQUENCY, &freq); | |
942 if((error = alGetError()) != AL_NO_ERROR) | |
943 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
944 ALmixer_SetError("alGetBufferi(AL_FREQUENCY): %s", alGetString(error) ); |
0 | 945 free(data->sample); |
946 data->sample = NULL; | |
947 return -1; | |
948 } | |
949 | |
950 alGetBufferi(data->buffer[0], AL_BITS, &bits); | |
951 if((error = alGetError()) != AL_NO_ERROR) | |
952 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
953 ALmixer_SetError("alGetBufferi(AL_BITS): %s", alGetString(error) ); |
0 | 954 free(data->sample); |
955 data->sample = NULL; | |
956 return -1; | |
957 } | |
958 | |
959 alGetBufferi(data->buffer[0], AL_CHANNELS, &channels); | |
960 if((error = alGetError()) != AL_NO_ERROR) | |
961 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
962 ALmixer_SetError("alGetBufferi(AL_CHANNELS): %s", alGetString(error) ); |
0 | 963 free(data->sample); |
964 data->sample = NULL; | |
965 return -1; | |
966 } | |
967 | |
968 alGetBufferi(data->buffer[0], AL_SIZE, &size); | |
969 if((error = alGetError()) != AL_NO_ERROR) | |
970 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
971 ALmixer_SetError("alGetBufferi(AL_SIZE): %s", alGetString(error) ); |
0 | 972 free(data->sample); |
973 data->sample = NULL; | |
974 return -1; | |
975 } | |
976 | |
977 alGetBufferi(data->buffer[0], AL_DATA, data_from_albuffer); | |
978 if((error = alGetError()) != AL_NO_ERROR) | |
979 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
980 ALmixer_SetError("alGetBufferi(AL_DATA): %s", alGetString(error) ); |
0 | 981 free(data->sample); |
982 data->sample = NULL; | |
983 return -1; | |
984 } | |
985 | |
986 if(size <= 0) | |
987 { | |
988 ALmixer_SetError("No data in al buffer"); | |
989 free(data->sample); | |
990 data->sample = NULL; | |
991 return -1; | |
992 } | |
993 | |
994 /* Now that we have all the attributes, we need to | |
995 * allocate memory for the buffer and reconstruct | |
996 * the AudioInfo attributes. | |
997 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
998 data->sample->buffer = malloc(size*sizeof(ALbyte)); |
0 | 999 if(NULL == data->sample->buffer) |
1000 { | |
1001 ALmixer_SetError("Out of memory for sample->buffer"); | |
1002 free(data->sample); | |
1003 data->sample = NULL; | |
1004 return -1; | |
1005 } | |
1006 | |
1007 memcpy(data->sample->buffer, data_from_albuffer, size); | |
1008 data->sample->buffer_size = size; | |
1009 | |
1010 /* Fill up the Sound_AudioInfo structures */ | |
1011 Set_AudioInfo(&data->sample->desired, freq, bits, channels); | |
1012 Set_AudioInfo(&data->sample->actual, freq, bits, channels); | |
1013 | |
1014 return 0; | |
1015 } | |
1016 | |
1017 #endif /* End DISABLE_SEEK_MEMORY_OPTIMIZATION */ | |
1018 #endif | |
1019 /*************** END REMOVED *************************/ | |
1020 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1021 static void Invoke_Channel_Done_Callback(ALint which_channel, ALboolean did_finish_naturally) |
0 | 1022 { |
1023 if(NULL == Channel_Done_Callback) | |
1024 { | |
1025 return; | |
1026 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1027 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
|
1028 } |
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 static ALint LookUpBuffer(ALuint buffer, ALmixer_Buffer_Map* buffer_map_list, ALuint num_items_in_list) |
0 | 1031 { |
1032 /* Only the first value is used for the key */ | |
1 | 1033 ALmixer_Buffer_Map key = { 0, 0, NULL, 0 }; |
1034 ALmixer_Buffer_Map* found_item = NULL; | |
0 | 1035 key.albuffer = buffer; |
1036 | |
1037 /* Use the ANSI C binary search feature (yea!) */ | |
1 | 1038 found_item = (ALmixer_Buffer_Map*)bsearch(&key, buffer_map_list, num_items_in_list, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 1039 if(NULL == found_item) |
1040 { | |
1041 ALmixer_SetError("Can't find buffer"); | |
1042 return -1; | |
1043 } | |
1044 return found_item->index; | |
1045 } | |
1046 | |
1047 | |
1048 /* FIXME: Need to pass back additional info to be useful. | |
1049 * Bit rate, stereo/mono (num chans), time in msec? | |
1050 * Precoded/streamed flag so user can plan for future data? | |
1051 */ | |
1 | 1052 /* |
1053 * channels: 1 for mono, 2 for stereo | |
1054 * | |
1055 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1056 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
|
1057 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1058 ALboolean is_unsigned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1059 ALubyte bits_per_sample = GetBitDepth(format); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1060 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1061 ALuint length_in_msec; |
1 | 1062 |
1063 if(GetSignednessValue(format) == ALMIXER_UNSIGNED_VALUE) | |
1064 { | |
1065 is_unsigned = 1; | |
1066 } | |
1067 else | |
1068 { | |
1069 is_unsigned = 0; | |
1070 } | |
1071 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1072 bytes_per_sample = (ALuint) (bits_per_sample / 8); |
1 | 1073 |
1074 length_in_msec = Compute_Total_Time_Decomposed(bytes_per_sample, frequency, channels, num_bytes); | |
1075 | |
0 | 1076 /* |
1077 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); | |
1078 */ | |
1079 if(NULL == Channel_Data_Callback) | |
1080 { | |
1081 return; | |
1082 } | |
1 | 1083 /* |
1084 * Channel_Data_Callback(which_channel, data, num_bytes, frequency, channels, GetBitDepth(format), format, decode_mode_is_predecoded); | |
1085 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1086 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
|
1087 } |
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 static void Invoke_Predecoded_Channel_Data_Callback(ALint channel, ALmixer_Data* data) |
0 | 1090 { |
1091 if(NULL == data->sample) | |
1092 { | |
1093 return; | |
1094 } | |
1095 /* The buffer position is complicated because if the current data was seeked, | |
1096 * we must adjust the buffer to the seek position | |
1097 */ | |
1098 Invoke_Channel_Data_Callback(channel, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1099 (((ALbyte*) data->sample->buffer) + (data->total_bytes - data->loaded_bytes) ), |
0 | 1100 data->loaded_bytes, |
1101 data->sample->desired.rate, | |
1102 data->sample->desired.channels, | |
1103 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1104 AL_TRUE |
0 | 1105 ); |
1106 } | |
1107 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1108 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
|
1109 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1110 ALint index; |
0 | 1111 if(NULL == data->buffer_map_list) |
1112 { | |
1113 return; | |
1114 } | |
1115 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1116 /* This should catch the case where all buffers are unqueued | |
1117 * and the "current" buffer is id: 0 | |
1118 */ | |
1119 if(-1 == index) | |
1120 { | |
1121 return; | |
1122 } | |
1123 Invoke_Channel_Data_Callback(channel, | |
1124 data->buffer_map_list[index].data, | |
1125 data->buffer_map_list[index].num_bytes, | |
1126 data->sample->desired.rate, | |
1127 data->sample->desired.channels, | |
1128 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1129 AL_FALSE |
0 | 1130 ); |
1131 } | |
1132 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1133 /* Converts milliseconds to byte positions. |
0 | 1134 * This is needed for seeking on predecoded samples |
1135 */ | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1136 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
|
1137 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1138 ALuint bytes_per_sample; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1139 ALuint bytes_per_frame; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1140 float bytes_per_millisecond; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1141 float byte_position; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1142 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1143 if(audio_info == NULL) |
0 | 1144 { |
1145 fprintf(stderr, "Error, info is NULL\n"); | |
1146 } | |
1147 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1148 /* 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
|
1149 * 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
|
1150 * 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
|
1151 * 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
|
1152 * 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
|
1153 * Uint32 to unspecified size types like ALuint. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1154 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1155 bytes_per_sample = (ALuint) ((audio_info->format & 0xFF) / 8); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1156 bytes_per_frame = bytes_per_sample * audio_info->channels; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1157 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
|
1158 byte_position = ((float)(number_of_milliseconds)) * bytes_per_millisecond; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1159 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
|
1160 } |
0 | 1161 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1162 static ALint Set_Predecoded_Seek_Position(ALmixer_Data* data, ALuint byte_position) |
0 | 1163 { |
1164 ALenum error; | |
1165 /* clear error */ | |
1166 alGetError(); | |
1167 | |
1168 /* Is it greater than, or greater-than or equal to ?? */ | |
1169 if(byte_position > data->total_bytes) | |
1170 { | |
1171 /* 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
|
1172 /* |
0 | 1173 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
|
1174 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1175 |
0 | 1176 /* In case the below thing doesn't work, |
1177 * just rewind the whole thing. | |
1178 * | |
1179 alBufferData(data->buffer[0], | |
1180 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1181 (ALbyte*) data->sample->buffer, |
0 | 1182 data->total_bytes, |
1183 data->sample->desired.rate | |
1184 ); | |
1185 */ | |
1186 | |
1187 /* I was trying to set to the end, (1 byte remaining), | |
1188 * but I was getting freezes. I'm thinking it might be | |
1189 * another Power of 2 bug in the Loki dist. I tried 2, | |
1190 * and it still hung. 4 didn't hang, but I got a clip | |
1191 * artifact. 8 seemed to work okay. | |
1192 */ | |
1193 alBufferData(data->buffer[0], | |
1194 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1195 (((ALbyte*) data->sample->buffer) + (data->total_bytes - 8) ), |
0 | 1196 8, |
1197 data->sample->desired.rate | |
1198 ); | |
1199 if( (error = alGetError()) != AL_NO_ERROR) | |
1200 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1201 ALmixer_SetError("Can't seek past end and alBufferData failed: %s\n", alGetString(error)); |
0 | 1202 return -1; |
1203 } | |
1204 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1205 * query command to work because I don't know if it will mutilate the | |
1206 * size for its own purposes or return the original size | |
1207 */ | |
1208 data->loaded_bytes = 8; | |
1209 | |
1210 /* Not sure if this should be an error or not */ | |
1211 /* | |
1212 ALmixer_SetError("Can't Seek past end"); | |
1213 return -1; | |
1214 */ | |
1215 return 0; | |
1216 } | |
1217 | |
1218 alBufferData(data->buffer[0], | |
1219 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1220 &(((ALbyte*)data->sample->buffer)[byte_position]), |
0 | 1221 data->total_bytes - byte_position, |
1222 data->sample->desired.rate | |
1223 ); | |
1224 if( (error = alGetError()) != AL_NO_ERROR) | |
1225 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1226 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1227 return -1; |
1228 } | |
1229 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1230 * query command to work because I don't know if it will mutilate the | |
1231 * size for its own purposes or return the original size | |
1232 */ | |
1233 data->loaded_bytes = data->total_bytes - byte_position; | |
1234 | |
1235 return 0; | |
1236 } | |
1237 | |
1238 /* Because we have multiple queue buffers and OpenAL won't let | |
1239 * us access them, we need to keep copies of each buffer around | |
1240 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1241 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
|
1242 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1243 ALint index; |
0 | 1244 /* We only want to copy if access_data is true. |
1245 * This is determined by whether memory has been | |
1246 * allocated in the buffer_map_list or not | |
1247 */ | |
1248 if(NULL == data->buffer_map_list) | |
1249 { | |
1250 return -1; | |
1251 } | |
1252 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1253 if(-1 == index) | |
1254 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1255 /* |
0 | 1256 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
|
1257 */ |
0 | 1258 return -1; |
1259 } | |
1260 /* Copy the data to the access buffer */ | |
1261 memcpy(data->buffer_map_list[index].data, data->sample->buffer, num_bytes); | |
1262 data->buffer_map_list[index].num_bytes = data->sample->buffer_size; | |
1263 | |
1264 return 0; | |
1265 } | |
1266 | |
1267 | |
1268 /* For streamed data, gets more data | |
1269 * and prepares it in the active Mix_chunk | |
1270 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1271 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
|
1272 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1273 ALuint bytes_decoded; |
0 | 1274 ALenum error; |
1275 if(NULL == data) | |
1276 { | |
1277 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1278 return 0; | |
1279 } | |
1280 | |
1281 bytes_decoded = Sound_Decode(data->sample); | |
1282 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1283 { | |
1284 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1285 ALmixer_SetError(Sound_GetError()); | |
1286 /* Force cleanup through FreeData | |
1287 Sound_FreeSample(data->sample); | |
1288 */ | |
1289 return 0; | |
1290 } | |
1291 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1292 /* 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
|
1293 |
0 | 1294 /* Don't forget to add check for EOF */ |
1295 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1296 if(0 == bytes_decoded) | |
1297 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1298 data->eof = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1299 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1300 #if 0 |
0 | 1301 fprintf(stderr, "Hit eof while trying to buffer\n"); |
1302 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1303 { | |
1304 fprintf(stderr, "\tEOF flag\n"); | |
1305 } | |
1306 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1307 { | |
1308 fprintf(stderr, "\tCanSeek flag\n"); | |
1309 } | |
1310 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1311 { | |
1312 fprintf(stderr, "\tEAGAIN flag\n"); | |
1313 } | |
1314 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1315 { | |
1316 fprintf(stderr, "\tNONE flag\n"); | |
1317 } | |
1318 #endif | |
1319 return 0; | |
1320 } | |
1321 | |
1322 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
1323 /******* REMOVE ME ********************************/ | |
1324 /***************** ANOTHER EXPERIEMENT *******************/ | |
1325 /* The PROBLEM: It seems that the Loki distribution has problems | |
1326 * with Queuing when the buffer size is not a power of two | |
1327 * and additional buffers must come after it. | |
1328 * The behavior is inconsistent, but one of several things | |
1329 * usually happens: | |
1330 * Playback is normal | |
1331 * Playback immediately stops after the non-pow2 buffer | |
1332 * Playback gets distorted on the non-pow2 buffer | |
1333 * The entire program segfaults. | |
1334 * The workaround is to always specify a power of two buffer size | |
1335 * and hope that SDL_sound always fill it. (By lucky coincidence, | |
1336 * I already submitted the Ogg fix.) However, this won't catch | |
1337 * cases where a loop happens because the read at the end of the | |
1338 * file is typically less than the buffer size. | |
1339 * | |
1340 * This fix addresses this issue, however it may break in | |
1341 * other conditions. Always decode in buffer sizes of powers of 2. | |
1342 * | |
1343 * The HACK: | |
1344 * If the buffer is short, try filling it up with 0's | |
1345 * to meet the user requested buffer_size which | |
1346 * is probably a nice number OpenAL likes, in | |
1347 * hopes to avoid a possible Loki bug with | |
1348 * short buffers. If looping (which is the main | |
1349 * reason for this), the negative side effect is | |
1350 * that it may take longer for the loop to start | |
1351 * because it must play dead silence. Or if the decoder | |
1352 * doesn't guarantee to return the requested bytes | |
1353 * (like Ogg), then you will get breakup in between | |
1354 * packets. | |
1355 */ | |
1356 if( (bytes_decoded) < data->sample->buffer_size) | |
1357 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1358 ALubyte bit_depth; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1359 ALubyte signedness_value; |
0 | 1360 int silence_value; |
1361 /* Crap, memset value needs to be the "silent" value, | |
1362 * but it will differ for signed/unsigned and bit depth | |
1363 */ | |
1364 bit_depth = GetBitDepth(data->sample->desired.format); | |
1365 signedness_value = GetSignednessValue(data->sample->desired.format); | |
1366 if(ALMIXER_SIGNED_VALUE == signedness_value) | |
1367 { | |
1368 /* I'm guessing that if it's signed, then 0 is the | |
1369 * "silent" value */ | |
1370 silence_value = 0; | |
1371 } | |
1372 else | |
1373 { | |
1374 if(8 == bit_depth) | |
1375 { | |
1376 /* If 8 bit, I'm guessing it's (2^7)-1 = 127 */ | |
1377 silence_value = 127; | |
1378 } | |
1379 else | |
1380 { | |
1381 /* For 16 bit, I'm guessing it's (2^15)-1 = 32767 */ | |
1382 silence_value = 32767; | |
1383 } | |
1384 } | |
1385 /* Now fill up the rest of the data buffer with the | |
1386 * silence_value. | |
1387 * I don't think I have to worry about endian issues for | |
1388 * this part since the data is for internal use only | |
1389 * at this point. | |
1390 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1391 memset( &( ((ALbyte*)(data->sample->buffer))[bytes_decoded] ), silence_value, data->sample->buffer_size - bytes_decoded); |
0 | 1392 /* Now reset the bytes_decoded to reflect the entire |
1393 * buffer to tell alBufferData what our full size is. | |
1394 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1395 /* |
0 | 1396 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
|
1397 */ |
0 | 1398 bytes_decoded = data->sample->buffer_size; |
1399 } | |
1400 /*********** END EXPERIMENT ******************************/ | |
1401 /******* END REMOVE ME ********************************/ | |
1402 #endif | |
1403 | |
1404 /* Now copy the data to the OpenAL buffer */ | |
1405 /* We can't just set a pointer because the API needs | |
1406 * its own copy to assist hardware acceleration */ | |
1407 alBufferData(buffer, | |
1408 TranslateFormat(&data->sample->desired), | |
1409 data->sample->buffer, | |
1410 bytes_decoded, | |
1411 data->sample->desired.rate | |
1412 ); | |
1413 if( (error = alGetError()) != AL_NO_ERROR) | |
1414 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1415 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1416 return 0; |
1417 } | |
1418 | |
1419 /* If we need to, copy the data also to the access area | |
1420 * (the function will do the check for us) | |
1421 */ | |
1422 CopyDataToAccessBuffer(data, bytes_decoded, buffer); | |
1423 return bytes_decoded; | |
1424 } | |
1425 | |
1426 | |
1427 | |
1428 | |
1429 /******************** EXPERIEMENT **************************** | |
1430 * Test function to force maximum buffer filling during loops | |
1431 * REMOVE LATER | |
1432 *********************************************/ | |
1433 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1434 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
|
1435 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1436 ALint bytes_decoded; |
0 | 1437 ALenum error; |
1438 if(NULL == data) | |
1439 { | |
1440 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1441 return -1; | |
1442 } | |
1443 | |
1444 if(AL_FALSE == alIsBuffer(buffer)) | |
1445 { | |
1446 fprintf(stderr, "NOT A BUFFER>>>>>>>>>>>>>>>\n"); | |
1447 return -1; | |
1448 } | |
1449 fprintf(stderr, "Entered GetMoreData222222: buffer id is %d\n", buffer); | |
1450 | |
1451 /* | |
1452 fprintf(stderr, "Decode in GetMoreData\n"); | |
1453 */ | |
1454 | |
1455 #if 0 | |
1456 if(buffer%2 == 1) | |
1457 { | |
1458 fprintf(stderr, "Setting buffer size to 16384\n"); | |
1459 Sound_SetBufferSize(data->sample, 16384); | |
1460 } | |
1461 else | |
1462 { | |
1463 fprintf(stderr, "Setting buffer size to 8192\n"); | |
1464 Sound_SetBufferSize(data->sample, 8192); | |
1465 } | |
1466 #endif | |
1467 | |
1468 bytes_decoded = Sound_Decode(data->sample); | |
1469 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1470 { | |
1471 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1472 ALmixer_SetError(Sound_GetError()); | |
1473 /* | |
1474 Sound_FreeSample(data->sample); | |
1475 */ | |
1476 return -1; | |
1477 } | |
1478 /* Don't forget to add check for EOF */ | |
1479 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1480 if(0 == bytes_decoded) | |
1481 { | |
1482 #if 1 | |
1483 fprintf(stderr, "Hit eof while trying to buffer\n"); | |
1484 data->eof = 1; | |
1485 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1486 { | |
1487 fprintf(stderr, "\tEOF flag\n"); | |
1488 } | |
1489 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1490 { | |
1491 fprintf(stderr, "\tCanSeek flag\n"); | |
1492 } | |
1493 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1494 { | |
1495 fprintf(stderr, "\tEAGAIN flag\n"); | |
1496 } | |
1497 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1498 { | |
1499 fprintf(stderr, "\tNONE flag\n"); | |
1500 } | |
1501 #endif | |
1502 return 0; | |
1503 } | |
1504 | |
1505 if(bytes_decoded < 16384) | |
1506 { | |
1507 char* tempbuffer1 = (char*)malloc(16384); | |
1508 char* tempbuffer2 = (char*)malloc(16384); | |
1509 int retval; | |
1510 memcpy(tempbuffer1, data->sample->buffer, bytes_decoded); | |
1511 retval = Sound_SetBufferSize(data->sample, 16384-bytes_decoded); | |
1512 if(retval == 1) | |
1513 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1514 ALuint new_bytes; |
0 | 1515 Sound_Rewind(data->sample); |
1516 new_bytes = Sound_Decode(data->sample); | |
1517 fprintf(stderr, "Orig bytes: %d, Make up bytes_decoded=%d, total=%d\n", bytes_decoded, new_bytes, new_bytes+bytes_decoded); | |
1518 | |
1519 memcpy(tempbuffer2, data->sample->buffer, new_bytes); | |
1520 | |
1521 retval = Sound_SetBufferSize(data->sample, 16384); | |
1522 fprintf(stderr, "Finished reset...now danger copy\n"); | |
1523 memcpy(data->sample->buffer, tempbuffer1,bytes_decoded); | |
1524 | |
1525 fprintf(stderr, "Finished reset...now danger copy2\n"); | |
1526 memcpy( &( ((char*)(data->sample->buffer))[bytes_decoded] ), tempbuffer2, new_bytes); | |
1527 | |
1528 fprintf(stderr, "Finished \n"); | |
1529 | |
1530 free(tempbuffer1); | |
1531 free(tempbuffer2); | |
1532 bytes_decoded += new_bytes; | |
1533 fprintf(stderr, "ASSERT bytes should equal 16384: %d\n", bytes_decoded); | |
1534 } | |
1535 else | |
1536 { | |
1537 fprintf(stderr, "Experiment failed: %s\n", Sound_GetError()); | |
1538 } | |
1539 } | |
1540 | |
1541 /* Now copy the data to the OpenAL buffer */ | |
1542 /* We can't just set a pointer because the API needs | |
1543 * its own copy to assist hardware acceleration */ | |
1544 alBufferData(buffer, | |
1545 TranslateFormat(&data->sample->desired), | |
1546 data->sample->buffer, | |
1547 bytes_decoded, | |
1548 data->sample->desired.rate | |
1549 ); | |
1550 if( (error = alGetError()) != AL_NO_ERROR) | |
1551 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1552 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1553 return -1; |
1554 } | |
1555 | |
1556 fprintf(stderr, "GetMoreData2222 returning %d bytes decoded\n", bytes_decoded); | |
1557 return bytes_decoded; | |
1558 } | |
1559 #endif | |
1560 | |
1561 /************ END EXPERIEMENT - REMOVE ME *************************/ | |
1562 | |
1563 | |
1564 | |
1565 | |
1566 | |
1567 | |
1568 | |
1569 | |
1570 | |
1571 /* This function will look up the source for the corresponding channel */ | |
1572 /* 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
|
1573 static ALuint Internal_GetSource(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1574 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1575 ALint i; |
0 | 1576 /* Make sure channel is in bounds */ |
1577 if(channel >= Number_of_Channels_global) | |
1578 { | |
1579 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); | |
1580 return 0; | |
1581 } | |
1582 /* If the user specified -1, then return the an available source */ | |
1583 if(channel < 0) | |
1584 { | |
1585 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1586 { | |
1587 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1588 { | |
1589 return ALmixer_Channel_List[i].alsource; | |
1590 } | |
1591 } | |
1592 /* If we get here, all sources are in use */ | |
1593 /* Error message seems too harsh | |
1594 ALmixer_SetError("All sources are in use"); | |
1595 */ | |
1596 return 0; | |
1597 } | |
1598 /* Last case: Return the source for the channel */ | |
1599 return ALmixer_Channel_List[channel].alsource; | |
1600 } | |
1601 | |
1602 /* 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
|
1603 static ALint Internal_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1604 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1605 ALint i; |
0 | 1606 /* Only the first value is used for the key */ |
1607 Source_Map key = { 0, 0 }; | |
1608 Source_Map* found_item = NULL; | |
1609 key.source = source; | |
1610 | |
1611 /* If the source is 0, look up the first available channel */ | |
1612 if(0 == source) | |
1613 { | |
1614 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1615 { | |
1616 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1617 { | |
1618 return i; | |
1619 } | |
1620 } | |
1621 /* If we get here, all sources are in use */ | |
1622 /* Error message seems too harsh | |
1623 ALmixer_SetError("All channels are in use"); | |
1624 */ | |
1625 return -1; | |
1626 } | |
1627 | |
1628 | |
1629 /* Else, look up the source and return the channel */ | |
1630 if(AL_FALSE == alIsSource(source)) | |
1631 { | |
1632 ALmixer_SetError("Is not a source"); | |
1633 return -1; | |
1634 } | |
1635 | |
1636 /* Use the ANSI C binary search feature (yea!) */ | |
1637 found_item = (Source_Map*)bsearch(&key, Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
1638 if(NULL == found_item) | |
1639 { | |
1640 ALmixer_SetError("Source is valid but not registered with ALmixer (to a channel)"); | |
1641 return -1; | |
1642 } | |
1643 return found_item->channel; | |
1644 } | |
1645 | |
1646 | |
1647 | |
1648 /* This function will find the first available channel (not in use) | |
1649 * from the specified start channel. Reserved channels to not qualify | |
1650 * as available. | |
1651 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1652 static ALint Internal_FindFreeChannel(ALint start_channel) |
0 | 1653 { |
1654 /* Start at the number of reserved so we skip over | |
1655 * all the reserved channels. | |
1656 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1657 ALint i = Number_of_Reserve_Channels_global; |
0 | 1658 /* Quick check to see if we're out of bounds */ |
1659 if(start_channel >= Number_of_Channels_global) | |
1660 { | |
1661 return -1; | |
1662 } | |
1663 | |
1664 /* If the start channel is even higher than the reserved, | |
1665 * then start at the higher value. | |
1666 */ | |
1667 if(start_channel > Number_of_Reserve_Channels_global) | |
1668 { | |
1669 i = start_channel; | |
1670 } | |
1671 | |
1672 /* i has already been set */ | |
1673 for( ; i<Number_of_Channels_global; i++) | |
1674 { | |
1675 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1676 { | |
1677 return i; | |
1678 } | |
1679 } | |
1680 /* If we get here, all sources are in use */ | |
1681 return -1; | |
1682 } | |
1683 | |
1684 | |
1685 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1686 /* 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
|
1687 * or 0 for error |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1688 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1689 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
|
1690 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1691 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1692 ALint counter = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1693 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1694 ALint buffers_still_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1695 ALint buffers_processed; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1696 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1697 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1698 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1699 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
|
1700 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1701 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1702 /* 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
|
1703 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1704 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1705 /* 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
|
1706 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
|
1707 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1708 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1709 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1710 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1711 fprintf(stderr, "14Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1712 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1713 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1714 /* 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
|
1715 * 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
|
1716 * 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
|
1717 * 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
|
1718 * 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
|
1719 * 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
|
1720 * 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
|
1721 * 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
|
1722 * 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
|
1723 * 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
|
1724 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1725 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1726 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1727 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1728 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1729 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1730 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1731 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1732 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
|
1733 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1734 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
|
1735 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1736 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1737 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1738 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1739 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1740 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1741 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1742 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1743 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1744 fprintf(stderr, "17Testing Error with buffers_processed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1745 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1746 ALmixer_SetError("Failed detecting still processed buffers: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1747 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1748 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1749 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1750 /* 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
|
1751 * to clear the source |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1752 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1753 if((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
|
1754 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1755 alSourcei(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1756 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1757 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1758 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1759 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1760 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
|
1761 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1762 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
|
1763 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1764 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1765 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1766 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1767 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1768 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
|
1769 |
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
|
1770 /* 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
|
1771 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
|
1772 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1773 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1774 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1775 counter++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1776 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1777 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1778 /* 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
|
1779 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1780 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1781 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1782 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
|
1783 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1784 /* 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
|
1785 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
|
1786 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1787 alSourceStop(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1788 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1789 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1790 fprintf(stderr, "19Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1791 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1792 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1793 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1794 /* 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
|
1795 * 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
|
1796 * 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
|
1797 * 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
|
1798 * 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
|
1799 * 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
|
1800 * 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
|
1801 * 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
|
1802 * 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
|
1803 * 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
|
1804 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1805 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1806 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1807 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1808 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1809 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1810 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1811 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1812 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
|
1813 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1814 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
|
1815 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1816 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1817 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1818 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1819 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1820 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1821 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1822 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1823 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1824 fprintf(stderr, "17Testing Error with buffers_processed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1825 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1826 ALmixer_SetError("Failed detecting still processed buffers: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1827 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1828 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1829 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1830 /* 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
|
1831 * to clear the source |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1832 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1833 if((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
|
1834 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1835 alSourcei(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1836 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1837 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1838 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1839 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1840 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
|
1841 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1842 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
|
1843 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1844 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1845 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1846 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1847 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1848 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
|
1849 |
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
|
1850 /* 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
|
1851 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
|
1852 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1853 Clean_Channel(i); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1854 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1855 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1856 /* Increment the counter */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1857 counter++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1858 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1859 /* 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
|
1860 * are bugs. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1861 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1862 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1863 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1864 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1865 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1866 / * 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
|
1867 * data will get messed up * / |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1868 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1869 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1870 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1871 /* Just in case */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1872 Is_Playing_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1873 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1874 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1875 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1876 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1877 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1878 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1879 return counter; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1880 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1881 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1882 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1883 /* 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
|
1884 * 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
|
1885 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1886 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
|
1887 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1888 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1889 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1890 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1891 /* 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
|
1892 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
|
1893 } |
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 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1896 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1897 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1898 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
|
1899 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1900 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1901 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
|
1902 } |
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 |
0 | 1905 |
1906 /* Note: Behaves, almost like SDL_mixer, but keep in mind | |
1907 * that there is no "music" channel anymore, so 0 | |
1908 * will remove everything. (Note, I no longer allow 0 | |
1909 * so it gets set to the default number.) | |
1910 * Also, callbacks for deleted channels will not be called. | |
1911 * I really need to do error checking, for realloc and | |
1912 * GenSources, but reversing the damage is too painful | |
1913 * for me to think about at the moment, so it's not in here. | |
1914 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1915 static ALint Internal_AllocateChannels(ALint numchans) |
0 | 1916 { |
1917 ALenum error; | |
1918 int i; | |
1919 /* Return info */ | |
1920 if(numchans < 0) | |
1921 { | |
1922 return Number_of_Channels_global; | |
1923 } | |
1924 if(0 == numchans) | |
1925 { | |
1926 numchans = ALMIXER_DEFAULT_NUM_CHANNELS; | |
1927 } | |
1928 /* No change */ | |
1929 if(numchans == Number_of_Channels_global) | |
1930 { | |
1931 return Number_of_Channels_global; | |
1932 } | |
1933 /* We need to increase the number of channels */ | |
1934 if(numchans > Number_of_Channels_global) | |
1935 { | |
1936 /* Not sure how safe this is, but SDL_mixer does it | |
1937 * the same way */ | |
1938 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1939 | |
1940 /* Allocate memory for the list of sources that map to the channels */ | |
1941 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
1942 | |
1943 for(i=Number_of_Channels_global; i<numchans; i++) | |
1944 { | |
1945 Init_Channel(i); | |
1946 /* Generate a new source and associate it with the channel */ | |
1947 alGenSources(1, &ALmixer_Channel_List[i].alsource); | |
1948 if((error = alGetError()) != AL_NO_ERROR) | |
1949 { | |
1950 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
|
1951 alGetString(error)); |
0 | 1952 } |
1953 /* Copy the source so the SourceMap has it too */ | |
1954 Source_Map_List[i].source = ALmixer_Channel_List[i].alsource; | |
1955 Source_Map_List[i].channel = i; | |
1956 /* Clean the channel because there are some things that need to | |
1957 * be done that can't happen until the source is set | |
1958 */ | |
1959 Clean_Channel(i); | |
1960 } | |
1961 | |
1962 /* The Source_Map_List must be sorted by source for binary searches | |
1963 */ | |
1964 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
1965 | |
1966 Number_of_Channels_global = numchans; | |
1967 return numchans; | |
1968 } | |
1969 /* Need to remove channels. This might be dangerous */ | |
1970 if(numchans < Number_of_Channels_global) | |
1971 { | |
1972 for(i=numchans; i<Number_of_Channels_global; i++) | |
1973 { | |
1974 /* Halt the channel */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1975 Internal_HaltChannel(i, AL_FALSE); |
0 | 1976 |
1977 /* Delete source associated with the channel */ | |
1978 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
1979 if((error = alGetError()) != AL_NO_ERROR) | |
1980 { | |
1981 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
|
1982 alGetString(error)); |
0 | 1983 } |
1984 } | |
1985 | |
1986 | |
1987 /* Not sure how safe this is, but SDL_mixer does it | |
1988 * the same way */ | |
1989 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1990 | |
1991 /* The tricky part is that we must remove the entries | |
1992 * in the source map that correspond to the deleted channels. | |
1993 * We'll resort the map by channels so we can pick them off | |
1994 * in order. | |
1995 */ | |
1996 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map_by_channel); | |
1997 | |
1998 /* Deallocate memory for the list of sources that map to the channels */ | |
1999 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
2000 | |
2001 /* Now resort the map by source and the correct num of chans */ | |
2002 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
2003 | |
2004 /* Reset the number of channels */ | |
2005 Number_of_Channels_global = numchans; | |
2006 return numchans; | |
2007 } | |
2008 /* Shouldn't ever reach here */ | |
2009 return -1; | |
2010 | |
2011 } | |
2012 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2013 static ALint Internal_ReserveChannels(ALint num) |
0 | 2014 { |
2015 /* Can't reserve more than the max num of channels */ | |
2016 /* Actually, I'll allow it for people who just want to | |
2017 * set the value really high to effectively disable | |
2018 * auto-assignment | |
2019 */ | |
2020 | |
2021 /* Return the current number of reserved channels */ | |
2022 if(num < 0) | |
2023 { | |
2024 return Number_of_Reserve_Channels_global; | |
2025 } | |
2026 Number_of_Reserve_Channels_global = num; | |
2027 return Number_of_Reserve_Channels_global; | |
2028 } | |
2029 | |
2030 | |
2031 /* This will rewind the SDL_Sound sample for streamed | |
2032 * samples and start buffering up the data for the next | |
2033 * playback. This may require samples to be halted | |
2034 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2035 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
|
2036 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2037 ALint retval = 0; |
0 | 2038 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2039 ALint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2040 ALint i; |
0 | 2041 */ |
2042 if(NULL == data) | |
2043 { | |
2044 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
|
2045 return AL_FALSE; |
0 | 2046 } |
2047 | |
2048 | |
2049 /* Might have to require Halt */ | |
2050 /* Okay, we assume Halt or natural stop has already | |
2051 * cleared the data buffers | |
2052 */ | |
2053 if(data->in_use) | |
2054 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2055 /* |
0 | 2056 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
|
2057 */ |
0 | 2058 /* |
2059 ALmixer_SetError("Data is in use. Cannot rewind unless all sources using the data are halted\n"); | |
2060 return -1; | |
2061 */ | |
2062 } | |
2063 | |
2064 | |
2065 /* Because Seek can alter things even in predecoded data, | |
2066 * decoded data must also be rewound | |
2067 */ | |
2068 if(data->decoded_all) | |
2069 { | |
2070 data->eof = 0; | |
2071 | |
2072 #if 0 | |
2073 #if defined(DISABLE_PREDECODED_SEEK) | |
2074 /* 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
|
2075 return AL_TRUE; |
0 | 2076 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) |
2077 /* This case is if the Sound_Sample has been deleted. | |
2078 * It assumes the data is already at the beginning. | |
2079 */ | |
2080 if(NULL == data->sample) | |
2081 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2082 return AL_TRUE; |
0 | 2083 } |
2084 /* Else, the sample has already been reallocated, | |
2085 * and we can fall to normal behavior | |
2086 */ | |
2087 #endif | |
2088 #endif | |
2089 /* If access_data, was enabled, the sound sample | |
2090 * still exists and we can do stuff. | |
2091 * If it's NULL, we can't do anything, but | |
2092 * it should already be "rewound". | |
2093 */ | |
2094 if(NULL == data->sample) | |
2095 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2096 return AL_TRUE; |
0 | 2097 } |
2098 /* Else, the sample has already been reallocated, | |
2099 * and we can fall to normal behavior | |
2100 */ | |
2101 | |
2102 Set_Predecoded_Seek_Position(data, 0); | |
2103 /* | |
2104 return data->total_bytes; | |
2105 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2106 return AL_TRUE; |
0 | 2107 } |
2108 | |
2109 /* Remaining stuff for streamed data */ | |
2110 | |
2111 data->eof = 0; | |
2112 retval = Sound_Rewind(data->sample); | |
2113 if(0 == retval) | |
2114 { | |
2115 ALmixer_SetError( Sound_GetError() ); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2116 return AL_FALSE; |
0 | 2117 } |
2118 #if 0 | |
2119 /* Clear error */ | |
2120 alGetError(); | |
2121 for(i=0; i<data->num_buffers; i++) | |
2122 { | |
2123 bytes_returned = GetMoreData(data, data->buffer[i]); | |
2124 if(-1 == bytes_returned) | |
2125 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2126 return AL_FALSE; |
0 | 2127 } |
2128 else if(0 == bytes_returned) | |
2129 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2130 return AL_FALSE; |
0 | 2131 } |
2132 retval += bytes_returned; | |
2133 | |
2134 } | |
2135 #endif | |
2136 | |
2137 | |
2138 | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2139 return AL_TRUE; |
0 | 2140 } |
2141 | |
2142 | |
2143 | |
2144 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2145 static ALint Internal_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2146 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2147 ALint retval = 0; |
0 | 2148 ALenum error; |
2149 ALint state; | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2150 ALint running_count = 0; |
0 | 2151 |
2152 if(channel >= Number_of_Channels_global) | |
2153 { | |
2154 ALmixer_SetError("Cannot rewind channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2155 return -1; | |
2156 } | |
2157 | |
2158 if((error = alGetError()) != AL_NO_ERROR) | |
2159 { | |
2160 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
|
2161 alGetString(error)); |
0 | 2162 } |
2163 /* Clear error */ | |
2164 alGetError(); | |
2165 | |
2166 /* If the user specified a specific channel */ | |
2167 if(channel >= 0) | |
2168 { | |
2169 /* only need to process channel if in use */ | |
2170 if(ALmixer_Channel_List[channel].channel_in_use) | |
2171 { | |
2172 | |
2173 /* What should I do? Do I just rewind the channel | |
2174 * or also rewind the data? Since the data is | |
2175 * shared, let's make it the user's responsibility | |
2176 * to rewind the data. | |
2177 */ | |
2178 if(ALmixer_Channel_List[channel].almixer_data->decoded_all) | |
2179 { | |
2180 alGetSourcei( | |
2181 ALmixer_Channel_List[channel].alsource, | |
2182 AL_SOURCE_STATE, &state | |
2183 ); | |
2184 if((error = alGetError()) != AL_NO_ERROR) | |
2185 { | |
2186 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
|
2187 alGetString(error)); |
0 | 2188 } |
2189 alSourceRewind(ALmixer_Channel_List[channel].alsource); | |
2190 if((error = alGetError()) != AL_NO_ERROR) | |
2191 { | |
2192 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2193 alGetString(error) ); |
0 | 2194 retval = -1; |
2195 } | |
2196 /* Need to resume playback if it was originally playing */ | |
2197 if(AL_PLAYING == state) | |
2198 { | |
2199 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2200 if((error = alGetError()) != AL_NO_ERROR) | |
2201 { | |
2202 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2203 alGetString(error) ); |
0 | 2204 retval = -1; |
2205 } | |
2206 } | |
2207 else if(AL_PAUSED == state) | |
2208 { | |
2209 /* HACK: The problem is that when paused, after | |
2210 * the Rewind, I can't get it off the INITIAL | |
2211 * state without restarting | |
2212 */ | |
2213 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2214 if((error = alGetError()) != AL_NO_ERROR) | |
2215 { | |
2216 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
|
2217 alGetString(error)); |
0 | 2218 } |
2219 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2220 if((error = alGetError()) != AL_NO_ERROR) | |
2221 { | |
2222 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2223 alGetString(error) ); |
0 | 2224 retval = -1; |
2225 } | |
2226 } | |
2227 } | |
2228 else | |
2229 { | |
2230 /* Streamed data is different. Rewinding the channel | |
2231 * does no good. Rewinding the data will have an | |
2232 * effect, but it will be lagged based on how | |
2233 * much data is queued. Recommend users call Halt | |
2234 * before rewind if they want immediate results. | |
2235 */ | |
2236 retval = Internal_RewindData(ALmixer_Channel_List[channel].almixer_data); | |
2237 } | |
2238 } | |
2239 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2240 /* The user wants to rewind all channels */ |
0 | 2241 else |
2242 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2243 ALint i; |
0 | 2244 for(i=0; i<Number_of_Channels_global; i++) |
2245 { | |
2246 /* only need to process channel if in use */ | |
2247 if(ALmixer_Channel_List[i].channel_in_use) | |
2248 { | |
2249 /* What should I do? Do I just rewind the channel | |
2250 * or also rewind the data? Since the data is | |
2251 * shared, let's make it the user's responsibility | |
2252 * to rewind the data. | |
2253 */ | |
2254 if(ALmixer_Channel_List[i].almixer_data->decoded_all) | |
2255 { | |
2256 alGetSourcei( | |
2257 ALmixer_Channel_List[i].alsource, | |
2258 AL_SOURCE_STATE, &state | |
2259 ); | |
2260 if((error = alGetError()) != AL_NO_ERROR) | |
2261 { | |
2262 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
|
2263 alGetString(error)); |
0 | 2264 } |
2265 alSourceRewind(ALmixer_Channel_List[i].alsource); | |
2266 if((error = alGetError()) != AL_NO_ERROR) | |
2267 { | |
2268 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2269 alGetString(error) ); |
0 | 2270 retval = -1; |
2271 } | |
2272 /* Need to resume playback if it was originally playing */ | |
2273 if(AL_PLAYING == state) | |
2274 { | |
2275 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2276 if((error = alGetError()) != AL_NO_ERROR) | |
2277 { | |
2278 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2279 alGetString(error) ); |
0 | 2280 retval = -1; |
2281 } | |
2282 } | |
2283 else if(AL_PAUSED == state) | |
2284 { | |
2285 /* HACK: The problem is that when paused, after | |
2286 * the Rewind, I can't get it off the INITIAL | |
2287 * state without restarting | |
2288 */ | |
2289 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2290 if((error = alGetError()) != AL_NO_ERROR) | |
2291 { | |
2292 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
|
2293 alGetString(error)); |
0 | 2294 } |
2295 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2296 if((error = alGetError()) != AL_NO_ERROR) | |
2297 { | |
2298 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2299 alGetString(error) ); |
0 | 2300 retval = -1; |
2301 } | |
2302 } | |
2303 } | |
2304 else | |
2305 { | |
2306 /* Streamed data is different. Rewinding the channel | |
2307 * does no good. Rewinding the data will have an | |
2308 * effect, but it will be lagged based on how | |
2309 * much data is queued. Recommend users call Halt | |
2310 * before rewind if they want immediate results. | |
2311 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2312 running_count += Internal_RewindData(ALmixer_Channel_List[i].almixer_data); |
0 | 2313 } |
2314 } | |
2315 } | |
2316 } | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2317 if(-1 == retval) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2318 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2319 return -1; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2320 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2321 else |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2322 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2323 return running_count; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2324 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2325 |
0 | 2326 } |
2327 | |
2328 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2329 static ALint Internal_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2330 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2331 ALint channel; |
0 | 2332 if(0 == source) |
2333 { | |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
2334 return Internal_RewindChannel(-1); |
0 | 2335 } |
2336 | |
2337 channel = Internal_GetChannel(source); | |
2338 if(-1 == channel) | |
2339 { | |
2340 ALmixer_SetError("Cannot rewind source: %s", ALmixer_GetError()); | |
2341 return 0; | |
2342 } | |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
2343 return Internal_RewindChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2344 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2345 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2346 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2347 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2348 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2349 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2350 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
|
2351 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2352 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2353 int ret_flag = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2354 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2355 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2356 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
|
2357 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2358 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2359 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2360 /* 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
|
2361 * 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
|
2362 * 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
|
2363 * 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
|
2364 * 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
|
2365 * to prevent sharing |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2366 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2367 if(0 == data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2368 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2369 if(data->in_use) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2370 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2371 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
|
2372 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2373 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2374 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2375 /* 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
|
2376 * This mainly affects streamed files, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2377 * so the check is placed here |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2378 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2379 if(data->eof) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2380 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2381 if( -1 == Internal_RewindData(data) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2382 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2383 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
|
2384 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2385 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2386 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2387 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2388 /* 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
|
2389 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2390 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2391 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2392 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
|
2393 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2394 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
|
2395 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2396 channel = i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2397 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2398 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2399 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2400 /* 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
|
2401 if(i == Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2402 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2403 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
|
2404 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2405 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2406 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2407 /* 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
|
2408 * out of bounds or in use */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2409 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2410 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2411 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2412 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2413 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
|
2414 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2415 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2416 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
|
2417 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2418 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
|
2419 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2420 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2421 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2422 /* 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
|
2423 if(loops < -1) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2424 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2425 loops = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2426 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2427 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2428 /* 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
|
2429 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2430 /* 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
|
2431 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
|
2432 data->in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2433 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2434 /* 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
|
2435 * (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
|
2436 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2437 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
|
2438 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
|
2439 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
|
2440 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2441 /* 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
|
2442 if(ticks < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2443 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2444 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
|
2445 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2446 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2447 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2448 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
|
2449 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2450 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2451 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2452 ALmixer_Channel_List[channel].halted = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2453 ALmixer_Channel_List[channel].paused = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2454 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2455 /* 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
|
2456 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2457 if( (-1 == loops) && (data->decoded_all) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2458 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2459 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
|
2460 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2461 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2462 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2463 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
|
2464 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2465 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2466 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2467 fprintf(stderr, "13Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2468 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2469 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2470 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2471 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2472 /* Because of the corner case, predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2473 * 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
|
2474 * Streams do not have this problem |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2475 * 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
|
2476 * avoid the conflict. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2477 * 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
|
2478 * Since streams, cannot share, only predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2479 * files are affected |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2480 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2481 if(data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2482 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2483 /* 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
|
2484 * 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
|
2485 * 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
|
2486 * must be +1 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2487 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2488 if(-1 == loops) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2489 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2490 /* -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
|
2491 * to add +1 to it */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2492 ALmixer_Channel_List[channel].loops = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2493 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
|
2494 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2495 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2496 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2497 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
|
2498 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
|
2499 } |
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2502 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2503 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2504 /* 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
|
2505 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
|
2506 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2507 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2508 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2509 /* 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
|
2510 /* 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
|
2511 * 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
|
2512 * 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
|
2513 * 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
|
2514 * 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
|
2515 * 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
|
2516 * easier to maintain. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2517 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2518 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2519 /* Clear the error flag */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2520 alGetError(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2521 if(data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2522 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2523 /* Bind the data to the source */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2524 alSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2525 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2526 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2527 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2528 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2529 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2530 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
|
2531 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2532 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2533 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2534 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2535 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2536 /* 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
|
2537 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
|
2538 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2539 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2540 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2541 /* 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
|
2542 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2543 ALuint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2544 ALuint j; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2545 data->num_buffers_in_use=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2546 /****** MODIFICATION must go here *********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2547 /* 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
|
2548 * 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
|
2549 * 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
|
2550 * 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
|
2551 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2552 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2553 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2554 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2555 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2556 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2557 /* No data or error */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2558 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
|
2559 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2560 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2561 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2562 /* 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
|
2563 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2564 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2565 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2566 /* 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
|
2567 * 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
|
2568 * before the last buffer is filled. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2569 * 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
|
2570 * 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
|
2571 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2572 |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2573 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2574 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
|
2575 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2576 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
|
2577 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2578 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2579 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
|
2580 fprintf(stderr, ">>>>>>>>>>>>>>>>>>HACK for GetMoreData2\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2581 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2582 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2583 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2584 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2585 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2586 * 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
|
2587 * 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
|
2588 * 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
|
2589 * 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
|
2590 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2591 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2592 if(bytes_returned < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2593 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2594 /* Error found */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2595 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
|
2596 /* 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
|
2597 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2598 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2599 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2600 else if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2601 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2602 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2603 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2604 /* No more data to buffer */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2605 /* Check for loops */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2606 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
|
2607 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2608 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2609 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
|
2610 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2611 if(0 == Sound_Rewind(data->sample)) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2612 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2613 fprintf(stderr, "error in rewind\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2614 ALmixer_SetError( Sound_GetError() ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2615 ALmixer_Channel_List[channel].loops = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2616 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2617 /* 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
|
2618 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2619 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2620 /* 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
|
2621 data->eof = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2622 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
|
2623 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2624 ALmixer_Channel_List[channel].loops--; |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2625 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2626 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
|
2627 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2628 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2629 /* 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
|
2630 * 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
|
2631 * into an infinite loop |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2632 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2633 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2634 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2635 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2636 if(bytes_returned <= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2637 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2638 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
|
2639 /* 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
|
2640 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2641 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2642 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2643 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2644 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2645 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2646 /* 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
|
2647 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2648 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2649 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2650 /* 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
|
2651 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2652 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2653 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2654 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
|
2655 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2656 data->num_buffers_in_use); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2657 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2658 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2659 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2660 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2661 data->num_buffers_in_use, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2662 data->buffer); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2663 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2664 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2665 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
|
2666 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2667 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2668 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2669 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2670 /* 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
|
2671 * 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
|
2672 * 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
|
2673 * 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
|
2674 * "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
|
2675 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2676 if(data->circular_buffer_queue != NULL) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2677 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2678 ALuint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2679 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2680 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
|
2681 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2682 // fprintf(stderr, "56c: CircularQueue_PushBack.\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2683 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
|
2684 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2685 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2686 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
|
2687 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
|
2688 } |
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2691 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2692 fprintf(stderr, "Queue in PlayTimed\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2693 CircularQueueUnsignedInt_Print(data->circular_buffer_queue); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2694 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2695 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2696 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2697 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2698 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2699 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2700 /****** END **********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2701 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2702 /* 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
|
2703 * so now we can play |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2704 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2705 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2706 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2707 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2708 ALmixer_SetError("Play failed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2709 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2710 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2711 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2712 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2713 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2714 /* 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
|
2715 Is_Playing_global++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2716 if(-1 == ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2717 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2718 fprintf(stderr, "BACKDOOR ERROR >>>>>>>>>>>>>>>>>>\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2719 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2720 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2721 return channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2722 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2723 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2724 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2725 /* 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
|
2726 * 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
|
2727 * 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
|
2728 * PlayChannelTimed() function call. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2729 * 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
|
2730 * 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
|
2731 * 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
|
2732 * 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
|
2733 * 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
|
2734 * 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
|
2735 * 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
|
2736 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2737 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
|
2738 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2739 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2740 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2741 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2742 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2743 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
|
2744 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2745 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2746 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2747 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2748 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2749 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2750 return Internal_GetSource(retval); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2751 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2752 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2753 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2754 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2755 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2756 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2757 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
|
2758 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2759 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2760 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
|
2761 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2762 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2763 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2764 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2765 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2766 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2767 return source; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2768 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2769 /* make compiler happy */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2770 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2771 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2772 |
0 | 2773 |
2774 | |
2775 | |
2776 /* Returns the channel or number of channels actually paused */ | |
2777 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2778 static ALint Internal_PauseChannel(ALint channel) |
0 | 2779 { |
2780 ALenum error; | |
2781 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2782 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2783 ALint counter = 0; |
0 | 2784 |
2785 if(channel >= Number_of_Channels_global) | |
2786 { | |
2787 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2788 return -1; | |
2789 } | |
2790 | |
2791 if((error = alGetError()) != AL_NO_ERROR) | |
2792 { | |
2793 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
|
2794 alGetString(error)); |
0 | 2795 } |
2796 /* Clear error */ | |
2797 alGetError(); | |
2798 | |
2799 /* If the user specified a specific channel */ | |
2800 if(channel >= 0) | |
2801 { | |
2802 /* only need to process channel if in use */ | |
2803 if(ALmixer_Channel_List[channel].channel_in_use) | |
2804 { | |
2805 /* We don't want to repause if already | |
2806 * paused because the fadeout/expire | |
2807 * timing will get messed up | |
2808 */ | |
2809 alGetSourcei( | |
2810 ALmixer_Channel_List[channel].alsource, | |
2811 AL_SOURCE_STATE, &state | |
2812 ); | |
2813 if((error = alGetError()) != AL_NO_ERROR) | |
2814 { | |
2815 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
|
2816 alGetString(error)); |
0 | 2817 } |
2818 if(AL_PLAYING == state) | |
2819 { | |
2820 /* Count the actual number of channels being paused */ | |
2821 counter++; | |
2822 | |
2823 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2824 if((error = alGetError()) != AL_NO_ERROR) | |
2825 { | |
2826 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2827 alGetString(error) ); |
0 | 2828 retval = -1; |
2829 } | |
2830 /* We need to pause the expire time count down */ | |
2831 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
2832 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2833 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2834 ALuint diff_time; |
0 | 2835 diff_time = current_time - |
2836 ALmixer_Channel_List[channel].start_time; | |
2837 /* When we unpause, we will want to reset | |
2838 * the start time so we can continue | |
2839 * to base calculations off GetTicks(). | |
2840 * This means we need to subtract the amount | |
2841 * of time already used up from expire_ticks. | |
2842 */ | |
2843 ALmixer_Channel_List[channel].expire_ticks = | |
2844 ALmixer_Channel_List[channel].expire_ticks - | |
2845 diff_time; | |
2846 /* Because -1 is a special value, we can't | |
2847 * allow the time to go negative | |
2848 */ | |
2849 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2850 { | |
2851 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2852 } | |
2853 } | |
2854 /* Do the same as expire time for fading */ | |
2855 if(ALmixer_Channel_List[channel].fade_enabled) | |
2856 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2857 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2858 ALuint diff_time; |
0 | 2859 diff_time = current_time - |
2860 ALmixer_Channel_List[channel].fade_start_time; | |
2861 /* When we unpause, we will want to reset | |
2862 * the start time so we can continue | |
2863 * to base calculations off GetTicks(). | |
2864 * This means we need to subtract the amount | |
2865 * of time already used up from expire_ticks. | |
2866 */ | |
2867 ALmixer_Channel_List[channel].fade_expire_ticks = | |
2868 ALmixer_Channel_List[channel].fade_expire_ticks - | |
2869 diff_time; | |
2870 /* Don't allow the time to go negative */ | |
2871 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2872 { | |
2873 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2874 } | |
2875 } /* End fade check */ | |
2876 } /* End if PLAYING */ | |
2877 } /* End If in use */ | |
2878 } /* End specific channel */ | |
2879 /* The user wants to halt all channels */ | |
2880 else | |
2881 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2882 ALint i; |
0 | 2883 for(i=0; i<Number_of_Channels_global; i++) |
2884 { | |
2885 /* only need to process channel if in use */ | |
2886 if(ALmixer_Channel_List[i].channel_in_use) | |
2887 { | |
2888 /* We don't want to repause if already | |
2889 * paused because the fadeout/expire | |
2890 * timing will get messed up | |
2891 */ | |
2892 alGetSourcei( | |
2893 ALmixer_Channel_List[i].alsource, | |
2894 AL_SOURCE_STATE, &state | |
2895 ); | |
2896 if((error = alGetError()) != AL_NO_ERROR) | |
2897 { | |
2898 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
|
2899 alGetString(error)); |
0 | 2900 } |
2901 if(AL_PLAYING == state) | |
2902 { | |
2903 /* Count the actual number of channels being paused */ | |
2904 counter++; | |
2905 | |
2906 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2907 if((error = alGetError()) != AL_NO_ERROR) | |
2908 { | |
2909 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2910 alGetString(error) ); |
0 | 2911 retval = -1; |
2912 } | |
2913 /* We need to pause the expire time count down */ | |
2914 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
2915 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2916 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2917 ALuint diff_time; |
0 | 2918 diff_time = current_time - |
2919 ALmixer_Channel_List[i].start_time; | |
2920 /* When we unpause, we will want to reset | |
2921 * the start time so we can continue | |
2922 * to base calculations off GetTicks(). | |
2923 * This means we need to subtract the amount | |
2924 * of time already used up from expire_ticks. | |
2925 */ | |
2926 ALmixer_Channel_List[i].expire_ticks = | |
2927 ALmixer_Channel_List[i].expire_ticks - | |
2928 diff_time; | |
2929 /* Because -1 is a special value, we can't | |
2930 * allow the time to go negative | |
2931 */ | |
2932 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2933 { | |
2934 ALmixer_Channel_List[i].expire_ticks = 0; | |
2935 } | |
2936 } | |
2937 /* Do the same as expire time for fading */ | |
2938 if(ALmixer_Channel_List[i].fade_enabled) | |
2939 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2940 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2941 ALuint diff_time; |
0 | 2942 diff_time = current_time - |
2943 ALmixer_Channel_List[i].fade_start_time; | |
2944 /* When we unpause, we will want to reset | |
2945 * the start time so we can continue | |
2946 * to base calculations off GetTicks(). | |
2947 * This means we need to subtract the amount | |
2948 * of time already used up from expire_ticks. | |
2949 */ | |
2950 ALmixer_Channel_List[i].fade_expire_ticks = | |
2951 ALmixer_Channel_List[i].fade_expire_ticks - | |
2952 diff_time; | |
2953 /* Don't allow the time to go negative */ | |
2954 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2955 { | |
2956 ALmixer_Channel_List[i].expire_ticks = 0; | |
2957 } | |
2958 } /* End fade check */ | |
2959 } /* End if PLAYING */ | |
2960 } /* End channel in use */ | |
2961 } /* End for-loop */ | |
2962 } | |
2963 if(-1 == retval) | |
2964 { | |
2965 return -1; | |
2966 } | |
2967 return counter; | |
2968 } | |
2969 | |
2970 /* 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
|
2971 static ALint Internal_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2972 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2973 ALint channel; |
0 | 2974 if(0 == source) |
2975 { | |
2976 return Internal_PauseChannel(-1); | |
2977 } | |
2978 | |
2979 channel = Internal_GetChannel(source); | |
2980 if(-1 == channel) | |
2981 { | |
2982 ALmixer_SetError("Cannot pause source: %s", ALmixer_GetError()); | |
2983 return -1; | |
2984 } | |
2985 return Internal_PauseChannel(channel); | |
2986 } | |
2987 | |
2988 | |
2989 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2990 static ALint Internal_ResumeChannel(ALint channel) |
0 | 2991 { |
2992 ALint state; | |
2993 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2994 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2995 ALint counter = 0; |
0 | 2996 |
2997 if(channel >= Number_of_Channels_global) | |
2998 { | |
2999 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
3000 return -1; | |
3001 } | |
3002 | |
3003 if((error = alGetError()) != AL_NO_ERROR) | |
3004 { | |
3005 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
|
3006 alGetString(error)); |
0 | 3007 } |
3008 /* Clear error */ | |
3009 alGetError(); | |
3010 | |
3011 /* If the user specified a specific channel */ | |
3012 if(channel >= 0) | |
3013 { | |
3014 /* only need to process channel if in use */ | |
3015 if(ALmixer_Channel_List[channel].channel_in_use) | |
3016 { | |
3017 alGetSourcei( | |
3018 ALmixer_Channel_List[channel].alsource, | |
3019 AL_SOURCE_STATE, &state | |
3020 ); | |
3021 if((error = alGetError()) != AL_NO_ERROR) | |
3022 { | |
3023 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
|
3024 alGetString(error)); |
0 | 3025 } |
3026 if(AL_PAUSED == state) | |
3027 { | |
3028 /* Count the actual number of channels resumed */ | |
3029 counter++; | |
3030 | |
3031 /* We need to resume the expire time count down */ | |
3032 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
3033 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3034 ALmixer_Channel_List[channel].start_time = ALmixer_GetTicks(); |
0 | 3035 } |
3036 /* Do the same as expire time for fading */ | |
3037 if(ALmixer_Channel_List[channel].fade_enabled) | |
3038 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3039 ALmixer_Channel_List[channel].fade_start_time = ALmixer_GetTicks(); |
0 | 3040 } |
3041 | |
3042 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
3043 if((error = alGetError()) != AL_NO_ERROR) | |
3044 { | |
3045 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3046 alGetString(error) ); |
0 | 3047 retval = -1; |
3048 } | |
3049 } | |
3050 } | |
3051 } | |
3052 /* The user wants to halt all channels */ | |
3053 else | |
3054 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3055 ALint i; |
0 | 3056 for(i=0; i<Number_of_Channels_global; i++) |
3057 { | |
3058 /* only need to process channel if in use */ | |
3059 if(ALmixer_Channel_List[i].channel_in_use) | |
3060 { | |
3061 alGetSourcei( | |
3062 ALmixer_Channel_List[i].alsource, | |
3063 AL_SOURCE_STATE, &state | |
3064 ); | |
3065 if((error = alGetError()) != AL_NO_ERROR) | |
3066 { | |
3067 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
|
3068 alGetString(error)); |
0 | 3069 } |
3070 if(AL_PAUSED == state) | |
3071 { | |
3072 /* Count the actual number of channels resumed */ | |
3073 counter++; | |
3074 | |
3075 /* We need to resume the expire time count down */ | |
3076 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
3077 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3078 ALmixer_Channel_List[i].start_time = ALmixer_GetTicks(); |
0 | 3079 } |
3080 /* Do the same as expire time for fading */ | |
3081 if(ALmixer_Channel_List[i].fade_enabled) | |
3082 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3083 ALmixer_Channel_List[i].fade_start_time = ALmixer_GetTicks(); |
0 | 3084 } |
3085 | |
3086 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
3087 if((error = alGetError()) != AL_NO_ERROR) | |
3088 { | |
3089 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3090 alGetString(error) ); |
0 | 3091 retval = -1; |
3092 } | |
3093 } | |
3094 } | |
3095 } | |
3096 } | |
3097 if(-1 == retval) | |
3098 { | |
3099 return -1; | |
3100 } | |
3101 return counter; | |
3102 } | |
3103 | |
3104 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3105 static ALint Internal_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3106 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3107 ALint channel; |
0 | 3108 if(0 == source) |
3109 { | |
3110 return Internal_ResumeChannel(-1); | |
3111 } | |
3112 | |
3113 channel = Internal_GetChannel(source); | |
3114 if(-1 == channel) | |
3115 { | |
3116 ALmixer_SetError("Cannot resume source: %s", ALmixer_GetError()); | |
3117 return -1; | |
3118 } | |
3119 return Internal_ResumeChannel(channel); | |
3120 } | |
3121 | |
3122 | |
3123 /* Might consider setting eof to 0 as a "feature" | |
3124 * This will allow seek to end to stay there because | |
3125 * Play automatically rewinds if at the end */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3126 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
|
3127 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3128 ALint retval; |
0 | 3129 |
3130 if(NULL == data) | |
3131 { | |
3132 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
|
3133 return AL_FALSE; |
0 | 3134 } |
3135 | |
3136 /* Seek for predecoded files involves moving the chunk pointer around */ | |
3137 if(data->decoded_all) | |
3138 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3139 ALuint byte_position; |
0 | 3140 |
3141 /* OpenAL doesn't seem to like it if I change the buffer | |
3142 * while playing (crashes), so I must require that Seek only | |
3143 * be done when the data is not in use. | |
3144 * Since data may be shared among multiple sources, | |
3145 * I can't shut them down myself, so I have to return an error. | |
3146 */ | |
3147 if(data->in_use) | |
3148 { | |
3149 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
|
3150 return AL_FALSE; |
0 | 3151 } |
3152 #if 0 | |
3153 #if defined(DISABLE_PREDECODED_SEEK) | |
3154 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
|
3155 return AL_FALSE; |
0 | 3156 |
3157 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
3158 /* By default, ALmixer frees the Sound_Sample for predecoded | |
3159 * samples because of the potential memory waste. | |
3160 * However, to seek a sample, we need to have a full | |
3161 * copy of the data around. So the strategy is to | |
3162 * recreate a hackish Sound_Sample to be used for seeking | |
3163 * purposes. If Sound_Sample is NULL, we will reallocate | |
3164 * memory for it and then procede as if everything | |
3165 * was normal. | |
3166 */ | |
3167 if(NULL == data->sample) | |
3168 { | |
3169 if( -1 == Reconstruct_Sound_Sample(data) ) | |
3170 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3171 return AL_FALSE; |
0 | 3172 } |
3173 } | |
3174 #endif | |
3175 #endif | |
3176 /* If access_data was set, then we still have the | |
3177 * Sound_Sample and we can move around in the data. | |
3178 * If it was not set, the data has been freed and we | |
3179 * cannot do anything because there is no way to | |
3180 * recover the data because OpenAL won't let us | |
3181 * get access to the buffers | |
3182 */ | |
3183 if(NULL == data->sample) | |
3184 { | |
3185 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
|
3186 return AL_FALSE; |
0 | 3187 } |
3188 | |
3189 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
|
3190 retval = Set_Predecoded_Seek_Position(data, byte_position); |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3191 if(-1 == retval) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3192 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3193 return AL_FALSE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3194 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3195 else |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3196 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3197 return AL_TRUE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3198 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3199 |
0 | 3200 } |
3201 else | |
3202 { | |
3203 /* Reset eof flag?? */ | |
3204 data->eof = 0; | |
3205 retval = Sound_Seek(data->sample, msec); | |
3206 if(0 == retval) | |
3207 { | |
3208 ALmixer_SetError(Sound_GetError()); | |
3209 | |
3210 fprintf(stderr, "Sound seek error: %s\n", ALmixer_GetError()); | |
3211 /* Try rewinding to clean up? */ | |
3212 /* | |
3213 Internal_RewindData(data); | |
3214 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3215 return AL_FALSE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3216 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3217 return AL_TRUE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3218 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3219 |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3220 return AL_TRUE; |
0 | 3221 } |
3222 | |
3223 | |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3224 static ALint Internal_SeekChannel(ALint channel, ALuint msec) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3225 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3226 ALint retval = 0; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3227 ALenum error; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3228 ALint state; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3229 ALint running_count = 0; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3230 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3231 if(0 == msec) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3232 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3233 return Internal_RewindChannel(channel); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3234 } |
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 if(channel >= Number_of_Channels_global) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3237 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3238 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
|
3239 return -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3240 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3241 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3242 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3243 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3244 fprintf(stderr, "24Testing error: %s\n", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3245 alGetString(error)); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3246 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3247 /* Clear error */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3248 alGetError(); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3249 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3250 /* If the user specified a specific channel */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3251 if(channel >= 0) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3252 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3253 /* only need to process channel if in use */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3254 if(ALmixer_Channel_List[channel].channel_in_use) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3255 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3256 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3257 /* What should I do? Do I just rewind the channel |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3258 * or also rewind the data? Since the data is |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3259 * shared, let's make it the user's responsibility |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3260 * to rewind the data. |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3261 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3262 if(ALmixer_Channel_List[channel].almixer_data->decoded_all) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3263 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3264 /* convert milliseconds to seconds */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3265 ALfloat sec_offset = msec / 1000.0f; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3266 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3267 alGetSourcei( |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3268 ALmixer_Channel_List[channel].alsource, |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3269 AL_SOURCE_STATE, &state |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3270 ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3271 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3272 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3273 fprintf(stderr, "25Testing error: %s\n", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3274 alGetString(error)); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3275 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3276 /* OpenAL seek */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3277 alSourcef(ALmixer_Channel_List[channel].alsource, AL_SEC_OFFSET, sec_offset); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3278 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3279 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3280 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3281 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3282 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3283 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3284 /* Need to resume playback if it was originally playing */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3285 if(AL_PLAYING == state) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3286 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3287 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3288 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3289 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3290 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3291 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3292 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3293 } |
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 else if(AL_PAUSED == state) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3296 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3297 /* HACK: The problem is that when paused, after |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3298 * the Rewind, I can't get it off the INITIAL |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3299 * state without restarting |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3300 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3301 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3302 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3303 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3304 fprintf(stderr, "25Testing error: %s\n", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3305 alGetString(error)); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3306 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3307 alSourcePause(ALmixer_Channel_List[channel].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3308 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3309 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3310 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3311 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3312 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3313 } |
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 else |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3317 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3318 /* Streamed data is different. Rewinding the channel |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3319 * does no good. Rewinding the data will have an |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3320 * effect, but it will be lagged based on how |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3321 * much data is queued. Recommend users call Halt |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3322 * before rewind if they want immediate results. |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3323 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3324 retval = Internal_SeekData(ALmixer_Channel_List[channel].almixer_data, msec); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3325 } |
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 /* The user wants to rewind all channels */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3329 else |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3330 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3331 ALint i; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3332 ALfloat sec_offset = msec / 1000.0f; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3333 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3334 for(i=0; i<Number_of_Channels_global; i++) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3335 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3336 /* only need to process channel if in use */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3337 if(ALmixer_Channel_List[i].channel_in_use) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3338 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3339 /* What should I do? Do I just rewind the channel |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3340 * or also rewind the data? Since the data is |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3341 * shared, let's make it the user's responsibility |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3342 * to rewind the data. |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3343 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3344 if(ALmixer_Channel_List[i].almixer_data->decoded_all) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3345 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3346 alGetSourcei( |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3347 ALmixer_Channel_List[i].alsource, |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3348 AL_SOURCE_STATE, &state |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3349 ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3350 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3351 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3352 fprintf(stderr, "26Testing error: %s\n", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3353 alGetString(error)); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3354 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3355 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3356 alSourcef(ALmixer_Channel_List[channel].alsource, AL_SEC_OFFSET, sec_offset); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3357 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3358 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3359 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3360 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3361 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3362 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3363 /* Need to resume playback if it was originally playing */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3364 if(AL_PLAYING == state) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3365 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3366 alSourcePlay(ALmixer_Channel_List[i].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3367 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3368 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3369 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3370 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3371 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3372 } |
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 else if(AL_PAUSED == state) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3375 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3376 /* HACK: The problem is that when paused, after |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3377 * the Rewind, I can't get it off the INITIAL |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3378 * state without restarting |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3379 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3380 alSourcePlay(ALmixer_Channel_List[i].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3381 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3382 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3383 fprintf(stderr, "27Testing error: %s\n", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3384 alGetString(error)); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3385 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3386 alSourcePause(ALmixer_Channel_List[i].alsource); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3387 if((error = alGetError()) != AL_NO_ERROR) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3388 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3389 ALmixer_SetError("%s", |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3390 alGetString(error) ); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3391 retval = -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3392 } |
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 else |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3396 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3397 /* Streamed data is different. Rewinding the channel |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3398 * does no good. Rewinding the data will have an |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3399 * effect, but it will be lagged based on how |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3400 * much data is queued. Recommend users call Halt |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3401 * before rewind if they want immediate results. |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3402 */ |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3403 running_count += Internal_SeekData(ALmixer_Channel_List[i].almixer_data, msec); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3404 } |
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 if(-1 == retval) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3409 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3410 return -1; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3411 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3412 else |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3413 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3414 return running_count; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3415 } |
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 static ALint Internal_SeekSource(ALuint source, ALuint msec) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3420 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3421 ALint channel; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3422 if(0 == source) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3423 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3424 return Internal_SeekChannel(-1, msec); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3425 } |
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 channel = Internal_GetChannel(source); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3428 if(-1 == channel) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3429 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3430 ALmixer_SetError("Cannot seek source: %s", ALmixer_GetError()); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3431 return 0; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3432 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3433 return Internal_SeekChannel(channel, msec); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
3434 } |
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 |
0 | 3437 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3438 static ALint Internal_FadeInChannelTimed(ALint channel, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 3439 { |
3440 ALfloat value; | |
3441 ALenum error; | |
3442 ALfloat original_value; | |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
3443 /* ALuint current_time = ALmixer_GetTicks(); */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3444 ALint retval; |
0 | 3445 |
3446 | |
3447 | |
3448 if(channel >= Number_of_Channels_global) | |
3449 { | |
3450 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); | |
3451 return -1; | |
3452 } | |
3453 /* Let's call PlayChannelTimed to do the job. | |
3454 * There are two catches: | |
3455 * First is that we must set the volumes before the play call(s). | |
3456 * Second is that we must initialize the channel values | |
3457 */ | |
3458 | |
3459 if(channel < 0) | |
3460 { | |
3461 /* This might cause a problem for threads/race conditions. | |
3462 * We need to set the volume on an unknown channel, | |
3463 * so we need to request a channel first. Remember | |
3464 * that requesting a channel doesn't lock and it | |
3465 * could be surrendered to somebody else before we claim it. | |
3466 */ | |
3467 channel = Internal_GetChannel(0); | |
3468 if(-1 == channel) | |
3469 { | |
3470 return -1; | |
3471 } | |
3472 } | |
3473 else if(ALmixer_Channel_List[channel].channel_in_use) | |
3474 { | |
3475 ALmixer_SetError("Channel %d is already in use", channel); | |
3476 return -1; | |
3477 } | |
3478 | |
3479 | |
3480 /* Get the original volume in case of a problem */ | |
3481 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
|
3482 AL_GAIN, &original_value); |
0 | 3483 |
3484 if((error = alGetError()) != AL_NO_ERROR) | |
3485 { | |
3486 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
|
3487 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3488 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3489 ALmixer_Channel_List[channel].fade_end_volume = original_value; |
0 | 3490 |
3491 /* Get the Min volume */ | |
3492 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3493 AL_MIN_GAIN, &value); | |
3494 if((error = alGetError()) != AL_NO_ERROR) | |
3495 { | |
3496 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
|
3497 alGetString(error)); |
0 | 3498 } |
3499 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3500 | |
3501 /* Set the actual volume */ | |
3502 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
|
3503 AL_GAIN, value); |
0 | 3504 if((error = alGetError()) != AL_NO_ERROR) |
3505 { | |
3506 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
|
3507 alGetString(error)); |
0 | 3508 } |
3509 | |
3510 | |
3511 /* Now call PlayChannelTimed */ | |
3512 retval = Internal_PlayChannelTimed(channel, data, loops, expire_ticks); | |
3513 if(-1 == retval) | |
3514 { | |
3515 /* Chance of failure is actually pretty high since | |
3516 * a channel might already be in use or streamed | |
3517 * data can be shared | |
3518 */ | |
3519 /* Restore the original value to avoid accidental | |
3520 * distruption of playback | |
3521 */ | |
3522 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
|
3523 AL_GAIN, original_value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3524 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3525 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3526 fprintf(stderr, "38Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3527 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3528 } |
0 | 3529 return retval; |
3530 } | |
3531 | |
3532 /* We can't accept 0 as a value because of div-by-zero. | |
3533 * If zero, just call PlayChannelTimed at normal | |
3534 * volume | |
3535 */ | |
3536 if(0 == fade_ticks) | |
3537 { | |
3538 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
|
3539 AL_GAIN, |
0 | 3540 ALmixer_Channel_List[channel].fade_end_volume |
3541 ); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3542 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3543 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3544 fprintf(stderr, "39Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3545 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3546 } |
0 | 3547 |
3548 return retval; | |
3549 } | |
3550 | |
3551 /* Enable fading effects via the flag */ | |
3552 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3553 /* Set fade start time */ | |
3554 ALmixer_Channel_List[channel].fade_start_time | |
3555 = ALmixer_Channel_List[channel].start_time; | |
3556 /* Set the fade expire ticks */ | |
3557 ALmixer_Channel_List[channel].fade_expire_ticks = fade_ticks; | |
3558 | |
3559 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3560 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / fade_ticks; | |
3561 | |
3562 return retval; | |
3563 | |
3564 } | |
3565 | |
3566 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3567 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
|
3568 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3569 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3570 ALint retval; |
0 | 3571 if(0 == source) |
3572 { | |
3573 retval = Internal_FadeInChannelTimed(-1, data, loops, fade_ticks, expire_ticks); | |
3574 if(-1 == retval) | |
3575 { | |
3576 return 0; | |
3577 } | |
3578 else | |
3579 { | |
3580 return Internal_GetSource(retval); | |
3581 } | |
3582 } | |
3583 | |
3584 channel = Internal_GetChannel(source); | |
3585 if(-1 == channel) | |
3586 { | |
3587 ALmixer_SetError("Cannot FadeIn source: %s", ALmixer_GetError()); | |
3588 return 0; | |
3589 } | |
3590 retval = Internal_FadeInChannelTimed(channel, data, loops, fade_ticks, expire_ticks); | |
3591 if(-1 == retval) | |
3592 { | |
3593 return 0; | |
3594 } | |
3595 else | |
3596 { | |
3597 return source; | |
3598 } | |
3599 /* make compiler happy */ | |
3600 return 0; | |
3601 } | |
3602 | |
3603 | |
3604 | |
3605 | |
3606 /* Will fade out currently playing channels. | |
3607 * 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
|
3608 static ALint Internal_FadeOutChannel(ALint channel, ALuint ticks) |
0 | 3609 { |
3610 ALfloat value; | |
3611 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3612 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3613 ALuint counter = 0; |
0 | 3614 |
3615 /* We can't accept 0 as a value because of div-by-zero. | |
3616 * If zero, just call Halt at normal | |
3617 * volume | |
3618 */ | |
3619 if(0 == ticks) | |
3620 { | |
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
|
3621 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 3622 } |
3623 | |
3624 | |
3625 if(channel >= Number_of_Channels_global) | |
3626 { | |
3627 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); | |
3628 return -1; | |
3629 } | |
3630 | |
3631 if(channel >= 0) | |
3632 { | |
3633 if(ALmixer_Channel_List[channel].channel_in_use) | |
3634 { | |
3635 /* Get the current volume */ | |
3636 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
|
3637 AL_GAIN, &value); |
0 | 3638 ALmixer_Channel_List[channel].fade_start_volume = value; |
3639 if((error = alGetError()) != AL_NO_ERROR) | |
3640 { | |
3641 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
|
3642 alGetString(error)); |
0 | 3643 } |
3644 | |
3645 /* Get the Min volume */ | |
3646 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3647 AL_MIN_GAIN, &value); | |
3648 if((error = alGetError()) != AL_NO_ERROR) | |
3649 { | |
3650 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
|
3651 alGetString(error)); |
0 | 3652 } |
3653 ALmixer_Channel_List[channel].fade_end_volume = value; | |
3654 | |
3655 /* Set expire start time */ | |
3656 ALmixer_Channel_List[channel].start_time = current_time; | |
3657 /* Set the expire ticks */ | |
3658 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
3659 /* Set fade start time */ | |
3660 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3661 /* Set the fade expire ticks */ | |
3662 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3663 /* Enable fading effects via the flag */ | |
3664 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3665 | |
3666 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3667 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3668 | |
3669 counter++; | |
3670 } | |
3671 } | |
3672 /* Else need to fade out all channels */ | |
3673 else | |
3674 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3675 ALint i; |
0 | 3676 for(i=0; i<Number_of_Channels_global; i++) |
3677 { | |
3678 if(ALmixer_Channel_List[i].channel_in_use) | |
3679 { | |
3680 /* Get the current volume */ | |
3681 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
|
3682 AL_GAIN, &value); |
0 | 3683 ALmixer_Channel_List[i].fade_start_volume = value; |
3684 if((error = alGetError()) != AL_NO_ERROR) | |
3685 { | |
3686 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
|
3687 alGetString(error)); |
0 | 3688 } |
3689 | |
3690 /* Get the Min volume */ | |
3691 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
3692 AL_MIN_GAIN, &value); | |
3693 if((error = alGetError()) != AL_NO_ERROR) | |
3694 { | |
3695 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
|
3696 alGetString(error)); |
0 | 3697 } |
3698 ALmixer_Channel_List[i].fade_end_volume = value; | |
3699 | |
3700 /* Set expire start time */ | |
3701 ALmixer_Channel_List[i].start_time = current_time; | |
3702 /* Set the expire ticks */ | |
3703 ALmixer_Channel_List[i].expire_ticks = ticks; | |
3704 /* Set fade start time */ | |
3705 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3706 /* Set the fade expire ticks */ | |
3707 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3708 /* Enable fading effects via the flag */ | |
3709 ALmixer_Channel_List[i].fade_enabled = 1; | |
3710 | |
3711 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3712 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3713 | |
3714 counter++; | |
3715 } | |
3716 } /* End for loop */ | |
3717 } | |
3718 return counter; | |
3719 } | |
3720 | |
3721 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3722 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
|
3723 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3724 ALint channel; |
0 | 3725 if(0 == source) |
3726 { | |
3727 return Internal_FadeOutChannel(-1, ticks); | |
3728 } | |
3729 | |
3730 channel = Internal_GetChannel(source); | |
3731 if(-1 == channel) | |
3732 { | |
3733 ALmixer_SetError("Cannot FadeOut source: %s", ALmixer_GetError()); | |
3734 return -1; | |
3735 } | |
3736 return Internal_FadeOutChannel(channel, ticks); | |
3737 } | |
3738 | |
3739 | |
3740 /* Will fade currently playing channels. | |
3741 * It starts at the current volume level and go to target | |
3742 * Only affects channels that are playing | |
3743 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3744 static ALint Internal_FadeChannel(ALint channel, ALuint ticks, ALfloat volume) |
0 | 3745 { |
3746 ALfloat value; | |
3747 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3748 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3749 ALuint counter = 0; |
0 | 3750 |
3751 if(channel >= Number_of_Channels_global) | |
3752 { | |
3753 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); | |
3754 return -1; | |
3755 } | |
3756 | |
3757 if(channel >= 0) | |
3758 { | |
3759 if(volume < ALmixer_Channel_List[channel].min_volume) | |
3760 { | |
3761 volume = ALmixer_Channel_List[channel].min_volume; | |
3762 } | |
3763 else if(volume > ALmixer_Channel_List[channel].max_volume) | |
3764 { | |
3765 volume = ALmixer_Channel_List[channel].max_volume; | |
3766 } | |
3767 | |
3768 if(ALmixer_Channel_List[channel].channel_in_use) | |
3769 { | |
3770 if(ticks > 0) | |
3771 { | |
3772 /* Get the current volume */ | |
3773 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
|
3774 AL_GAIN, &value); |
0 | 3775 if((error = alGetError()) != AL_NO_ERROR) |
3776 { | |
3777 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
|
3778 alGetString(error)); |
0 | 3779 } |
3780 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3781 | |
3782 /* Set the target volume */ | |
3783 ALmixer_Channel_List[channel].fade_end_volume = volume; | |
3784 | |
3785 /* Set fade start time */ | |
3786 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3787 /* Set the fade expire ticks */ | |
3788 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3789 /* Enable fading effects via the flag */ | |
3790 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3791 | |
3792 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3793 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3794 } | |
3795 else | |
3796 { | |
3797 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
|
3798 AL_GAIN, volume); |
0 | 3799 if((error = alGetError()) != AL_NO_ERROR) |
3800 { | |
3801 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
|
3802 alGetString(error)); |
0 | 3803 } |
3804 } | |
3805 counter++; | |
3806 } | |
3807 } | |
3808 /* Else need to fade out all channels */ | |
3809 else | |
3810 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3811 ALint i; |
0 | 3812 for(i=0; i<Number_of_Channels_global; i++) |
3813 { | |
3814 if(volume < ALmixer_Channel_List[i].min_volume) | |
3815 { | |
3816 volume = ALmixer_Channel_List[i].min_volume; | |
3817 } | |
3818 else if(volume > ALmixer_Channel_List[i].max_volume) | |
3819 { | |
3820 volume = ALmixer_Channel_List[i].max_volume; | |
3821 } | |
3822 | |
3823 if(ALmixer_Channel_List[i].channel_in_use) | |
3824 { | |
3825 if(ticks > 0) | |
3826 { | |
3827 /* Get the current volume */ | |
3828 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
|
3829 AL_GAIN, &value); |
0 | 3830 if((error = alGetError()) != AL_NO_ERROR) |
3831 { | |
3832 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
|
3833 alGetString(error)); |
0 | 3834 } |
3835 ALmixer_Channel_List[i].fade_start_volume = value; | |
3836 | |
3837 /* Set target volume */ | |
3838 ALmixer_Channel_List[i].fade_end_volume = volume; | |
3839 | |
3840 /* Set fade start time */ | |
3841 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3842 /* Set the fade expire ticks */ | |
3843 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3844 /* Enable fading effects via the flag */ | |
3845 ALmixer_Channel_List[i].fade_enabled = 1; | |
3846 | |
3847 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3848 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3849 } | |
3850 else | |
3851 { | |
3852 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
|
3853 AL_GAIN, volume); |
0 | 3854 if((error = alGetError()) != AL_NO_ERROR) |
3855 { | |
3856 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
|
3857 alGetString(error)); |
0 | 3858 } |
3859 } | |
3860 counter++; | |
3861 } | |
3862 } /* End for loop */ | |
3863 } | |
3864 return counter; | |
3865 } | |
3866 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3867 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
|
3868 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3869 ALint channel; |
0 | 3870 if(0 == source) |
3871 { | |
3872 return Internal_FadeChannel(-1, ticks, volume); | |
3873 } | |
3874 | |
3875 channel = Internal_GetChannel(source); | |
3876 if(-1 == channel) | |
3877 { | |
3878 ALmixer_SetError("Cannot Fade source: %s", ALmixer_GetError()); | |
3879 return -1; | |
3880 } | |
3881 return Internal_FadeChannel(channel, ticks, volume); | |
3882 } | |
3883 | |
3884 | |
3885 | |
3886 | |
3887 /* Set a volume regardless if it's in use or not. | |
3888 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3889 static ALboolean Internal_SetVolumeChannel(ALint channel, ALfloat volume) |
0 | 3890 { |
3891 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3892 ALboolean retval = AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3893 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3894 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3895 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3896 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
|
3897 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3898 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3899 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3900 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3901 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3902 if(volume < 0.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3903 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3904 volume = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3905 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3906 else if(volume > 1.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3907 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3908 volume = 1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3909 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3910 alSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3911 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3912 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3913 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3914 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3915 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3916 retval = AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3917 } |
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3920 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3921 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3922 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
|
3923 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3924 if(volume < 0.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3925 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3926 volume = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3927 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3928 else if(volume > 1.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3929 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3930 volume = 1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3931 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3932 alSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3933 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3934 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3935 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3936 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3937 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3938 retval = AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3939 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3940 } |
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 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3943 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3944 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3945 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
|
3946 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3947 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3948 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3949 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3950 return Internal_SetVolumeChannel(-1, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3951 } |
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 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3954 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3955 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3956 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
|
3957 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3958 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3959 return Internal_SetVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3960 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3961 |
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 static ALfloat Internal_GetVolumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3964 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3965 ALfloat value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3966 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3967 ALfloat running_total = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3968 ALfloat retval = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3969 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3970 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3971 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3972 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
|
3973 return -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3974 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3975 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3976 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3977 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3978 alGetSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3979 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3980 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3981 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3982 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3983 retval = -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3984 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3985 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3986 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3987 retval = value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3988 } |
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3991 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3992 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3993 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
|
3994 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3995 alGetSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3996 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3997 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3998 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3999 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4000 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4001 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4002 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4003 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4004 running_total += value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4005 } |
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 if(0 == Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4008 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4009 ALmixer_SetError("No channels are allocated"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4010 retval = -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4011 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4012 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4013 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4014 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
|
4015 } |
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 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4018 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4019 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4020 static ALfloat Internal_GetVolumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4021 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4022 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4023 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4024 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4025 return Internal_GetVolumeChannel(-1); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4026 } |
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 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4029 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4030 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4031 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
|
4032 return -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4033 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4034 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4035 return Internal_GetVolumeChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4036 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4037 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4038 |
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 /* 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
|
4041 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4042 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
|
4043 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4044 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4045 ALboolean retval = AL_TRUE; |
0 | 4046 |
4047 if(channel >= Number_of_Channels_global) | |
4048 { | |
4049 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
|
4050 return AL_FALSE; |
0 | 4051 } |
4052 | |
4053 if(channel >= 0) | |
4054 { | |
4055 if(volume < 0.0f) | |
4056 { | |
4057 volume = 0.0f; | |
4058 } | |
4059 else if(volume > 1.0f) | |
4060 { | |
4061 volume = 1.0f; | |
4062 } | |
4063 ALmixer_Channel_List[channel].max_volume = volume; | |
4064 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4065 AL_MAX_GAIN, volume); | |
4066 if((error = alGetError()) != AL_NO_ERROR) | |
4067 { | |
4068 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4069 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4070 retval = AL_FALSE; |
0 | 4071 } |
4072 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
4073 { | |
4074 ALmixer_Channel_List[channel].min_volume = volume; | |
4075 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4076 AL_MIN_GAIN, volume); | |
4077 if((error = alGetError()) != AL_NO_ERROR) | |
4078 { | |
4079 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4080 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4081 retval = AL_FALSE; |
0 | 4082 } |
4083 } | |
4084 } | |
4085 else | |
4086 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4087 ALint i; |
0 | 4088 for(i=0; i<Number_of_Channels_global; i++) |
4089 { | |
4090 if(volume < 0.0f) | |
4091 { | |
4092 volume = 0.0f; | |
4093 } | |
4094 else if(volume > 1.0f) | |
4095 { | |
4096 volume = 1.0f; | |
4097 } | |
4098 ALmixer_Channel_List[i].max_volume = volume; | |
4099 alSourcef(ALmixer_Channel_List[i].alsource, | |
4100 AL_MAX_GAIN, volume); | |
4101 if((error = alGetError()) != AL_NO_ERROR) | |
4102 { | |
4103 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4104 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4105 retval = AL_FALSE; |
0 | 4106 } |
4107 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
4108 { | |
4109 ALmixer_Channel_List[i].min_volume = volume; | |
4110 alSourcef(ALmixer_Channel_List[i].alsource, | |
4111 AL_MIN_GAIN, volume); | |
4112 if((error = alGetError()) != AL_NO_ERROR) | |
4113 { | |
4114 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4115 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4116 retval = AL_FALSE; |
0 | 4117 } |
4118 } | |
4119 } | |
4120 } | |
4121 return retval; | |
4122 } | |
4123 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4124 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
|
4125 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4126 ALint channel; |
0 | 4127 if(0 == source) |
4128 { | |
4129 return Internal_SetMaxVolumeChannel(-1, volume); | |
4130 } | |
4131 | |
4132 channel = Internal_GetChannel(source); | |
4133 if(-1 == channel) | |
4134 { | |
4135 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
|
4136 return AL_FALSE; |
0 | 4137 } |
4138 return Internal_SetMaxVolumeChannel(channel, volume); | |
4139 } | |
4140 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4141 static ALfloat Internal_GetMaxVolumeChannel(ALint channel) |
0 | 4142 { |
4143 /* | |
4144 ALfloat value; | |
4145 ALenum error; | |
4146 */ | |
4147 ALfloat running_total = 0.0f; | |
4148 ALfloat retval = 0.0f; | |
4149 | |
4150 if(channel >= Number_of_Channels_global) | |
4151 { | |
4152 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); | |
4153 return -1.0f; | |
4154 } | |
4155 | |
4156 if(channel >= 0) | |
4157 { | |
4158 /* | |
4159 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
4160 AL_GAIN, &value); | |
4161 if((error = alGetError()) != AL_NO_ERROR) | |
4162 { | |
4163 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4164 alGetString(error) ); |
0 | 4165 retval = -1.0f; |
4166 } | |
4167 else | |
4168 { | |
4169 retval = value; | |
4170 } | |
4171 */ | |
4172 retval = ALmixer_Channel_List[channel].max_volume; | |
4173 | |
4174 } | |
4175 else | |
4176 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4177 ALint i; |
0 | 4178 for(i=0; i<Number_of_Channels_global; i++) |
4179 { | |
4180 /* | |
4181 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
4182 AL_GAIN, &value); | |
4183 if((error = alGetError()) != AL_NO_ERROR) | |
4184 { | |
4185 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4186 alGetString(error) ); |
0 | 4187 retval = -1; |
4188 } | |
4189 else | |
4190 { | |
4191 running_total += value; | |
4192 } | |
4193 */ | |
4194 running_total += ALmixer_Channel_List[i].max_volume; | |
4195 } | |
4196 if(0 == Number_of_Channels_global) | |
4197 { | |
4198 ALmixer_SetError("No channels are allocated"); | |
4199 retval = -1.0f; | |
4200 } | |
4201 else | |
4202 { | |
4203 retval = running_total / Number_of_Channels_global; | |
4204 } | |
4205 } | |
4206 return retval; | |
4207 } | |
4208 | |
4209 static ALfloat Internal_GetMaxVolumeSource(ALuint source) | |
4210 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4211 ALint channel; |
0 | 4212 if(0 == source) |
4213 { | |
4214 return Internal_GetMaxVolumeChannel(-1); | |
4215 } | |
4216 | |
4217 channel = Internal_GetChannel(source); | |
4218 if(-1 == channel) | |
4219 { | |
4220 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
4221 return -1.0f; | |
4222 } | |
4223 | |
4224 return Internal_GetMaxVolumeChannel(channel); | |
4225 } | |
4226 | |
4227 | |
4228 /* Set a volume regardless if it's in use or not. | |
4229 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4230 static ALboolean Internal_SetMinVolumeChannel(ALint channel, ALfloat volume) |
0 | 4231 { |
4232 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4233 ALboolean retval = AL_TRUE; |
0 | 4234 |
4235 if(channel >= Number_of_Channels_global) | |
4236 { | |
4237 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
|
4238 return AL_FALSE; |
0 | 4239 } |
4240 | |
4241 if(channel >= 0) | |
4242 { | |
4243 if(volume < 0.0f) | |
4244 { | |
4245 volume = 0.0f; | |
4246 } | |
4247 else if(volume > 1.0f) | |
4248 { | |
4249 volume = 1.0f; | |
4250 } | |
4251 ALmixer_Channel_List[channel].min_volume = volume; | |
4252 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4253 AL_MIN_GAIN, volume); | |
4254 if((error = alGetError()) != AL_NO_ERROR) | |
4255 { | |
4256 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4257 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4258 retval = AL_FALSE; |
0 | 4259 } |
4260 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
4261 { | |
4262 ALmixer_Channel_List[channel].max_volume = volume; | |
4263 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4264 AL_MAX_GAIN, volume); | |
4265 if((error = alGetError()) != AL_NO_ERROR) | |
4266 { | |
4267 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4268 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4269 retval = AL_FALSE; |
0 | 4270 } |
4271 } | |
4272 } | |
4273 else | |
4274 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4275 ALint i; |
0 | 4276 for(i=0; i<Number_of_Channels_global; i++) |
4277 { | |
4278 if(volume < 0.0f) | |
4279 { | |
4280 volume = 0.0f; | |
4281 } | |
4282 else if(volume > 1.0f) | |
4283 { | |
4284 volume = 1.0f; | |
4285 } | |
4286 ALmixer_Channel_List[i].min_volume = volume; | |
4287 alSourcef(ALmixer_Channel_List[i].alsource, | |
4288 AL_MIN_GAIN, volume); | |
4289 if((error = alGetError()) != AL_NO_ERROR) | |
4290 { | |
4291 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4292 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4293 retval = AL_FALSE; |
0 | 4294 } |
4295 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
4296 { | |
4297 ALmixer_Channel_List[i].max_volume = volume; | |
4298 alSourcef(ALmixer_Channel_List[i].alsource, | |
4299 AL_MAX_GAIN, volume); | |
4300 if((error = alGetError()) != AL_NO_ERROR) | |
4301 { | |
4302 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4303 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4304 retval = AL_FALSE; |
0 | 4305 } |
4306 } | |
4307 } | |
4308 } | |
4309 return retval; | |
4310 } | |
4311 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4312 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
|
4313 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4314 ALint channel; |
0 | 4315 if(0 == source) |
4316 { | |
4317 return Internal_SetMinVolumeChannel(-1, volume); | |
4318 } | |
4319 | |
4320 channel = Internal_GetChannel(source); | |
4321 if(-1 == channel) | |
4322 { | |
4323 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
|
4324 return AL_FALSE; |
0 | 4325 } |
4326 return Internal_SetMinVolumeChannel(channel, volume); | |
4327 } | |
4328 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4329 static ALfloat Internal_GetMinVolumeChannel(ALint channel) |
0 | 4330 { |
4331 /* | |
4332 ALfloat value; | |
4333 ALenum error; | |
4334 */ | |
4335 ALfloat running_total = 0.0f; | |
4336 ALfloat retval = 0.0f; | |
4337 | |
4338 if(channel >= Number_of_Channels_global) | |
4339 { | |
4340 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); | |
4341 return -1.0f; | |
4342 } | |
4343 | |
4344 if(channel >= 0) | |
4345 { | |
4346 /* | |
4347 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
4348 AL_GAIN, &value); | |
4349 if((error = alGetError()) != AL_NO_ERROR) | |
4350 { | |
4351 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4352 alGetString(error) ); |
0 | 4353 retval = -1.0f; |
4354 } | |
4355 else | |
4356 { | |
4357 retval = value; | |
4358 } | |
4359 */ | |
4360 retval = ALmixer_Channel_List[channel].min_volume; | |
4361 | |
4362 } | |
4363 else | |
4364 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4365 ALint i; |
0 | 4366 for(i=0; i<Number_of_Channels_global; i++) |
4367 { | |
4368 /* | |
4369 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
4370 AL_GAIN, &value); | |
4371 if((error = alGetError()) != AL_NO_ERROR) | |
4372 { | |
4373 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4374 alGetString(error) ); |
0 | 4375 retval = -1; |
4376 } | |
4377 else | |
4378 { | |
4379 running_total += value; | |
4380 } | |
4381 */ | |
4382 running_total += ALmixer_Channel_List[i].min_volume; | |
4383 } | |
4384 if(0 == Number_of_Channels_global) | |
4385 { | |
4386 ALmixer_SetError("No channels are allocated"); | |
4387 retval = -1.0f; | |
4388 } | |
4389 else | |
4390 { | |
4391 retval = running_total / Number_of_Channels_global; | |
4392 } | |
4393 } | |
4394 return retval; | |
4395 } | |
4396 | |
4397 static ALfloat Internal_GetMinVolumeSource(ALuint source) | |
4398 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4399 ALint channel; |
0 | 4400 if(0 == source) |
4401 { | |
4402 return Internal_GetMinVolumeChannel(-1); | |
4403 } | |
4404 | |
4405 channel = Internal_GetChannel(source); | |
4406 if(-1 == channel) | |
4407 { | |
4408 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
4409 return -1.0f; | |
4410 } | |
4411 | |
4412 return Internal_GetMinVolumeChannel(channel); | |
4413 } | |
4414 | |
4415 | |
4416 /* Changes the listener volume */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4417 static ALboolean Internal_SetMasterVolume(ALfloat volume) |
0 | 4418 { |
4419 ALenum error; | |
4420 alListenerf(AL_GAIN, volume); | |
4421 if((error = alGetError()) != AL_NO_ERROR) | |
4422 { | |
4423 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4424 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4425 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4426 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4427 return AL_TRUE; |
0 | 4428 } |
4429 | |
4430 static ALfloat Internal_GetMasterVolume() | |
4431 { | |
4432 ALenum error; | |
4433 ALfloat volume; | |
4434 alGetListenerf(AL_GAIN, &volume); | |
4435 if((error = alGetError()) != AL_NO_ERROR) | |
4436 { | |
4437 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4438 alGetString(error) ); |
0 | 4439 return -1.0f; |
4440 } | |
4441 return volume; | |
4442 } | |
4443 | |
4444 | |
4445 | |
4446 | |
4447 /* Will fade out currently playing channels. | |
4448 * 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
|
4449 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
|
4450 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4451 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4452 ALuint counter = 0; |
0 | 4453 |
4454 /* We can't accept 0 as a value because of div-by-zero. | |
4455 * If zero, just call Halt at normal | |
4456 * volume | |
4457 */ | |
4458 if(0 == ticks) | |
4459 { | |
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
|
4460 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 4461 } |
4462 if(ticks < -1) | |
4463 { | |
4464 ticks = -1; | |
4465 } | |
4466 | |
4467 | |
4468 if(channel >= Number_of_Channels_global) | |
4469 { | |
4470 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); | |
4471 return -1; | |
4472 } | |
4473 | |
4474 if(channel >= 0) | |
4475 { | |
4476 if(ALmixer_Channel_List[channel].channel_in_use) | |
4477 { | |
4478 /* Set expire start time */ | |
4479 ALmixer_Channel_List[channel].start_time = current_time; | |
4480 /* Set the expire ticks */ | |
4481 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
4482 | |
4483 counter++; | |
4484 } | |
4485 } | |
4486 /* Else need to fade out all channels */ | |
4487 else | |
4488 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4489 ALint i; |
0 | 4490 for(i=0; i<Number_of_Channels_global; i++) |
4491 { | |
4492 if(ALmixer_Channel_List[i].channel_in_use) | |
4493 { | |
4494 /* Set expire start time */ | |
4495 ALmixer_Channel_List[i].start_time = current_time; | |
4496 /* Set the expire ticks */ | |
4497 ALmixer_Channel_List[i].expire_ticks = ticks; | |
4498 | |
4499 counter++; | |
4500 } | |
4501 } /* End for loop */ | |
4502 } | |
4503 return counter; | |
4504 } | |
4505 | |
4506 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4507 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
|
4508 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4509 ALint channel; |
0 | 4510 if(0 == source) |
4511 { | |
4512 return Internal_ExpireChannel(-1, ticks); | |
4513 } | |
4514 | |
4515 channel = Internal_GetChannel(source); | |
4516 if(-1 == channel) | |
4517 { | |
4518 ALmixer_SetError("Cannot Expire source: %s", ALmixer_GetError()); | |
4519 return -1; | |
4520 } | |
4521 return Internal_ExpireChannel(channel, ticks); | |
4522 } | |
4523 | |
4524 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4525 static ALint Internal_QueryChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4526 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4527 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4528 ALint counter = 0; |
0 | 4529 if(channel >= Number_of_Channels_global) |
4530 { | |
4531 ALmixer_SetError("Invalid channel: %d", channel); | |
4532 return -1; | |
4533 } | |
4534 | |
4535 if(channel >= 0) | |
4536 { | |
4537 return ALmixer_Channel_List[channel].channel_in_use; | |
4538 } | |
4539 | |
4540 /* Else, return the number of channels in use */ | |
4541 for(i=0; i<Number_of_Channels_global; i++) | |
4542 { | |
4543 if(ALmixer_Channel_List[i].channel_in_use) | |
4544 { | |
4545 counter++; | |
4546 } | |
4547 } | |
4548 return counter; | |
4549 } | |
4550 | |
4551 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4552 static ALint Internal_QuerySource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4553 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4554 ALint channel; |
0 | 4555 if(0 == source) |
4556 { | |
4557 return Internal_QueryChannel(-1); | |
4558 } | |
4559 | |
4560 channel = Internal_GetChannel(source); | |
4561 if(-1 == channel) | |
4562 { | |
4563 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4564 return -1; | |
4565 } | |
4566 | |
4567 return Internal_QueryChannel(channel); | |
4568 } | |
4569 | |
4570 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4571 static ALuint Internal_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4572 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4573 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4574 ALuint counter = 0; |
0 | 4575 |
4576 | |
4577 /* Else, return the number of channels in use */ | |
4578 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4579 { | |
4580 if(ALmixer_Channel_List[i].channel_in_use) | |
4581 { | |
4582 counter++; | |
4583 } | |
4584 } | |
4585 return counter; | |
4586 } | |
4587 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4588 static ALuint Internal_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4589 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4590 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4591 ALuint counter = 0; |
0 | 4592 |
4593 | |
4594 /* Else, return the number of channels in use */ | |
4595 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4596 { | |
4597 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4598 { | |
4599 counter++; | |
4600 } | |
4601 } | |
4602 return counter; | |
4603 } | |
4604 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4605 static ALuint Internal_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4606 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4607 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4608 ALuint counter = 0; |
0 | 4609 |
4610 | |
4611 /* Else, return the number of channels in use */ | |
4612 for(i=0; i<Number_of_Channels_global; i++) | |
4613 { | |
4614 if(ALmixer_Channel_List[i].channel_in_use) | |
4615 { | |
4616 counter++; | |
4617 } | |
4618 } | |
4619 return counter; | |
4620 } | |
4621 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4622 static ALuint Internal_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4623 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4624 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4625 ALuint counter = 0; |
0 | 4626 |
4627 | |
4628 /* Else, return the number of channels in use */ | |
4629 for(i=0; i<Number_of_Channels_global; i++) | |
4630 { | |
4631 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4632 { | |
4633 counter++; | |
4634 } | |
4635 } | |
4636 return counter; | |
4637 } | |
4638 | |
4639 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4640 static ALint Internal_PlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4641 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4642 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4643 ALint counter = 0; |
0 | 4644 ALint state; |
4645 | |
4646 if(channel >= Number_of_Channels_global) | |
4647 { | |
4648 ALmixer_SetError("Invalid channel: %d", channel); | |
4649 return -1; | |
4650 } | |
4651 | |
4652 if(channel >= 0) | |
4653 { | |
4654 if(ALmixer_Channel_List[channel].channel_in_use) | |
4655 { | |
4656 alGetSourcei( | |
4657 ALmixer_Channel_List[channel].alsource, | |
4658 AL_SOURCE_STATE, &state | |
4659 ); | |
4660 if(AL_PLAYING == state) | |
4661 { | |
4662 return 1; | |
4663 } | |
4664 } | |
4665 return 0; | |
4666 } | |
4667 | |
4668 /* Else, return the number of channels in use */ | |
4669 for(i=0; i<Number_of_Channels_global; i++) | |
4670 { | |
4671 if(ALmixer_Channel_List[i].channel_in_use) | |
4672 { | |
4673 alGetSourcei( | |
4674 ALmixer_Channel_List[i].alsource, | |
4675 AL_SOURCE_STATE, &state | |
4676 ); | |
4677 if(AL_PLAYING == state) | |
4678 { | |
4679 counter++; | |
4680 } | |
4681 } | |
4682 } | |
4683 return counter; | |
4684 } | |
4685 | |
4686 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4687 static ALint Internal_PlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4688 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4689 ALint channel; |
0 | 4690 if(0 == source) |
4691 { | |
4692 return Internal_PlayingChannel(-1); | |
4693 } | |
4694 | |
4695 channel = Internal_GetChannel(source); | |
4696 if(-1 == channel) | |
4697 { | |
4698 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4699 return -1; | |
4700 } | |
4701 | |
4702 return Internal_PlayingChannel(channel); | |
4703 } | |
4704 | |
4705 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4706 static ALint Internal_PausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4707 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4708 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4709 ALint counter = 0; |
0 | 4710 ALint state; |
4711 | |
4712 if(channel >= Number_of_Channels_global) | |
4713 { | |
4714 ALmixer_SetError("Invalid channel: %d", channel); | |
4715 return -1; | |
4716 } | |
4717 | |
4718 if(channel >= 0) | |
4719 { | |
4720 if(ALmixer_Channel_List[channel].channel_in_use) | |
4721 { | |
4722 alGetSourcei( | |
4723 ALmixer_Channel_List[channel].alsource, | |
4724 AL_SOURCE_STATE, &state | |
4725 ); | |
4726 if(AL_PAUSED == state) | |
4727 { | |
4728 return 1; | |
4729 } | |
4730 } | |
4731 return 0; | |
4732 } | |
4733 | |
4734 /* Else, return the number of channels in use */ | |
4735 for(i=0; i<Number_of_Channels_global; i++) | |
4736 { | |
4737 if(ALmixer_Channel_List[i].channel_in_use) | |
4738 { | |
4739 alGetSourcei( | |
4740 ALmixer_Channel_List[i].alsource, | |
4741 AL_SOURCE_STATE, &state | |
4742 ); | |
4743 if(AL_PAUSED == state) | |
4744 { | |
4745 counter++; | |
4746 } | |
4747 } | |
4748 } | |
4749 return counter; | |
4750 } | |
4751 | |
4752 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4753 static ALint Internal_PausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4754 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4755 ALint channel; |
0 | 4756 if(0 == source) |
4757 { | |
4758 return Internal_PausedChannel(-1); | |
4759 } | |
4760 | |
4761 channel = Internal_GetChannel(source); | |
4762 if(-1 == channel) | |
4763 { | |
4764 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4765 return -1; | |
4766 } | |
4767 | |
4768 return Internal_PausedChannel(channel); | |
4769 } | |
4770 | |
4771 | |
4772 | |
4773 | |
4774 | |
4775 | |
4776 /* Private function for Updating ALmixer. | |
4777 * This is a very big and ugly function. | |
4778 * It should return the number of buffers that were | |
4779 * queued during the call. The value might be | |
4780 * used to guage how long you might wait to | |
4781 * call the next update loop in case you are worried | |
4782 * about preserving CPU cycles. The idea is that | |
4783 * when a buffer is queued, there was probably some | |
4784 * CPU intensive looping which took awhile. | |
4785 * 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
|
4786 * Timing the call with ALmixer_GetTicks() would produce |
0 | 4787 * more accurate information. |
4788 * Returns a negative value if there was an error, | |
4789 * the value being the number of errors. | |
4790 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4791 static ALint Update_ALmixer(void* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4792 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4793 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4794 ALint error_flag = 0; |
0 | 4795 ALenum error; |
4796 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4797 ALint i=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4798 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4799 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4800 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4801 #endif |
0 | 4802 if(0 == ALmixer_Initialized) |
4803 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4804 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4805 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4806 #endif |
0 | 4807 return 0; |
4808 } | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4809 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4810 /* Bypass if in interruption event */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4811 if(NULL == alcGetCurrentContext()) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4812 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4813 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4814 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4815 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4816 return 0; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4817 } |
0 | 4818 |
4819 /* Check the quick flag to see if anything needs updating */ | |
4820 /* If anything is playing, then we have to do work */ | |
4821 if( 0 == Is_Playing_global) | |
4822 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4823 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4824 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4825 #endif |
0 | 4826 return 0; |
4827 } | |
4828 /* Clear error */ | |
4829 if((error = alGetError()) != AL_NO_ERROR) | |
4830 { | |
4831 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
|
4832 alGetString(error)); |
0 | 4833 } |
4834 alGetError(); | |
4835 | |
4836 for(i=0; i<Number_of_Channels_global; i++) | |
4837 { | |
4838 if( ALmixer_Channel_List[i].channel_in_use ) | |
4839 { | |
4840 | |
4841 /* For simplicity, before we do anything else, | |
4842 * we can check the timeout and fading values | |
4843 * and do the appropriate things | |
4844 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4845 ALuint current_time = ALmixer_GetTicks(); |
0 | 4846 |
4847 /* Check to see if we need to halt due to Timed play */ | |
4848 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
4849 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4850 ALuint target_time = (ALuint)ALmixer_Channel_List[i].expire_ticks |
0 | 4851 + ALmixer_Channel_List[i].start_time; |
4852 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4853 AL_SOURCE_STATE, &state); | |
4854 if((error = alGetError()) != AL_NO_ERROR) | |
4855 { | |
4856 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
|
4857 alGetString(error)); |
0 | 4858 } |
4859 | |
4860 /* Check the time, and also make sure that it is not | |
4861 * paused (if paused, we don't want to make the | |
4862 * evaluation because when resumed, we will adjust | |
4863 * the times to compensate for the pause). | |
4864 */ | |
4865 if( (current_time >= target_time) | |
4866 && (state != AL_PAUSED) ) | |
4867 { | |
4868 /* 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
|
4869 Internal_HaltChannel(i, AL_FALSE); |
0 | 4870 if((error = alGetError()) != AL_NO_ERROR) |
4871 { | |
4872 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
|
4873 alGetString(error)); |
0 | 4874 } |
4875 | |
4876 /* Everything should be done so go on to the next loop */ | |
4877 continue; | |
4878 } | |
4879 } /* End if time expired check */ | |
4880 | |
4881 /* Check to see if we need to adjust the volume for fading */ | |
4882 if( ALmixer_Channel_List[i].fade_enabled ) | |
4883 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4884 ALuint target_time = ALmixer_Channel_List[i].fade_expire_ticks |
0 | 4885 + ALmixer_Channel_List[i].fade_start_time; |
4886 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4887 AL_SOURCE_STATE, &state); | |
4888 if((error = alGetError()) != AL_NO_ERROR) | |
4889 { | |
4890 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
|
4891 alGetString(error)); |
0 | 4892 } |
4893 | |
4894 /* Check the time, and also make sure that it is not | |
4895 * paused (if paused, we don't want to make the | |
4896 * evaluation because when resumed, we will adjust | |
4897 * the times to compensate for the pause). | |
4898 */ | |
4899 if(state != AL_PAUSED) | |
4900 { | |
4901 ALfloat t; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4902 ALuint delta_time; |
0 | 4903 ALfloat current_volume; |
4904 if(current_time >= target_time) | |
4905 { | |
4906 /* Need to constrain value to the end time | |
4907 * (can't go pass the value for calculations) | |
4908 */ | |
4909 current_time = target_time; | |
4910 /* We can disable the fade flag now */ | |
4911 ALmixer_Channel_List[i].fade_enabled = 0; | |
4912 } | |
4913 /* Use the linear interpolation formula: | |
4914 * X = (1-t)x0 + tx1 | |
4915 * where x0 would be the start value | |
4916 * and x1 is the final value | |
4917 * and t is delta_time*inv_time (adjusts 0 <= time <= 1) | |
4918 * delta_time = current_time-start_time | |
4919 * inv_time = 1/ (end_time-start_time) | |
4920 * so t = current_time-start_time / (end_time-start_time) | |
4921 * | |
4922 */ | |
4923 delta_time = current_time - ALmixer_Channel_List[i].fade_start_time; | |
4924 t = (ALfloat) delta_time * ALmixer_Channel_List[i].fade_inv_time; | |
4925 current_volume = (1.0f-t) * ALmixer_Channel_List[i].fade_start_volume | |
4926 + t * ALmixer_Channel_List[i].fade_end_volume; | |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
4927 /* |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
4928 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
|
4929 */ |
0 | 4930 /* Set the volume */ |
4931 alSourcef(ALmixer_Channel_List[i].alsource, | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
4932 AL_GAIN, current_volume); |
0 | 4933 if((error = alGetError()) != AL_NO_ERROR) |
4934 { | |
4935 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
|
4936 alGetString(error)); |
0 | 4937 } |
4938 | |
4939 /* | |
4940 fprintf(stderr, "Current time =%d\n", current_time); | |
4941 fprintf(stderr, "Current vol=%f on channel %d\n", current_volume, i); | |
4942 */ | |
4943 } /* End if not PAUSED */ | |
4944 } /* End if fade_enabled */ | |
4945 | |
4946 | |
4947 /* Okay, now that the time expired and fading stuff | |
4948 * is done, do the rest of the hard stuff | |
4949 */ | |
4950 | |
4951 | |
4952 /* For predecoded, check to see if done */ | |
4953 if( ALmixer_Channel_List[i].almixer_data->decoded_all ) | |
4954 { | |
4955 | |
4956 #if 0 | |
4957 /********* Remove this **********/ | |
4958 ALint buffers_processed; | |
4959 ALint buffers_still_queued; | |
4960 fprintf(stderr, "For Predecoded\n"); | |
4961 | |
4962 alGetSourcei( | |
4963 ALmixer_Channel_List[i].alsource, | |
4964 AL_SOURCE_STATE, &state | |
4965 ); | |
4966 switch(state) { | |
4967 case AL_PLAYING: | |
4968 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
4969 break; | |
4970 case AL_PAUSED: | |
4971 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
4972 break; | |
4973 case AL_STOPPED: | |
4974 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
4975 break; | |
4976 case AL_INITIAL: | |
4977 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
4978 break; | |
4979 default: | |
4980 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
4981 break; | |
4982 } | |
4983 | |
4984 alGetSourcei( | |
4985 ALmixer_Channel_List[i].alsource, | |
4986 AL_BUFFERS_PROCESSED, &buffers_processed | |
4987 ); | |
4988 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
4989 | |
4990 alGetSourcei( | |
4991 ALmixer_Channel_List[i].alsource, | |
4992 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4993 ); | |
4994 | |
4995 /******** END REMOVE *******/ | |
4996 #endif | |
4997 /* FIXME: Ugh! Somewhere an alError is being thrown ("Invalid Enum Value"), but I can't | |
4998 * find it. It only seems to be thrown for OS X. I placed error messages after every al* | |
4999 * command I could find in the above loops, but the error doesn't seem to show | |
5000 * up until around here. I mistook it for a get queued buffers | |
5001 * error in OS X. I don't think there's an error down there. | |
5002 * For now, I'm clearing the error here. | |
5003 */ | |
5004 | |
5005 if((error = alGetError()) != AL_NO_ERROR) | |
5006 { | |
5007 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
|
5008 alGetString(error)); |
0 | 5009 } |
5010 | |
5011 | |
5012 alGetSourcei( | |
5013 ALmixer_Channel_List[i].alsource, | |
5014 AL_SOURCE_STATE, &state | |
5015 ); | |
5016 if((error = alGetError()) != AL_NO_ERROR) | |
5017 { | |
5018 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
|
5019 alGetString(error)); |
0 | 5020 } |
5021 | |
5022 | |
5023 if(AL_STOPPED == state) | |
5024 { | |
5025 /* Playback has ended. | |
5026 * Loop if necessary, or launch callback | |
5027 * and clear channel (or clear channel and | |
5028 * then launch callback?) | |
5029 */ | |
5030 | |
5031 | |
5032 /* Need to check for loops */ | |
5033 if(ALmixer_Channel_List[i].loops != 0) | |
5034 { | |
5035 /* Corner Case: If the buffer has | |
5036 * been modified using Seek, | |
5037 * the loop will start at the seek | |
5038 * position. | |
5039 */ | |
5040 if(ALmixer_Channel_List[i].loops != -1) | |
5041 { | |
5042 ALmixer_Channel_List[i].loops--; | |
5043 } | |
5044 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5045 if((error = alGetError()) != AL_NO_ERROR) | |
5046 { | |
5047 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
|
5048 alGetString(error)); |
0 | 5049 } |
5050 continue; | |
5051 } | |
5052 /* No loops. End play. */ | |
5053 else | |
5054 { | |
5055 /* Problem: It seems that when mixing | |
5056 * streamed and predecoded sources, | |
5057 * the previous instance lingers, | |
5058 * so we need to force remove | |
5059 * the data from the source. | |
5060 * The sharing problem | |
5061 * occurs when a previous predecoded buffer is played on | |
5062 * a source, and then a streamed source is played later | |
5063 * on that same source. OpenAL isn't consistently | |
5064 * removing the previous buffer so both get played. | |
5065 * (Different dists seem to have different quirks. | |
5066 * The problem might lead to crashes in the worst case.) | |
5067 */ | |
5068 /* Additional problem: There is another | |
5069 * inconsistency among OpenAL distributions. | |
5070 * Both Loki and Creative Windows seem to keep | |
5071 * the buffer queued which requires removing. | |
5072 * But the Creative Macintosh version does | |
5073 * not have any buffer queued after play | |
5074 * and it returns the error: Invalid Enum Value | |
5075 * if I try to unqueue it. | |
5076 * So I'm going to put in a check to see if I | |
5077 * can detect any buffers queued first | |
5078 * and then unqueue them if I can see them. | |
5079 * Additional note: The new CoreAudio based | |
5080 * implementation leaves it's buffer queued | |
5081 * like Loki and Creative Windows. But | |
5082 * considering all the problems I'm having | |
5083 * with the different distributions, this | |
5084 * check seems reasonable. | |
5085 */ | |
5086 ALint buffers_still_queued; | |
5087 if((error = alGetError()) != AL_NO_ERROR) | |
5088 { | |
5089 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
|
5090 alGetString(error)); |
0 | 5091 } |
5092 | |
5093 alGetSourcei( | |
5094 ALmixer_Channel_List[i].alsource, | |
5095 AL_BUFFERS_QUEUED, &buffers_still_queued | |
5096 ); | |
5097 if((error = alGetError()) != AL_NO_ERROR) | |
5098 { | |
5099 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
|
5100 alGetString(error)); |
0 | 5101 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
|
5102 alGetString(error) ); |
0 | 5103 error_flag--; |
5104 } | |
5105 if(buffers_still_queued > 0) | |
5106 { | |
1 | 5107 |
5108 #if 0 /* This triggers an error in OS X Core Audio. */ | |
5109 alSourceUnqueueBuffers( | |
5110 ALmixer_Channel_List[i].alsource, | |
5111 1, | |
5112 ALmixer_Channel_List[i].almixer_data->buffer | |
5113 ); | |
5114 #else | |
5115 /* fprintf(stderr, "In the Bob Aron section...about to clear source\n"); | |
0 | 5116 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 5117 */ |
0 | 5118 /* Rather than force unqueuing the buffer, let's see if |
5119 * setting the buffer to none works (the OpenAL 1.0 | |
5120 * Reference Annotation suggests this should work). | |
5121 */ | |
5122 alSourcei(ALmixer_Channel_List[i].alsource, | |
5123 AL_BUFFER, AL_NONE); | |
5124 /* | |
5125 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5126 */ | |
1 | 5127 #endif |
0 | 5128 if((error = alGetError()) != AL_NO_ERROR) |
5129 { | |
5130 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
|
5131 alGetString(error)); |
0 | 5132 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
|
5133 alGetString(error) ); |
0 | 5134 error_flag--; |
5135 } | |
5136 | |
5137 } | |
5138 | |
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
|
5139 /* 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
|
5140 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
|
5141 |
0 | 5142 Clean_Channel(i); |
5143 /* Subtract counter */ | |
5144 Is_Playing_global--; | |
5145 | |
5146 | |
5147 /* We're done for this loop. | |
5148 * Go to next channel | |
5149 */ | |
5150 continue; | |
5151 } | |
5152 continue; | |
5153 } | |
5154 } /* End if decoded_all */ | |
5155 /* For streamed */ | |
5156 else | |
5157 { | |
5158 ALint buffers_processed; | |
5159 ALint buffers_still_queued; | |
5160 ALint current_buffer_id; | |
5161 | |
5162 ALuint unqueued_buffer_id; | |
5163 #if 0 | |
5164 /********* Remove this **********/ | |
5165 fprintf(stderr, "For Streamed\n"); | |
5166 | |
5167 alGetSourcei( | |
5168 ALmixer_Channel_List[i].alsource, | |
5169 AL_SOURCE_STATE, &state | |
5170 ); | |
5171 switch(state) { | |
5172 case AL_PLAYING: | |
5173 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
5174 break; | |
5175 case AL_PAUSED: | |
5176 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
5177 break; | |
5178 case AL_STOPPED: | |
5179 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
5180 break; | |
5181 case AL_INITIAL: | |
5182 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
5183 break; | |
5184 default: | |
5185 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
5186 break; | |
5187 } | |
5188 /******** END REMOVE *******/ | |
5189 #endif | |
5190 /* Get the number of buffers still queued */ | |
5191 alGetSourcei( | |
5192 ALmixer_Channel_List[i].alsource, | |
5193 AL_BUFFERS_QUEUED, &buffers_still_queued | |
5194 ); | |
5195 if((error = alGetError()) != AL_NO_ERROR) | |
5196 { | |
5197 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
|
5198 alGetString(error)); |
0 | 5199 } |
5200 /* Get the number of buffers processed | |
5201 * so we know if we need to refill | |
5202 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5203 /* 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
|
5204 * 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
|
5205 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5206 // fprintf(stderr, "calling AL_BUFFERS_PROCESSED on source:%d", ALmixer_Channel_List[i].alsource); |
0 | 5207 alGetSourcei( |
5208 ALmixer_Channel_List[i].alsource, | |
5209 AL_BUFFERS_PROCESSED, &buffers_processed | |
5210 ); | |
5211 if((error = alGetError()) != AL_NO_ERROR) | |
5212 { | |
5213 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
|
5214 alGetString(error)); |
0 | 5215 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5216 // fprintf(stderr, "finished AL_BUFFERS_PROCESSED, buffers_processed=%d", buffers_processed); |
0 | 5217 |
5218 /* WTF!!! The Nvidia distribution is failing on the alGetSourcei(source, AL_BUFFER, buf_id) call. | |
5219 * I need this call to figure out which buffer OpenAL is currently playing. | |
5220 * It keeps returning an "Invalid Enum" error. | |
5221 * This is totally inane! It's a basic query. | |
5222 * By the spec, this functionality is not explicitly defined so Nvidia refuses to | |
5223 * fix this behavior, even though all other distributions work fine with this. | |
5224 * The only workaround for this is for | |
5225 * a significant rewrite of my code which requires me to | |
5226 * duplicate the OpenAL queued buffers state with my own | |
5227 * code and try to derive what the current playing buffer is by indirect observation of | |
5228 * looking at buffers_processed. But of course this has a ton of downsides since my | |
5229 * queries do not give me perfect timing of what OpenAL is actually doing and | |
5230 * the fact that some of the distributions seem to have buffer queuing problems | |
5231 * with their query results (CoreAudio). This also means a ton of extra code | |
5232 * on my side. The lack of support of a 1 line call has required me to | |
5233 * implement yet another entire state machine. <sigh> | |
5234 */ | |
5235 #if 0 /* This code will not work until possibly OpenAL 1.1 because of Nvidia */ | |
5236 /* Get the id to the current buffer playing */ | |
5237 alGetSourcei( | |
5238 ALmixer_Channel_List[i].alsource, | |
5239 AL_BUFFER, ¤t_buffer_id | |
5240 ); | |
5241 if((error = alGetError()) != AL_NO_ERROR) | |
5242 { | |
5243 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
|
5244 alGetString(error)); |
0 | 5245 } |
5246 | |
5247 /* Before the hard stuff, check to see if the | |
5248 * current queued AL buffer has changed. | |
5249 * If it has, we should launch a data callback if | |
5250 * necessary | |
5251 */ | |
5252 if( ((ALuint)current_buffer_id) != | |
5253 ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5254 { | |
5255 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5256 = (ALuint)current_buffer_id; | |
5257 | |
5258 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5259 } | |
5260 #else | |
5261 /* Only do this if "access_data" was requested (i.e. the circular_buffer!=NULL) | |
5262 * And if one of the two are true: | |
5263 * Either buffers_processed > 0 (because the current_buffer might have changed) | |
5264 * or if the current_buffer==0 (because we are in an initial state or recovering from | |
5265 * a buffer underrun) | |
5266 */ | |
5267 if((ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5268 && ( | |
5269 (buffers_processed > 0) || (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5270 ) | |
5271 ) | |
5272 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5273 ALint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5274 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5275 ALubyte is_out_of_sync = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5276 ALuint my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
1 | 5277 /* Ugh, I have to deal with signed/unsigned mismatch here. */ |
5278 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
|
5279 ALuint unplayed_buffers; |
1 | 5280 if(buffers_unplayed_int < 0) |
5281 { | |
5282 unplayed_buffers = 0; | |
5283 } | |
5284 else | |
5285 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5286 unplayed_buffers = (ALuint)buffers_unplayed_int; |
1 | 5287 } |
0 | 5288 /* |
5289 fprintf(stderr, "Queue in processed check, before pop, buffers_processed=%d\n", buffers_processed); | |
5290 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5291 */ | |
5292 /* We can't make any determinations solely based on the number of buffers_processed | |
5293 * because currently, we only unqueue 1 buffer per loop. That means if 2 or more | |
5294 * buffers became processed in one loop, the following loop, we would have | |
5295 * at least that_many-1 buffers_processed (plus possible new processed). | |
5296 * If we tried to just remove 1 buffer from our queue, we would be incorrect | |
5297 * because we would not actually reflect the current playing buffer. | |
5298 * So the solution seems to be to make sure our queue is the same size | |
5299 * as the number of buffers_queued-buffers_processed, and return the head of our queue | |
5300 * as the current playing buffer. | |
5301 */ | |
5302 /* Also, we have a corner case. When we first start playing or if we have | |
5303 * a buffer underrun, we have not done a data callback. | |
5304 * In this case, we need to see if there is any new data in our queue | |
5305 * and if so, launch that data callback. | |
5306 */ | |
5307 /* Warning, this code risks the possibility of no data callback being fired if | |
5308 * the system is really late (or skipped buffers). | |
5309 */ | |
5310 | |
5311 /* First, let's syncronize our queue with the OpenAL queue */ | |
5312 #if 0 | |
5313 fprintf(stderr, "inside, Buffers processed=%d, Buffers queued=%d, my queue=%d\n", | |
5314 buffers_processed, buffers_still_queued, my_queue_size); | |
1 | 5315 #endif |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5316 is_out_of_sync = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5317 for(k=0; k<buffers_processed; k++) |
0 | 5318 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5319 queue_ret_flag = CircularQueueUnsignedInt_PopFront( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5320 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
|
5321 if(0 == queue_ret_flag) |
0 | 5322 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5323 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
|
5324 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5325 } |
0 | 5326 my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
5327 /* We have several possibilities we need to handle: | |
5328 * 1) We are in an initial state or underrun and need to do a data callback on the head. | |
5329 * 2) We were out of sync and need to do a new data callback on the new head. | |
5330 * 3) We were not out of sync but just had left over processed buffers which caused us to | |
5331 * fall in this block of code. (Don't do anything.) | |
5332 */ | |
5333 if( (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) || (1 == is_out_of_sync) ) | |
5334 { | |
5335 if(my_queue_size > 0) | |
5336 { | |
5337 current_buffer_id = CircularQueueUnsignedInt_Front( | |
5338 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5339 if(0 == current_buffer_id) | |
5340 { | |
5341 fprintf(stderr, "53a Internal Error, current_buffer_id=0 when it shouldn't be 0\n"); | |
5342 } | |
5343 /* | |
5344 else | |
5345 { | |
5346 fprintf(stderr, "Queue in processed check, after pop\n"); | |
5347 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5348 } | |
5349 */ | |
5350 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5351 = (ALuint)current_buffer_id; | |
5352 | |
5353 #if 0 | |
5354 /* Remove me...only for checking...doesn't work on Nvidia */ | |
5355 { | |
5356 ALuint real_id; | |
5357 alGetSourcei( | |
5358 ALmixer_Channel_List[i].alsource, | |
5359 AL_BUFFER, &real_id | |
5360 ); | |
5361 alGetError(); | |
5362 fprintf(stderr, "Callback fired on data buffer=%d, real_id shoud be=%d\n", current_buffer_id, real_id); | |
5363 } | |
5364 #endif | |
5365 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5366 } | |
5367 else | |
5368 { | |
1 | 5369 /* |
0 | 5370 fprintf(stderr, "53b, Notice/Warning:, OpenAL queue has been depleted.\n"); |
1 | 5371 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
5372 */ | |
0 | 5373 /* In this case, we might either be in an underrun or finished with playback */ |
5374 ALmixer_Channel_List[i].almixer_data->current_buffer = 0; | |
5375 } | |
5376 } | |
5377 } | |
5378 #endif | |
5379 | |
5380 | |
5381 | |
5382 /* Just a test - remove | |
5383 if( ALmixer_Channel_List[i].loops > 0) | |
5384 { | |
5385 fprintf(stderr, ">>>>>>>>>>>>>>>Loops = %d\n", | |
5386 ALmixer_Channel_List[i].loops); | |
5387 } | |
5388 */ | |
5389 #if 0 | |
5390 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
5391 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5392 #endif | |
5393 /* We've used up a buffer so we need to unqueue and replace */ | |
5394 /* Okay, it gets more complicated here: | |
5395 * We need to Queue more data | |
5396 * if buffers_processed > 0 or | |
5397 * if num_of_buffers_in_use < NUMBER_OF_QUEUE_BUFFERS | |
5398 * but we don't do this if at EOF, | |
5399 * except when there is looping | |
5400 */ | |
5401 /* For this to work, we must rely on EVERYTHING | |
5402 * else to unset the EOF if there is looping. | |
5403 * Remember, even Play() must do this | |
5404 */ | |
5405 | |
5406 /* If not EOF, then we are still playing. | |
5407 * Inside, we might find num_of_buffers < NUM...QUEUE_BUF.. | |
5408 * or buffers_process > 0 | |
5409 * in which case we queue up. | |
5410 * We also might find no buffers we need to fill, | |
5411 * in which case we just keep going | |
5412 */ | |
5413 if( ! ALmixer_Channel_List[i].almixer_data->eof) | |
5414 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5415 ALuint bytes_returned; |
0 | 5416 /* We have a priority. We first must assign |
5417 * unused buffers in reserve. If there is nothing | |
5418 * left, then we may unqueue buffers. We can't | |
5419 * do it the other way around because we will | |
5420 * lose the pointer to the unqueued buffer | |
5421 */ | |
5422 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5423 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5424 { | |
1 | 5425 #if 0 |
0 | 5426 fprintf(stderr, "Getting more data in NOT_EOF and num_buffers_in_use (%d) < max_queue (%d)\n", |
5427 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5428 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5429 #endif |
0 | 5430 /* Going to add an unused packet. |
5431 * Grab next packet */ | |
5432 bytes_returned = GetMoreData( | |
5433 ALmixer_Channel_List[i].almixer_data, | |
5434 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5435 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5436 ); | |
5437 } | |
5438 /* For processed > 0 */ | |
5439 else if(buffers_processed > 0) | |
5440 { | |
5441 /* Unqueue only 1 buffer for now. | |
5442 * If there are more than one, | |
5443 * let the next Update pass deal with it | |
5444 * so we don't stall the program for too long. | |
5445 */ | |
5446 #if 0 | |
5447 fprintf(stderr, "About to Unqueue, Buffers processed = %d\n", buffers_processed); | |
5448 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5449 fprintf(stderr, "Unqueuing a buffer\n"); | |
5450 #endif | |
5451 alSourceUnqueueBuffers( | |
5452 ALmixer_Channel_List[i].alsource, | |
5453 1, &unqueued_buffer_id | |
5454 ); | |
5455 if((error = alGetError()) != AL_NO_ERROR) | |
5456 { | |
5457 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
|
5458 alGetString(error)); |
0 | 5459 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
|
5460 alGetString(error) ); |
0 | 5461 error_flag--; |
5462 } | |
5463 /* | |
5464 fprintf(stderr, "Right after unqueue..."); | |
5465 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5466 fprintf(stderr, "Getting more data for NOT_EOF, max_buffers filled\n"); | |
5467 */ | |
5468 /* Grab unqueued packet */ | |
5469 bytes_returned = GetMoreData( | |
5470 ALmixer_Channel_List[i].almixer_data, | |
5471 unqueued_buffer_id); | |
5472 } | |
5473 /* We are still streaming, but currently | |
5474 * don't need to fill any buffers */ | |
5475 else | |
5476 { | |
5477 /* Might want to check state */ | |
5478 /* In case the playback stopped, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5479 * we need to resume |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5480 * a.k.a. buffer underrun |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5481 */ |
1 | 5482 #if 1 |
5483 /* Try not refetching the state here because I'm getting a duplicate | |
5484 buffer playback (hiccup) */ | |
0 | 5485 alGetSourcei( |
5486 ALmixer_Channel_List[i].alsource, | |
5487 AL_SOURCE_STATE, &state | |
5488 ); | |
1 | 5489 if((error = alGetError()) != AL_NO_ERROR) |
5490 { | |
5491 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
|
5492 alGetString(error)); |
1 | 5493 } |
5494 /* Get the number of buffers processed | |
5495 */ | |
5496 alGetSourcei( | |
5497 ALmixer_Channel_List[i].alsource, | |
5498 AL_BUFFERS_PROCESSED, | |
5499 &buffers_processed | |
5500 ); | |
5501 if((error = alGetError()) != AL_NO_ERROR) | |
5502 { | |
5503 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
|
5504 alGetString(error)); |
1 | 5505 } |
5506 #endif | |
0 | 5507 if(AL_STOPPED == state) |
5508 { | |
5509 /* Resuming in not eof, but nothing to buffer */ | |
1 | 5510 |
5511 /* Okay, here's another lately discovered problem: | |
5512 * I can't find it in the spec, but for at least some of the | |
5513 * implementations, if I call play on a stopped source that | |
5514 * has processed buffers, all those buffers get marked as unprocessed | |
5515 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5516 * processed, on resume, the earlier 24 buffers will get replayed, | |
5517 * causing a "hiccup" like sound in the playback. | |
5518 * To avoid this, I must unqueue all processed buffers before | |
5519 * calling play. But to complicate things, I need to worry about resyncing | |
5520 * the circular queue with this since I designed this thing | |
5521 * with some correlation between the two. However, I might | |
5522 * have already handled this, so I will try writing this code without | |
5523 * syncing for now. | |
5524 * There is currently an assumption that a buffer | |
5525 * was queued above so I actually have something | |
5526 * to play. | |
5527 */ | |
5528 ALint temp_count; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5529 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5530 fprintf(stderr, "STOPPED1, need to clear processed=%d, status is:\n", buffers_processed); |
1 | 5531 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
|
5532 #endif |
1 | 5533 for(temp_count=0; temp_count<buffers_processed; temp_count++) |
5534 { | |
5535 alSourceUnqueueBuffers( | |
5536 ALmixer_Channel_List[i].alsource, | |
5537 1, &unqueued_buffer_id | |
5538 ); | |
5539 if((error = alGetError()) != AL_NO_ERROR) | |
5540 { | |
5541 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
|
5542 alGetString(error)); |
1 | 5543 error_flag--; |
5544 } | |
5545 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5546 #if 0 |
1 | 5547 fprintf(stderr, "After unqueue clear...:\n"); |
5548 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
|
5549 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5550 /* 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
|
5551 * 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
|
5552 * 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
|
5553 * 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
|
5554 * no buffers in queue. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5555 * 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
|
5556 * Then we need to resume playing. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5557 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5558 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5559 int buffers_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5560 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5561 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5562 AL_BUFFERS_QUEUED, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5563 &buffers_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5564 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5565 |
1 | 5566 if((error = alGetError()) != AL_NO_ERROR) |
5567 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5568 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
|
5569 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5570 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5571 assert(buffers_queued == 0); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5572 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
|
5573 #endif |
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 /* 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
|
5576 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
|
5577 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5578 /* 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
|
5579 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5580 ALmixer_Channel_List[i].almixer_data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5581 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
|
5582 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5583 /* 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
|
5584 * 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
|
5585 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5586 if(bytes_returned > 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 /* Queue up the new data */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5589 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5590 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5591 1, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5592 &ALmixer_Channel_List[i].almixer_data->buffer[0] |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5593 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5594 if((error = alGetError()) != AL_NO_ERROR) |
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 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
|
5597 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5598 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5599 /* 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
|
5600 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
|
5601 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5602 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5603 /* 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
|
5604 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
|
5605 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5606 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5607 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
|
5608 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5609 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
|
5610 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
|
5611 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5612 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5613 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5614 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
|
5615 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
|
5616 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5617 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5618 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5619 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5620 |
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 /* Resume playback from underrun */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5623 alSourcePlay(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5624 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5625 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5626 fprintf(stderr, "55Tbesting error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5627 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5628 } |
1 | 5629 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5630 |
0 | 5631 } |
5632 /* Let's escape to the next loop. | |
5633 * All code below this point is for queuing up | |
5634 */ | |
5635 /* | |
1 | 5636 fprintf(stderr, "Entry: Nothing to do...continue\n\n"); |
5637 */ | |
0 | 5638 continue; |
5639 } | |
5640 /* We now know we have to fill an available | |
5641 * buffer. | |
5642 */ | |
5643 | |
5644 /* In the previous branch, we just grabbed more data. | |
5645 * Let's check it to make sure it's okay, | |
5646 * and then queue it up | |
5647 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5648 /* This check doesn't work anymore because it is now ALuint */ |
0 | 5649 #if 0 |
5650 if(-1 == bytes_returned) | |
5651 { | |
5652 /* Problem occurred...not sure what to do */ | |
5653 /* Go to next loop? */ | |
5654 error_flag--; | |
5655 /* Set the eof flag to force a quit so | |
5656 * we don't get stuck in an infinite loop | |
5657 */ | |
5658 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5659 continue; | |
5660 } | |
5661 #endif | |
5662 /* This is a special case where we've run | |
5663 * out of data. We should check for loops | |
5664 * and get more data. If there is no loop, | |
5665 * then do nothing and wait for future | |
5666 * update passes to handle the EOF. | |
5667 * The advantage of handling the loop here | |
5668 * instead of waiting for play to stop is | |
5669 * that we should be able to keep the buffer | |
5670 * filled. | |
5671 */ | |
5672 #if 0 | |
5673 else if(0 == bytes_returned) | |
5674 #endif | |
5675 if(0 == bytes_returned) | |
5676 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5677 /* |
0 | 5678 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
|
5679 */ |
0 | 5680 /* Check for loops */ |
5681 if( ALmixer_Channel_List[i].loops != 0 ) | |
5682 { | |
5683 /* We have to loop, so rewind | |
5684 * and fetch more data | |
5685 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5686 /* |
0 | 5687 fprintf(stderr, "Rewinding data\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5688 */ |
0 | 5689 if(0 == Sound_Rewind( |
5690 ALmixer_Channel_List[i].almixer_data->sample)) | |
5691 { | |
5692 fprintf(stderr, "Rewinding failed\n"); | |
5693 ALmixer_SetError( Sound_GetError() ); | |
5694 ALmixer_Channel_List[i].loops = 0; | |
5695 error_flag--; | |
5696 /* We'll continue on because we do have some valid data */ | |
5697 continue; | |
5698 } | |
5699 /* Remember to reset the data->eof flag */ | |
5700 ALmixer_Channel_List[i].almixer_data->eof = 0; | |
5701 if(ALmixer_Channel_List[i].loops > 0) | |
5702 { | |
5703 ALmixer_Channel_List[i].loops--; | |
5704 } | |
5705 /* Try grabbing another packet now. | |
5706 * Since we may have already unqueued a | |
5707 * buffer, we don't want to lose it. | |
5708 */ | |
5709 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5710 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5711 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5712 /* |
0 | 5713 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
|
5714 */ |
0 | 5715 /* Grab next packet */ |
5716 bytes_returned = GetMoreData( | |
5717 ALmixer_Channel_List[i].almixer_data, | |
5718 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5719 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5720 ); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5721 /* |
0 | 5722 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
|
5723 */ |
0 | 5724 } |
5725 /* Refilling unqueued packet */ | |
5726 else | |
5727 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5728 /* |
0 | 5729 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
|
5730 */ |
0 | 5731 /* Grab next packet */ |
5732 bytes_returned = GetMoreData( | |
5733 ALmixer_Channel_List[i].almixer_data, | |
5734 unqueued_buffer_id); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5735 /* |
0 | 5736 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
|
5737 */ |
0 | 5738 } |
5739 /* Another error check */ | |
5740 /* | |
5741 if(bytes_returned <= 0) | |
5742 */ | |
5743 if(0 == bytes_returned) | |
5744 { | |
5745 fprintf(stderr, "??????????ERROR\n"); | |
5746 ALmixer_SetError("Could not loop because after rewind, no data could be retrieved"); | |
5747 /* Problem occurred...not sure what to do */ | |
5748 /* Go to next loop? */ | |
5749 error_flag--; | |
5750 /* Set the eof flag to force a quit so | |
5751 * we don't get stuck in an infinite loop | |
5752 */ | |
5753 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5754 continue; | |
5755 } | |
5756 /* We made it to the end. We still need | |
5757 * to BufferData, so let this branch | |
5758 * fall into the next piece of | |
5759 * code below which will handle that | |
5760 */ | |
5761 | |
5762 | |
5763 } /* END loop check */ | |
5764 else | |
5765 { | |
5766 /* No more loops to do. | |
5767 * EOF flag should be set. | |
5768 * Just go to next loop and | |
5769 * let things be handled correctly | |
5770 * in future update calls | |
5771 */ | |
1 | 5772 /* |
0 | 5773 fprintf(stderr, "SHOULD BE EOF\n"); |
5774 | |
5775 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
1 | 5776 */ |
0 | 5777 continue; |
5778 } | |
5779 } /* END if bytes_returned == 0 */ | |
5780 /********* Possible trouble point. I might be queueing empty buffers on the mac. | |
5781 * This check doesn't say if the buffer is valid. Only the EOF assumption is a clue at this point | |
5782 */ | |
5783 /* Fall here */ | |
5784 /* Everything is normal. We aren't | |
5785 * at an EOF, but need to simply | |
5786 * queue more data. The data is already checked for good, | |
5787 * so queue it up */ | |
5788 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5789 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5790 { | |
5791 /* Keep count of how many buffers we have | |
5792 * to queue so we can return the value | |
5793 */ | |
5794 retval++; | |
1 | 5795 /* |
0 | 5796 fprintf(stderr, "NOT_EOF???, about to Queue more data for num_buffers (%d) < max_queue (%d)\n", |
5797 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5798 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5799 */ |
0 | 5800 alSourceQueueBuffers( |
5801 ALmixer_Channel_List[i].alsource, | |
5802 1, | |
5803 &ALmixer_Channel_List[i].almixer_data->buffer[ | |
5804 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5805 ); | |
5806 if((error = alGetError()) != AL_NO_ERROR) | |
5807 { | |
5808 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
|
5809 alGetString(error)); |
0 | 5810 } |
5811 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5812 * which buffer to show during callbacks (for things like | |
5813 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5814 * data structure. This code will be called only if | |
5815 * "access_data" was set, indicated by whether the queue is NULL. | |
5816 */ | |
5817 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5818 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5819 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5820 // fprintf(stderr, "56d: CircularQueue_PushBack.\n"); |
0 | 5821 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5822 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5823 ALmixer_Channel_List[i].almixer_data->buffer[ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5824 ); | |
5825 if(0 == queue_ret_flag) | |
5826 { | |
5827 fprintf(stderr, "56aSerious internal error: CircularQueue could not push into queue.\n"); | |
5828 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5829 } | |
5830 /* | |
5831 else | |
5832 { | |
5833 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5834 } | |
5835 */ | |
5836 } | |
5837 } | |
5838 /* for processed > 0 */ | |
5839 else | |
5840 { | |
5841 /* Keep count of how many buffers we have | |
5842 * to queue so we can return the value | |
5843 */ | |
5844 retval++; | |
5845 /* | |
5846 fprintf(stderr, "NOT_EOF, about to Queue more data for filled max_queue (%d)\n", | |
5847 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
5848 */ | |
5849 alSourceQueueBuffers( | |
5850 ALmixer_Channel_List[i].alsource, | |
5851 1, &unqueued_buffer_id); | |
5852 if((error = alGetError()) != AL_NO_ERROR) | |
5853 { | |
5854 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
|
5855 alGetString(error) ); |
0 | 5856 error_flag--; |
5857 continue; | |
5858 } | |
5859 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5860 * which buffer to show during callbacks (for things like | |
5861 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5862 * data structure. This code will be called only if | |
5863 * "access_data" was set, indicated by whether the queue is NULL. | |
5864 */ | |
5865 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5866 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5867 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5868 // fprintf(stderr, "56e: CircularQueue_PushBack.\n"); |
0 | 5869 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5870 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5871 unqueued_buffer_id | |
5872 ); | |
5873 if(0 == queue_ret_flag) | |
5874 { | |
5875 fprintf(stderr, "56bSerious internal error: CircularQueue could not push into queue.\n"); | |
5876 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5877 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5878 #if 0 |
0 | 5879 else |
5880 { | |
5881 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5882 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5883 #endif |
0 | 5884 } |
5885 } | |
5886 /* If we used an available buffer queue, | |
5887 * then we need to update the number of them in use | |
5888 */ | |
5889 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5890 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5891 { | |
5892 /* Increment the number of buffers in use */ | |
5893 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use++; | |
5894 } | |
5895 /* Might want to check state */ | |
5896 /* In case the playback stopped, | |
5897 * we need to resume */ | |
1 | 5898 #if 1 |
5899 /* Try not refetching the state here because I'm getting a duplicate | |
5900 buffer playback (hiccup) */ | |
0 | 5901 alGetSourcei( |
5902 ALmixer_Channel_List[i].alsource, | |
5903 AL_SOURCE_STATE, &state | |
5904 ); | |
1 | 5905 if((error = alGetError()) != AL_NO_ERROR) |
5906 { | |
5907 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
|
5908 alGetString(error)); |
1 | 5909 } |
5910 /* Get the number of buffers processed | |
5911 */ | |
5912 alGetSourcei( | |
5913 ALmixer_Channel_List[i].alsource, | |
5914 AL_BUFFERS_PROCESSED, | |
5915 &buffers_processed | |
5916 ); | |
5917 if((error = alGetError()) != AL_NO_ERROR) | |
5918 { | |
5919 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
|
5920 alGetString(error)); |
1 | 5921 } |
5922 #endif | |
0 | 5923 if(AL_STOPPED == state) |
5924 { | |
1 | 5925 /* |
0 | 5926 fprintf(stderr, "Resuming in not eof\n"); |
1 | 5927 */ |
5928 /* Okay, here's another lately discovered problem: | |
5929 * I can't find it in the spec, but for at least some of the | |
5930 * implementations, if I call play on a stopped source that | |
5931 * has processed buffers, all those buffers get marked as unprocessed | |
5932 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5933 * processed, on resume, the earlier 24 buffers will get replayed, | |
5934 * causing a "hiccup" like sound in the playback. | |
5935 * To avoid this, I must unqueue all processed buffers before | |
5936 * calling play. But to complicate things, I need to worry about resyncing | |
5937 * the circular queue with this since I designed this thing | |
5938 * with some correlation between the two. However, I might | |
5939 * have already handled this, so I will try writing this code without | |
5940 * syncing for now. | |
5941 * There is currently an assumption that a buffer | |
5942 * was queued above so I actually have something | |
5943 * to play. | |
5944 */ | |
5945 ALint temp_count; | |
5946 /* | |
5947 fprintf(stderr, "STOPPED2, need to clear processed, status is:\n"); | |
5948 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5949 */ | |
5950 | |
5951 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5952 { | |
5953 alSourceUnqueueBuffers( | |
5954 ALmixer_Channel_List[i].alsource, | |
5955 1, &unqueued_buffer_id | |
5956 ); | |
5957 if((error = alGetError()) != AL_NO_ERROR) | |
5958 { | |
5959 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
|
5960 alGetString(error)); |
1 | 5961 error_flag--; |
5962 } | |
5963 } | |
5964 /* | |
5965 fprintf(stderr, "After unqueue clear...:\n"); | |
5966 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5967 */ | |
5968 | |
5969 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5970 if((error = alGetError()) != AL_NO_ERROR) | |
5971 { | |
5972 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
|
5973 alGetString(error)); |
1 | 5974 } |
0 | 5975 } |
5976 continue; | |
5977 } /* END if( ! eof) */ | |
5978 /* We have hit EOF in the SDL_Sound sample and there | |
5979 * are no more loops. However, there may still be | |
5980 * buffers in the OpenAL queue which still need to | |
5981 * be played out. The following body of code will | |
5982 * determine if play is still happening or | |
5983 * initiate the stop/cleanup sequenece. | |
5984 */ | |
5985 else | |
5986 { | |
5987 /* Let's continue to remove the used up | |
5988 * buffers as they come in. */ | |
5989 if(buffers_processed > 0) | |
5990 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5991 ALint temp_count; |
0 | 5992 /* Do as a for-loop because I don't want |
5993 * to have to create an array for the | |
5994 * unqueued_buffer_id's | |
5995 */ | |
5996 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5997 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5998 /* |
0 | 5999 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
|
6000 */ |
0 | 6001 alSourceUnqueueBuffers( |
6002 ALmixer_Channel_List[i].alsource, | |
6003 1, &unqueued_buffer_id | |
6004 ); | |
6005 if((error = alGetError()) != AL_NO_ERROR) | |
6006 { | |
6007 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
|
6008 alGetString(error)); |
0 | 6009 } |
6010 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6011 /* |
0 | 6012 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
|
6013 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6014 |
0 | 6015 /* Need to update counts since we removed everything. |
6016 * If we don't update the counts here, we end up in the | |
6017 * "Shouldn't be here section, but maybe it's okay due to race conditions" | |
6018 */ | |
6019 alGetSourcei( | |
6020 ALmixer_Channel_List[i].alsource, | |
6021 AL_BUFFERS_QUEUED, &buffers_still_queued | |
6022 ); | |
6023 if((error = alGetError()) != AL_NO_ERROR) | |
6024 { | |
6025 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
|
6026 alGetString(error)); |
0 | 6027 } |
6028 /* Get the number of buffers processed | |
6029 * so we know if we need to refill | |
6030 */ | |
6031 alGetSourcei( | |
6032 ALmixer_Channel_List[i].alsource, | |
6033 AL_BUFFERS_PROCESSED, &buffers_processed | |
6034 ); | |
6035 if((error = alGetError()) != AL_NO_ERROR) | |
6036 { | |
6037 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
|
6038 alGetString(error)); |
0 | 6039 } |
6040 } | |
6041 | |
6042 | |
6043 /* Else if buffers_processed == 0 | |
6044 * and buffers_still_queued == 0. | |
6045 * then we check to see if the source | |
6046 * is still playing. Quit if stopped | |
6047 * We shouldn't need to worry about | |
6048 * looping because that should have | |
6049 * been handled above. | |
6050 */ | |
6051 if(0 == buffers_still_queued) | |
6052 { | |
6053 /* Make sure playback has stopped before | |
6054 * we shutdown. | |
6055 */ | |
6056 alGetSourcei( | |
6057 ALmixer_Channel_List[i].alsource, | |
6058 AL_SOURCE_STATE, &state | |
6059 ); | |
6060 if((error = alGetError()) != AL_NO_ERROR) | |
6061 { | |
6062 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
|
6063 alGetString(error)); |
0 | 6064 } |
6065 if(AL_STOPPED == state) | |
6066 { | |
6067 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use = 0; | |
6068 /* Playback has ended. | |
6069 * Loop if necessary, or launch callback | |
6070 * and clear channel (or clear channel and | |
6071 * 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
|
6072 * Update: Need to do callback first because I reference the mixer_data and source |
0 | 6073 */ |
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
|
6074 |
c808684660a7
Bug fix: Moved Invoke_Callback before CleanChannel because I was trying to get the ALmixer_Data pointer, but it was cleared:
Eric Wing <ewing . public |-at-| gmail . com>
parents:
6
diff
changeset
|
6075 /* 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
|
6076 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
|
6077 |
0 | 6078 Clean_Channel(i); |
6079 /* Subtract counter */ | |
6080 Is_Playing_global--; | |
6081 | |
6082 | |
6083 /* We're done for this loop. | |
6084 * Go to next channel | |
6085 */ | |
6086 continue; | |
6087 } | |
6088 } /* End end-playback */ | |
6089 else | |
6090 { | |
6091 /* Need to run out buffer */ | |
6092 #if 1 | |
6093 /* Might want to check state */ | |
6094 /* In case the playback stopped, | |
6095 * we need to resume */ | |
6096 alGetSourcei( | |
6097 ALmixer_Channel_List[i].alsource, | |
6098 AL_SOURCE_STATE, &state | |
6099 ); | |
6100 if((error = alGetError()) != AL_NO_ERROR) | |
6101 { | |
6102 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
|
6103 alGetString(error)); |
0 | 6104 } |
6105 if(AL_STOPPED == state) | |
6106 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6107 /* |
0 | 6108 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
|
6109 */ |
1 | 6110 /* |
0 | 6111 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 6112 */ |
0 | 6113 /* Rather than force unqueuing the buffer, let's see if |
6114 * setting the buffer to none works (the OpenAL 1.0 | |
6115 * Reference Annotation suggests this should work). | |
6116 */ | |
6117 alSourcei(ALmixer_Channel_List[i].alsource, | |
6118 AL_BUFFER, AL_NONE); | |
6119 /* | |
6120 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
6121 */ | |
6122 /* This doesn't work because in some cases, I think | |
6123 * it causes the sound to be replayed | |
6124 */ | |
6125 /* | |
6126 fprintf(stderr, "Resuming in eof (trying to run out buffers\n"); | |
6127 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
6128 */ | |
6129 } | |
6130 #endif | |
6131 } /* End trap section */ | |
6132 } /* End POST-EOF use-up buffer section */ | |
6133 } /* END Streamed section */ | |
6134 } /* END channel in use */ | |
6135 } /* END for-loop for each channel */ | |
6136 | |
6137 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6138 alcProcessContext(alcGetCurrentContext()); | |
6139 if((error = alGetError()) != AL_NO_ERROR) | |
6140 { | |
6141 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
|
6142 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6143 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6144 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6145 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6146 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6147 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6148 #endif |
0 | 6149 /* Return the number of errors */ |
6150 if(error_flag < 0) | |
6151 { | |
6152 return error_flag; | |
6153 } | |
6154 /* Return the number of buffers that were queued */ | |
6155 return retval; | |
6156 } | |
6157 | |
6158 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6159 /* 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
|
6160 static void my_dummy_audio_callback(void* userdata, ALbyte* stream, int len) |
0 | 6161 { |
6162 } | |
6163 #endif | |
6164 | |
6165 | |
6166 | |
6167 | |
6168 #ifdef ENABLE_ALMIXER_THREADS | |
6169 /* We might need threads. We | |
6170 * must constantly poll OpenAL to find out | |
6171 * if sound is being streamed, if play has | |
6172 * ended, etc. Without threads, this must | |
6173 * be explicitly done by the user. | |
6174 * We could try to do it for them if we | |
6175 * finish the threads. | |
6176 */ | |
6177 | |
6178 static int Stream_Data_Thread_Callback(void* data) | |
6179 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6180 ALint retval; |
0 | 6181 |
6182 while(ALmixer_Initialized) | |
6183 { | |
6184 retval = Update_ALmixer(data); | |
6185 /* 0 means that nothing needed updating and | |
6186 * the function returned quickly | |
6187 */ | |
6188 if(0 == retval) | |
6189 { | |
6190 /* Let's be nice and make the thread sleep since | |
6191 * little work was done in update | |
6192 */ | |
6193 /* Make sure times are multiples of 10 | |
6194 * for optimal performance and accuracy in Linux | |
6195 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6196 ALmixer_Delay(10); |
0 | 6197 } |
6198 else | |
6199 { | |
6200 /* 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
|
6201 ALmixer_Delay(0); |
0 | 6202 } |
6203 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6204 /* |
0 | 6205 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
|
6206 */ |
0 | 6207 return 0; |
6208 } | |
6209 #endif /* End of ENABLE_ALMIXER_THREADS */ | |
6210 | |
6211 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6212 /* 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
|
6213 * 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
|
6214 * so SDL_mixer porting people beware. |
0 | 6215 * Warning: SDL_QuitSubSystem(SDL_INIT_AUDIO) is called which |
6216 * means the SDL audio system will be disabled. It will not | |
6217 * be restored (in case SDL is not actually being used) so | |
6218 * the user will need to restart it if they need it after | |
6219 * OpenAL shuts down. | |
6220 */ | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6221 ALboolean ALmixer_Init(ALuint frequency, ALuint num_sources, ALuint refresh) |
0 | 6222 { |
6223 ALCdevice* dev; | |
6224 ALCcontext* context; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6225 ALint i; |
0 | 6226 ALenum error; |
6227 ALuint* source; | |
6228 | |
6229 #ifdef USING_LOKI_AL_DIST | |
6230 /* The Loki dist requires that I set both the | |
6231 * device and context frequency values separately | |
6232 */ | |
6233 /* Hope this won't overflow */ | |
6234 char device_string[256]; | |
6235 #endif | |
6236 | |
6237 /* (Venting frustration) Damn it! Nobody bothered | |
6238 * documenting how you're supposed to use an attribute | |
6239 * list. In fact, the not even the Loki test program | |
6240 * writers seem to know because they use it inconsistently. | |
6241 * For example, how do you terminate that attribute list? | |
6242 * The Loki test code does it 3 different ways. They | |
6243 * set the last value to 0, or they set it to ALC_INVALID, | |
6244 * or they set two final values: ALC_INVALID, 0 | |
6245 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6246 * but with Creative Labs ALC_INVALID is -1. | |
6247 * So something's going to break. Loki's source | |
6248 * code says to terminate with ALC_INVALID. But I | |
6249 * don't know if that's really true, or it happens | |
6250 * to be a coinicidence because it's defined to 0. | |
6251 * Creative provides no source code, so I can't look at how | |
6252 * they terminate it. | |
6253 * So this is really, really ticking me off... | |
6254 * For now, I'm going to use ALC_INVALID. | |
6255 * (Update...after further review of the API spec, | |
6256 * it seems that a NULL terminated string is the correct | |
6257 * termination value to use, so 0 it is.) | |
6258 */ | |
6259 #if 0 | |
6260 ALint attrlist[] = { | |
6261 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6262 /* Don't know anything about these values. | |
6263 * Trust defaults? */ | |
6264 /* Supposed to be the refresh rate in Hz. | |
6265 * I think 15-120 are supposed to be good | |
6266 * values. Though I haven't gotten any effect except | |
6267 * for one strange instance on a Mac. But it was | |
6268 * unrepeatable. | |
6269 */ | |
6270 #if 0 | |
6271 ALC_REFRESH, 15, | |
6272 #endif | |
6273 /* Sync requires a alcProcessContext() call | |
6274 * for every cycle. By default, this is | |
6275 * not used and the value is AL_FALSE | |
6276 * because it will probably perform | |
6277 * pretty badly for me. | |
6278 */ | |
6279 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6280 ALC_SYNC, AL_TRUE, | |
6281 #else | |
6282 ALC_SYNC, AL_FALSE, | |
6283 #endif | |
6284 /* Looking at the API spec, it implies | |
6285 * that the list be a NULL terminated string | |
6286 * so it's probably not safe to use ALC_INVALID | |
6287 */ | |
6288 /* | |
6289 ALC_INVALID }; | |
6290 */ | |
6291 '\0'}; | |
6292 #endif | |
6293 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6294 * However, if no value is specified, I don't | |
6295 * want it in the list so I can get the OpenAL defaults | |
6296 */ | |
6297 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6298 ALsizei current_attrlist_index = 0; |
0 | 6299 |
6300 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6301 /* More problems: I'm getting bit by endian/signedness issues on | |
6302 * different platforms. I can find the endianess easily enough, | |
6303 * but I don't know how to determine what the correct signedness | |
6304 * is (if such a thing exists). I do know that if I try using | |
6305 * unsigned on OSX with an originally signed sample, I get | |
6306 * distortion. However, I don't have any native unsigned samples | |
6307 * to test. But I'm assuming that the platform must be in the | |
6308 * correct signedness no matter what. | |
6309 * I can either assume everybody is signed, or I can try to | |
6310 * determine the value. If I try to determine the values, | |
6311 * I think my only ability to figure it out will be to open | |
6312 * SDL_Audio, and read what the obtained settings were. | |
6313 * Then shutdown everything. However, I don't even know how | |
6314 * reliable this is. | |
6315 * Update: I think I resolved the issues...forgot to update | |
6316 * these comments when it happened. I should check the revision control | |
6317 * log... Anyway, I think the issue was partly related to me not | |
6318 * doing something correctly with the AudioInfo or some kind | |
6319 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6320 * revision control, I think I might have assumed that SDL_Sound would | |
6321 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6322 * and had to fill one out myself. | |
6323 */ | |
6324 SDL_AudioSpec desired; | |
6325 SDL_AudioSpec obtained; | |
6326 #endif | |
6327 | |
6328 | |
6329 /* Make sure ALmixer isn't already initialized */ | |
6330 if(ALmixer_Initialized) | |
6331 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6332 return AL_FALSE; |
0 | 6333 } |
6334 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6335 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6336 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6337 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6338 /* 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
|
6339 /* 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
|
6340 * 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
|
6341 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6342 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6343 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6344 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6345 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6346 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6347 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6348 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6349 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6350 } |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6351 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6352 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6353 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6354 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
|
6355 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
|
6356 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6357 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6358 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6359 |
0 | 6360 /* Set the defaults */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6361 /* |
0 | 6362 attrlist[0] = ALC_FREQUENCY; |
6363 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6364 attrlist[2] = ALC_SYNC; | |
6365 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6366 attrlist[3] = ALC_TRUE; | |
6367 #else | |
6368 attrlist[3] = ALC_FALSE; | |
6369 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6370 */ |
0 | 6371 /* Set frequency value if it is not 0 */ |
6372 if(0 != frequency) | |
6373 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6374 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6375 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6376 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6377 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6378 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6379 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6380 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6381 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6382 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6383 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6384 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6385 #endif |
0 | 6386 |
6387 /* If the user specifies a refresh value, | |
6388 * make room for it | |
6389 */ | |
6390 if(0 != refresh) | |
6391 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6392 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
|
6393 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6394 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6395 current_attrlist_index++; |
0 | 6396 } |
6397 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6398 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6399 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6400 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6401 |
0 | 6402 /* Initialize SDL_Sound */ |
6403 if(! Sound_Init() ) | |
6404 { | |
6405 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6406 return AL_FALSE; |
0 | 6407 } |
6408 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6409 /* Here is the paranoid check that opens | |
6410 * SDL audio in an attempt to find the correct | |
6411 * system values. | |
6412 */ | |
6413 /* Doesn't have to be the actual value I think | |
6414 * (as long as it doesn't influence format, in | |
6415 * which case I'm probably screwed anyway because OpenAL | |
6416 * may easily choose to do something else). | |
6417 */ | |
6418 desired.freq = 44100; | |
6419 desired.channels = 2; | |
6420 desired.format = AUDIO_S16SYS; | |
6421 desired.callback = my_dummy_audio_callback; | |
6422 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6423 { | |
6424 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6425 /* Now to get really paranoid, we should probably | |
6426 * also assume that the 8bit format is also the | |
6427 * same sign type and set that value | |
6428 */ | |
6429 if(AUDIO_S16SYS == obtained.format) | |
6430 { | |
6431 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6432 } | |
6433 /* Should be AUDIO_U16SYS */ | |
6434 else | |
6435 { | |
6436 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6437 } | |
6438 SDL_CloseAudio(); | |
6439 } | |
6440 else | |
6441 { | |
6442 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6443 */ | |
6444 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6445 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6446 } | |
6447 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6448 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6449 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6450 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
6451 * causes OpenAL and SMPEG to conflict. For some reason | |
6452 * if SDL_Init on audio is active, then all the SMPEG | |
6453 * decoded sound comes out silent. Unfortunately, | |
6454 * Sound_Init() invokes SDL_Init on audio. I'm | |
6455 * not sure why it actually needs it... | |
6456 * But we'll attempt to disable it here after the | |
6457 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
6458 */ | |
6459 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6460 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6461 |
0 | 6462 /* I'm told NULL will call the default string |
6463 * and hopefully do the right thing for each platform | |
6464 */ | |
6465 /* | |
6466 dev = alcOpenDevice( NULL ); | |
6467 */ | |
6468 /* Now I'm told I need to set both the device and context | |
6469 * to have the same sampling rate, so I must pass a string | |
6470 * to OpenDevice(). I don't know how portable these strings are. | |
6471 * I don't even know if the format for strings is | |
6472 * compatible | |
6473 * From the testattrib.c in the Loki test section | |
6474 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
6475 */ | |
6476 | |
6477 #ifdef USING_LOKI_AL_DIST | |
6478 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
6479 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
6480 #else | |
6481 dev = alcOpenDevice( NULL ); | |
6482 #endif | |
6483 if(NULL == dev) | |
6484 { | |
6485 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
|
6486 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6487 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6488 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6489 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6490 /* 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
|
6491 /* 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
|
6492 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6493 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6494 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6495 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6496 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
|
6497 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6498 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
|
6499 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6500 #endif |
0 | 6501 |
6502 context = alcCreateContext(dev, attrlist); | |
6503 if(NULL == context) | |
6504 { | |
6505 ALmixer_SetError("Cannot create a context OpenAL"); | |
6506 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6507 return AL_FALSE; |
0 | 6508 } |
6509 | |
6510 | |
6511 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6512 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6513 * According to Garin Hiebert, this is actually an inconsistency | |
6514 * in the Loki version. The function should return a boolean. | |
6515 * instead of ALC_NO_ERROR. Garin suggested I check via | |
6516 * alcGetError(). | |
6517 */ | |
6518 /* clear the error */ | |
6519 alcGetError(dev); | |
6520 alcMakeContextCurrent(context); | |
6521 | |
6522 error = alcGetError(dev); | |
6523 if( (ALC_NO_ERROR != error) ) | |
6524 { | |
6525 ALmixer_SetError("Could not MakeContextCurrent"); | |
6526 alcDestroyContext(context); | |
6527 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6528 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6529 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6530 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6531 /* 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
|
6532 * 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
|
6533 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6534 * 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
|
6535 * 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
|
6536 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6537 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6538 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6539 ALmixer_Frequency_global = frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6540 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6541 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6542 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
|
6543 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6544 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
|
6545 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6546 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6547 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6548 |
0 | 6549 #if 0 |
6550 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
6551 if(alcGetCurrentContext() != context) | |
6552 { | |
6553 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6554 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6555 * I think this is a bug in the OpenAL implementation. | |
6556 */ | |
6557 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
6558 | |
6559 fprintf(stderr, "Making context current\n"); | |
6560 #ifndef __APPLE__ | |
6561 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
6562 #else | |
6563 if(!alcMakeContextCurrent(context)) | |
6564 #endif | |
6565 { | |
6566 ALmixer_SetError("Could not MakeContextCurrent"); | |
6567 alcDestroyContext(context); | |
6568 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6569 return AL_FALSE; |
0 | 6570 } |
6571 } | |
6572 #endif | |
6573 | |
6574 | |
6575 /* #endif */ | |
6576 /* Saw this in the README with the OS X OpenAL distribution. | |
6577 * It looked interesting and simple, so I thought I might | |
6578 * try it out. | |
6579 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
6580 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
6581 * Audio format, the audio data passed to the | |
6582 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
6583 * usage by removing an audio data conversion | |
6584 * (per source) at render timem at the expense of a larger memory footprint. | |
6585 * | |
6586 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
6587 * setting will be applied to all subsequent | |
6588 * calls to alBufferData(). | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6589 * |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6590 * 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
|
6591 * Rather than deal with it right now, I think I am going to make it an opt-in thing. |
0 | 6592 */ |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6593 #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
|
6594 /* |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6595 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
|
6596 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6597 #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
|
6598 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6599 #else |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6600 /* 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
|
6601 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
|
6602 /* |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6603 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
|
6604 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6605 if(0 != convert_data_enum) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6606 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6607 alEnable(convert_data_enum); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6608 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6609 if( (AL_NO_ERROR != alGetError()) ) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6610 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6611 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
|
6612 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
|
6613 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6614 #endif |
22
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 #endif /* __APPLE__ */ |
0 | 6617 |
6618 | |
6619 | |
6620 | |
6621 ALmixer_Initialized = 1; | |
6622 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6623 if(num_sources == 0) |
0 | 6624 { |
6625 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
6626 } | |
6627 else | |
6628 { | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6629 /* 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
|
6630 Number_of_Channels_global = (ALint)num_sources; |
0 | 6631 } |
6632 Number_of_Reserve_Channels_global = 0; | |
6633 Is_Playing_global = 0; | |
6634 /* Set to Null in case system quit and was reinitialized */ | |
6635 Channel_Done_Callback = NULL; | |
6636 Channel_Done_Callback_Userdata = NULL; | |
6637 Channel_Data_Callback = NULL; | |
1 | 6638 Channel_Data_Callback_Userdata = NULL; |
0 | 6639 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6640 /* Allocate memory for linked list of ALmixerData. */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6641 s_listOfALmixerData = LinkedList_Create(); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6642 if(NULL == s_listOfALmixerData) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6643 { |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6644 ALmixer_SetError("Couldn't create linked list"); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6645 alcDestroyContext(context); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6646 alcCloseDevice(dev); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6647 ALmixer_Initialized = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6648 Number_of_Channels_global = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6649 return AL_FALSE; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6650 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6651 |
0 | 6652 /* Allocate memory for the list of channels */ |
6653 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
6654 if(NULL == ALmixer_Channel_List) | |
6655 { | |
6656 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
|
6657 LinkedList_Free(s_listOfALmixerData); |
0 | 6658 alcDestroyContext(context); |
6659 alcCloseDevice(dev); | |
6660 ALmixer_Initialized = 0; | |
6661 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6662 return AL_FALSE; |
0 | 6663 } |
6664 | |
6665 /* Allocate memory for the list of sources that map to the channels */ | |
6666 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
6667 if(NULL == Source_Map_List) | |
6668 { | |
6669 ALmixer_SetError("Out of Memory for Source Map List"); | |
6670 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6671 LinkedList_Free(s_listOfALmixerData); |
0 | 6672 alcDestroyContext(context); |
6673 alcCloseDevice(dev); | |
6674 ALmixer_Initialized = 0; | |
6675 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6676 return AL_FALSE; |
0 | 6677 } |
6678 | |
6679 /* Create array that will hold the sources */ | |
6680 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
6681 if(NULL == source) | |
6682 { | |
6683 ALmixer_SetError("Out of Memory for sources"); | |
6684 free(Source_Map_List); | |
6685 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6686 LinkedList_Free(s_listOfALmixerData); |
0 | 6687 alcDestroyContext(context); |
6688 alcCloseDevice(dev); | |
6689 ALmixer_Initialized = 0; | |
6690 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6691 return AL_FALSE; |
0 | 6692 } |
6693 | |
6694 /* Clear the error state */ | |
6695 alGetError(); | |
6696 /* Generate the OpenAL sources */ | |
6697 alGenSources(Number_of_Channels_global, source); | |
6698 if( (error=alGetError()) != AL_NO_ERROR) | |
6699 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6700 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 6701 free(ALmixer_Channel_List); |
6702 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6703 LinkedList_Free(s_listOfALmixerData); |
0 | 6704 alcDestroyContext(context); |
6705 alcCloseDevice(dev); | |
6706 ALmixer_Initialized = 0; | |
6707 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6708 return AL_FALSE; |
0 | 6709 } |
6710 | |
6711 /* Initialize each channel and associate one source to one channel */ | |
6712 for(i=0; i<Number_of_Channels_global; i++) | |
6713 { | |
6714 if(0 == source[i]) | |
6715 { | |
6716 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"); | |
6717 } | |
6718 | |
6719 Init_Channel(i); | |
6720 /* Keeping the source allocation out of the Init function | |
6721 * in case I want to reuse the Init | |
6722 * function for resetting data | |
6723 */ | |
6724 ALmixer_Channel_List[i].alsource = source[i]; | |
6725 /* Now also keep a copy of the source to channel mapping | |
6726 * in case we need to look up a channel from the source | |
6727 * instead of a source from a channel | |
6728 */ | |
6729 Source_Map_List[i].source = source[i]; | |
6730 Source_Map_List[i].channel = i; | |
6731 /* Clean the channel because there are some things that need to | |
6732 * be done that can't happen until the source is set | |
6733 */ | |
6734 Clean_Channel(i); | |
6735 } | |
6736 | |
6737 /* The Source_Map_List must be sorted by source for binary searches | |
6738 */ | |
6739 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
6740 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6741 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6742 ALmixer_OutputDecoders(); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6743 */ |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6744 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6745 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6746 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6747 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6748 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6749 if(NULL == s_simpleLock) |
0 | 6750 { |
6751 /* SDL sets the error message already? */ | |
6752 free(source); | |
6753 free(ALmixer_Channel_List); | |
6754 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6755 LinkedList_Free(s_listOfALmixerData); |
0 | 6756 alcDestroyContext(context); |
6757 alcCloseDevice(dev); | |
6758 ALmixer_Initialized = 0; | |
6759 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6760 return AL_FALSE; |
0 | 6761 } |
6762 | |
6763 | |
6764 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
6765 if(NULL == Stream_Thread_global) | |
6766 { | |
6767 /* 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
|
6768 SDL_DestroyMutex(s_simpleLock); |
0 | 6769 free(source); |
6770 free(ALmixer_Channel_List); | |
6771 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6772 LinkedList_Free(s_listOfALmixerData); |
0 | 6773 alcDestroyContext(context); |
6774 alcCloseDevice(dev); | |
6775 ALmixer_Initialized = 0; | |
6776 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6777 return AL_FALSE; |
0 | 6778 } |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
6779 |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
6780 /* 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
|
6781 Internal_LowerThreadPriority(Stream_Thread_global); |
0 | 6782 |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6783 /* |
0 | 6784 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6785 */ |
0 | 6786 #endif /* End of ENABLE_ALMIXER_THREADS */ |
6787 | |
6788 /* We don't need this array any more because all the sources | |
6789 * are connected to channels | |
6790 */ | |
6791 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6792 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6793 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6794 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6795 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6796 ALboolean ALmixer_InitContext(ALuint frequency, ALuint refresh) |
0 | 6797 { |
6798 ALCdevice* dev; | |
6799 ALCcontext* context; | |
6800 ALCenum error; | |
6801 | |
6802 #ifdef USING_LOKI_AL_DIST | |
6803 /* The Loki dist requires that I set both the | |
6804 * device and context frequency values separately | |
6805 */ | |
6806 /* Hope this won't overflow */ | |
6807 char device_string[256]; | |
6808 #endif | |
6809 | |
6810 /* (Venting frustration) Damn it! Nobody bothered | |
6811 * documenting how you're supposed to use an attribute | |
6812 * list. In fact, the not even the Loki test program | |
6813 * writers seem to know because they use it inconsistently. | |
6814 * For example, how do you terminate that attribute list? | |
6815 * The Loki test code does it 3 different ways. They | |
6816 * set the last value to 0, or they set it to ALC_INVALID, | |
6817 * or they set two final values: ALC_INVALID, 0 | |
6818 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6819 * but with Creative Labs ALC_INVALID is -1. | |
6820 * So something's going to break. Loki's source | |
6821 * code says to terminate with ALC_INVALID. But I | |
6822 * don't know if that's really true, or it happens | |
6823 * to be a coinicidence because it's defined to 0. | |
6824 * Creative provides no source code, so I can't look at how | |
6825 * they terminate it. | |
6826 * So this is really, really ticking me off... | |
6827 * For now, I'm going to use ALC_INVALID. | |
6828 * (Update...after further review of the API spec, | |
6829 * it seems that a NULL terminated string is the correct | |
6830 * termination value to use, so 0 it is.) | |
6831 */ | |
6832 #if 0 | |
6833 ALint attrlist[] = { | |
6834 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6835 /* Don't know anything about these values. | |
6836 * Trust defaults? */ | |
6837 /* Supposed to be the refresh rate in Hz. | |
6838 * I think 15-120 are supposed to be good | |
6839 * values. Though I haven't gotten any effect except | |
6840 * for one strange instance on a Mac. But it was | |
6841 * unrepeatable. | |
6842 */ | |
6843 #if 0 | |
6844 ALC_REFRESH, 15, | |
6845 #endif | |
6846 /* Sync requires a alcProcessContext() call | |
6847 * for every cycle. By default, this is | |
6848 * not used and the value is AL_FALSE | |
6849 * because it will probably perform | |
6850 * pretty badly for me. | |
6851 */ | |
6852 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6853 ALC_SYNC, AL_TRUE, | |
6854 #else | |
6855 ALC_SYNC, AL_FALSE, | |
6856 #endif | |
6857 /* Looking at the API spec, it implies | |
6858 * that the list be a NULL terminated string | |
6859 * so it's probably not safe to use ALC_INVALID | |
6860 */ | |
6861 /* | |
6862 ALC_INVALID }; | |
6863 */ | |
6864 '\0'}; | |
6865 #endif | |
6866 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6867 * However, if no value is specified, I don't | |
6868 * want it in the list so I can get the OpenAL defaults | |
6869 */ | |
6870 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6871 ALsizei current_attrlist_index = 0; |
0 | 6872 |
6873 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6874 /* More problems: I'm getting bit by endian/signedness issues on | |
6875 * different platforms. I can find the endianess easily enough, | |
6876 * but I don't know how to determine what the correct signedness | |
6877 * is (if such a thing exists). I do know that if I try using | |
6878 * unsigned on OSX with an originally signed sample, I get | |
6879 * distortion. However, I don't have any native unsigned samples | |
6880 * to test. But I'm assuming that the platform must be in the | |
6881 * correct signedness no matter what. | |
6882 * I can either assume everybody is signed, or I can try to | |
6883 * determine the value. If I try to determine the values, | |
6884 * I think my only ability to figure it out will be to open | |
6885 * SDL_Audio, and read what the obtained settings were. | |
6886 * Then shutdown everything. However, I don't even know how | |
6887 * reliable this is. | |
6888 * Update: I think I resolved the issues...forgot to update | |
6889 * these comments when it happened. I should check the revision control | |
6890 * log... Anyway, I think the issue was partly related to me not | |
6891 * doing something correctly with the AudioInfo or some kind | |
6892 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6893 * revision control, I think I might have assumed that SDL_Sound would | |
6894 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6895 * and had to fill one out myself. | |
6896 */ | |
6897 SDL_AudioSpec desired; | |
6898 SDL_AudioSpec obtained; | |
6899 #endif | |
6900 | |
6901 | |
6902 | |
6903 | |
6904 /* Make sure ALmixer isn't already initialized */ | |
6905 if(ALmixer_Initialized) | |
6906 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6907 return AL_FALSE; |
0 | 6908 } |
6909 | |
6910 /* Set the defaults */ | |
6911 attrlist[0] = ALC_FREQUENCY; | |
6912 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6913 attrlist[2] = ALC_SYNC; | |
6914 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6915 attrlist[3] = ALC_TRUE; | |
6916 #else | |
6917 attrlist[3] = ALC_FALSE; | |
6918 #endif | |
6919 /* Set frequency value if it is not 0 */ | |
6920 if(0 != frequency) | |
6921 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6922 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6923 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6924 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6925 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6926 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6927 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6928 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6929 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6930 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6931 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6932 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6933 #endif |
0 | 6934 |
6935 /* If the user specifies a refresh value, | |
6936 * make room for it | |
6937 */ | |
6938 if(0 != refresh) | |
6939 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6940 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
|
6941 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6942 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6943 current_attrlist_index++; |
0 | 6944 } |
6945 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6946 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6947 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6948 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6949 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6950 |
0 | 6951 /* Initialize SDL_Sound */ |
6952 if(! Sound_Init() ) | |
6953 { | |
6954 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6955 return AL_FALSE; |
0 | 6956 } |
6957 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6958 /* Here is the paranoid check that opens | |
6959 * SDL audio in an attempt to find the correct | |
6960 * system values. | |
6961 */ | |
6962 /* Doesn't have to be the actual value I think | |
6963 * (as long as it doesn't influence format, in | |
6964 * which case I'm probably screwed anyway because OpenAL | |
6965 * may easily choose to do something else). | |
6966 */ | |
6967 desired.freq = 44100; | |
6968 desired.channels = 2; | |
6969 desired.format = AUDIO_S16SYS; | |
6970 desired.callback = my_dummy_audio_callback; | |
6971 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6972 { | |
6973 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6974 /* Now to get really paranoid, we should probably | |
6975 * also assume that the 8bit format is also the | |
6976 * same sign type and set that value | |
6977 */ | |
6978 if(AUDIO_S16SYS == obtained.format) | |
6979 { | |
6980 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6981 } | |
6982 /* Should be AUDIO_U16SYS */ | |
6983 else | |
6984 { | |
6985 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6986 } | |
6987 SDL_CloseAudio(); | |
6988 } | |
6989 else | |
6990 { | |
6991 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6992 */ | |
6993 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6994 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6995 } | |
6996 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6997 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6998 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6999 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
7000 * causes OpenAL and SMPEG to conflict. For some reason | |
7001 * if SDL_Init on audio is active, then all the SMPEG | |
7002 * decoded sound comes out silent. Unfortunately, | |
7003 * Sound_Init() invokes SDL_Init on audio. I'm | |
7004 * not sure why it actually needs it... | |
7005 * But we'll attempt to disable it here after the | |
7006 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
7007 */ | |
7008 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7009 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7010 |
0 | 7011 /* I'm told NULL will call the default string |
7012 * and hopefully do the right thing for each platform | |
7013 */ | |
7014 /* | |
7015 dev = alcOpenDevice( NULL ); | |
7016 */ | |
7017 /* Now I'm told I need to set both the device and context | |
7018 * to have the same sampling rate, so I must pass a string | |
7019 * to OpenDevice(). I don't know how portable these strings are. | |
7020 * I don't even know if the format for strings is | |
7021 * compatible | |
7022 * From the testattrib.c in the Loki test section | |
7023 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
7024 */ | |
7025 | |
7026 #ifdef USING_LOKI_AL_DIST | |
7027 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
7028 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
7029 #else | |
7030 dev = alcOpenDevice( NULL ); | |
7031 #endif | |
7032 if(NULL == dev) | |
7033 { | |
7034 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
|
7035 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7036 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7037 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7038 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7039 /* 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
|
7040 /* 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
|
7041 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7042 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7043 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7044 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7045 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
|
7046 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7047 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
|
7048 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7049 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7050 |
0 | 7051 |
7052 context = alcCreateContext(dev, attrlist); | |
7053 if(NULL == context) | |
7054 { | |
7055 ALmixer_SetError("Cannot create a context OpenAL"); | |
7056 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7057 return AL_FALSE; |
0 | 7058 } |
7059 | |
7060 | |
7061 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
7062 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
7063 * According to Garin Hiebert, this is actually an inconsistency | |
7064 * in the Loki version. The function should return a boolean. | |
7065 * instead of ALC_NO_ERROR. Garin suggested I check via | |
7066 * alcGetError(). | |
7067 */ | |
7068 /* clear the error */ | |
7069 alcGetError(dev); | |
7070 alcMakeContextCurrent(context); | |
7071 | |
7072 error = alcGetError(dev); | |
7073 if( (ALC_NO_ERROR != error) ) | |
7074 { | |
7075 ALmixer_SetError("Could not MakeContextCurrent"); | |
7076 alcDestroyContext(context); | |
7077 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7078 return AL_FALSE; |
0 | 7079 } |
7080 | |
7081 | |
7082 #if 0 | |
7083 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
7084 if(alcGetCurrentContext() != context) | |
7085 { | |
7086 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
7087 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
7088 * I think this is a bug in the OpenAL implementation. | |
7089 */ | |
7090 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
7091 | |
7092 fprintf(stderr, "Making context current\n"); | |
7093 #ifndef __APPLE__ | |
7094 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
7095 #else | |
7096 if(!alcMakeContextCurrent(context)) | |
7097 #endif | |
7098 { | |
7099 ALmixer_SetError("Could not MakeContextCurrent"); | |
7100 alcDestroyContext(context); | |
7101 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7102 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7103 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7104 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7105 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7106 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7107 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7108 /* 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
|
7109 * 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
|
7110 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7111 * 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
|
7112 * 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
|
7113 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7114 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7115 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7116 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
|
7117 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7118 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
|
7119 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7120 #endif |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7121 |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7122 |
0 | 7123 |
7124 /* Saw this in the README with the OS X OpenAL distribution. | |
7125 * It looked interesting and simple, so I thought I might | |
7126 * try it out. | |
7127 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
7128 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
7129 * Audio format, the audio data passed to the | |
7130 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
7131 * usage by removing an audio data conversion | |
7132 * (per source) at render timem at the expense of a larger memory footprint. | |
7133 * | |
7134 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
7135 * setting will be applied to all subsequent | |
7136 * calls to alBufferData(). | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7137 * 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
|
7138 * Rather than deal with it right now, I think I am going to make it an opt-in thing. |
0 | 7139 */ |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7140 #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
|
7141 /* |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7142 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
|
7143 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7144 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7145 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7146 #else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7147 /* 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
|
7148 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
|
7149 /* |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7150 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
|
7151 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7152 if(0 != convert_data_enum) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7153 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7154 alEnable(convert_data_enum); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7155 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7156 if( (AL_NO_ERROR != alGetError()) ) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7157 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7158 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
|
7159 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
|
7160 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7161 #endif |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7162 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7163 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7164 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7165 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7166 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7167 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7168 ALboolean ALmixer_InitMixer(ALuint num_sources) |
0 | 7169 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7170 ALint i; |
0 | 7171 ALenum error; |
7172 ALuint* source; | |
7173 | |
7174 | |
7175 ALmixer_Initialized = 1; | |
7176 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7177 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7178 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7179 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7180 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7181 /* 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
|
7182 /* 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
|
7183 * 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
|
7184 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7185 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7186 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7187 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7188 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7189 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7190 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7191 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7192 return AL_FALSE; |
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 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7195 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7196 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7197 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
|
7198 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
|
7199 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7200 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7201 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7202 if(num_sources == 0) |
0 | 7203 { |
7204 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
7205 } | |
7206 else | |
7207 { | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7208 Number_of_Channels_global = (ALint)num_sources; |
0 | 7209 } |
7210 Number_of_Reserve_Channels_global = 0; | |
7211 Is_Playing_global = 0; | |
7212 /* Set to Null in case system quit and was reinitialized */ | |
7213 Channel_Done_Callback = NULL; | |
7214 Channel_Done_Callback_Userdata = NULL; | |
7215 Channel_Data_Callback = NULL; | |
1 | 7216 Channel_Data_Callback_Userdata = NULL; |
0 | 7217 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7218 /* Allocate memory for linked list of ALmixerData. */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7219 s_listOfALmixerData = LinkedList_Create(); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7220 if(NULL == s_listOfALmixerData) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7221 { |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7222 ALmixer_SetError("Couldn't create linked list"); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7223 ALmixer_Initialized = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7224 Number_of_Channels_global = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7225 return AL_FALSE; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7226 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7227 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7228 |
0 | 7229 /* Allocate memory for the list of channels */ |
7230 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
7231 if(NULL == ALmixer_Channel_List) | |
7232 { | |
7233 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
|
7234 LinkedList_Free(s_listOfALmixerData); |
0 | 7235 ALmixer_Initialized = 0; |
7236 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7237 return AL_FALSE; |
0 | 7238 } |
7239 | |
7240 /* Allocate memory for the list of sources that map to the channels */ | |
7241 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
7242 if(NULL == Source_Map_List) | |
7243 { | |
7244 ALmixer_SetError("Out of Memory for Source Map List"); | |
7245 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7246 LinkedList_Free(s_listOfALmixerData); |
0 | 7247 ALmixer_Initialized = 0; |
7248 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7249 return AL_FALSE; |
0 | 7250 } |
7251 | |
7252 /* Create array that will hold the sources */ | |
7253 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
7254 if(NULL == source) | |
7255 { | |
7256 ALmixer_SetError("Out of Memory for sources"); | |
7257 free(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 /* Clear the error state */ | |
7266 alGetError(); | |
7267 /* Generate the OpenAL sources */ | |
7268 alGenSources(Number_of_Channels_global, source); | |
7269 if( (error=alGetError()) != AL_NO_ERROR) | |
7270 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7271 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 7272 free(ALmixer_Channel_List); |
7273 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7274 LinkedList_Free(s_listOfALmixerData); |
0 | 7275 ALmixer_Initialized = 0; |
7276 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7277 return AL_FALSE; |
0 | 7278 } |
7279 | |
7280 /* Initialize each channel and associate one source to one channel */ | |
7281 for(i=0; i<Number_of_Channels_global; i++) | |
7282 { | |
7283 Init_Channel(i); | |
7284 /* Keeping the source allocation out of the Init function | |
7285 * in case I want to reuse the Init | |
7286 * function for resetting data | |
7287 */ | |
7288 ALmixer_Channel_List[i].alsource = source[i]; | |
7289 /* Now also keep a copy of the source to channel mapping | |
7290 * in case we need to look up a channel from the source | |
7291 * instead of a source from a channel | |
7292 */ | |
7293 Source_Map_List[i].source = source[i]; | |
7294 Source_Map_List[i].channel = i; | |
7295 /* Clean the channel because there are some things that need to | |
7296 * be done that can't happen until the source is set | |
7297 */ | |
7298 Clean_Channel(i); | |
7299 } | |
7300 | |
7301 /* The Source_Map_List must be sorted by source for binary searches | |
7302 */ | |
7303 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
7304 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7305 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7306 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7307 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7308 if(NULL == s_simpleLock) |
0 | 7309 { |
7310 /* SDL sets the error message already? */ | |
7311 free(source); | |
7312 free(ALmixer_Channel_List); | |
7313 free(Source_Map_List); | |
7314 ALmixer_Initialized = 0; | |
7315 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7316 return AL_FALSE; |
0 | 7317 } |
7318 | |
7319 | |
7320 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
7321 if(NULL == Stream_Thread_global) | |
7322 { | |
7323 /* 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
|
7324 SDL_DestroyMutex(s_simpleLock); |
0 | 7325 free(source); |
7326 free(ALmixer_Channel_List); | |
7327 free(Source_Map_List); | |
7328 ALmixer_Initialized = 0; | |
7329 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7330 return AL_FALSE; |
0 | 7331 } |
24
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
7332 |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
7333 /* 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
|
7334 Internal_LowerThreadPriority(Stream_Thread_global); |
e085cbc573cf
iOS optimization/bug/workaround.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
22
diff
changeset
|
7335 |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7336 /* |
0 | 7337 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7338 */ |
0 | 7339 #endif /* End of ENABLE_ALMIXER_THREADS */ |
7340 | |
7341 /* We don't need this array any more because all the sources | |
7342 * are connected to channels | |
7343 */ | |
7344 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7345 return AL_TRUE; |
0 | 7346 } |
7347 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7348 void ALmixer_BeginInterruption() |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7349 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7350 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7351 SDL_LockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7352 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7353 s_interruptionContext = alcGetCurrentContext(); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7354 if(NULL != s_interruptionContext) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7355 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7356 /* iOS alcSuspendContext is a no-op */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7357 alcSuspendContext(s_interruptionContext); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7358 alcMakeContextCurrent(NULL); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7359 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7360 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7361 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7362 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7363 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7364 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7365 void ALmixer_EndInterruption() |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7366 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7367 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7368 SDL_LockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7369 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7370 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7371 /* Note: iOS, you need to set the AudioSession active. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7372 * But if the AudioSession is not initialized, this SetActive |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7373 * call fails. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7374 * 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
|
7375 */ |
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 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7378 OSStatus the_error = AudioSessionSetActive(true); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7379 if(noErr != the_error) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7380 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7381 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
|
7382 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7383 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7384 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7385 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7386 if(NULL != s_interruptionContext) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7387 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7388 alcMakeContextCurrent(s_interruptionContext); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7389 alcProcessContext(s_interruptionContext); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7390 s_interruptionContext = NULL; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7391 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7392 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7393 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7394 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7395 } |
0 | 7396 |
7397 /* Keep the return value void to allow easy use with | |
7398 * atexit() | |
7399 */ | |
7400 void ALmixer_Quit() | |
7401 { | |
7402 ALCcontext* context; | |
7403 ALCdevice* dev; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7404 ALint i; |
0 | 7405 |
7406 if( ! ALmixer_Initialized) | |
7407 { | |
7408 return; | |
7409 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7410 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7411 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7412 #endif |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7413 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7414 /* Several things we need to do: |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7415 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
|
7416 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
|
7417 Next, we should delete the OpenAL sources. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7418 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
|
7419 Finally, we can delete the OpenAL context. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7420 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7421 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7422 context = alcGetCurrentContext(); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7423 if(NULL == context) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7424 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7425 /* 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
|
7426 if(NULL == s_interruptionContext) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7427 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7428 /* Nothing left to try. I think we're done. */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7429 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
|
7430 return; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7431 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7432 else |
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 context = s_interruptionContext; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7435 /* reactivate the context so we can call OpenAL functions */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7436 alcMakeContextCurrent(context); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7437 s_interruptionContext = NULL; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7438 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7439 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7440 |
0 | 7441 /* Shutdown everything before closing context */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7442 Internal_HaltChannel(-1, AL_FALSE); |
0 | 7443 |
7444 /* This flag will cause the thread to terminate */ | |
7445 ALmixer_Initialized = 0; | |
7446 #ifdef ENABLE_ALMIXER_THREADS | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7447 SDL_UnlockMutex(s_simpleLock); |
0 | 7448 SDL_WaitThread(Stream_Thread_global, NULL); |
7449 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7450 SDL_DestroyMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7451 #endif |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7452 |
0 | 7453 /* Delete all the OpenAL sources */ |
7454 for(i=0; i<Number_of_Channels_global; i++) | |
7455 { | |
7456 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
7457 } | |
7458 /* Delete all the channels */ | |
7459 free(ALmixer_Channel_List); | |
7460 free(Source_Map_List); | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7461 |
0 | 7462 /* Reset the Number_of_Channels just in case somebody |
7463 * tries using a ALmixer function. | |
7464 * I probably should put "Initialized" checks everywhere, | |
7465 * but I'm too lazy at the moment. | |
7466 */ | |
7467 Number_of_Channels_global = 0; | |
7468 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7469 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7470 /* 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
|
7471 * 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
|
7472 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7473 while(LinkedList_Size(s_listOfALmixerData) > 0) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7474 { |
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
|
7475 /* 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
|
7476 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
|
7477 ALmixer_FreeData(almixer_data); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7478 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7479 LinkedList_Free(s_listOfALmixerData); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7480 s_listOfALmixerData = NULL; |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7481 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7482 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7483 /* 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
|
7484 dev = alcGetContextsDevice(context); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7485 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7486 alcMakeContextCurrent(NULL); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7487 alcDestroyContext(context); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7488 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7489 if(NULL == dev) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7490 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7491 return; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7492 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7493 alcCloseDevice(dev); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7494 |
0 | 7495 Sound_Quit(); |
7496 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7497 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7498 /* 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
|
7499 TError_FreeErrorPool(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7500 s_ALmixerErrorPool = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7501 #endif |
0 | 7502 return; |
7503 } | |
7504 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7505 ALboolean ALmixer_IsInitialized() |
0 | 7506 { |
7507 return ALmixer_Initialized; | |
7508 } | |
7509 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7510 ALuint ALmixer_GetFrequency() |
0 | 7511 { |
7512 return ALmixer_Frequency_global; | |
7513 } | |
7514 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7515 const ALmixer_version* ALmixer_GetLinkedVersion() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7516 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7517 static ALmixer_version linked_mixver; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7518 ALMIXER_GET_COMPILED_VERSION(&linked_mixver); |
0 | 7519 return(&linked_mixver); |
7520 } | |
7521 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7522 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7523 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7524 const char* ALmixer_GetError() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7525 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7526 const char* error_string = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7527 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7528 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7529 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
|
7530 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7531 error_string = TError_GetLastErrorStr(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7532 /* 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
|
7533 if(NULL == error_string) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7534 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7535 return ""; |
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 else |
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 return error_string; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7540 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7541 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7542 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7543 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
|
7544 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7545 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7546 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7547 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
|
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 va_list argp; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7551 va_start(argp, err_str); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7552 // 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
|
7553 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
|
7554 va_end(argp); |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7557 #endif |
0 | 7558 |
7559 | |
7560 | |
7561 | |
7562 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7563 void ALmixer_OutputAttributes() |
0 | 7564 { |
7565 ALint num_flags = 0; | |
7566 ALint* flags = 0; | |
7567 int i; | |
7568 ALCdevice* dev = alcGetContextsDevice( alcGetCurrentContext() ); | |
7569 | |
7570 | |
7571 printf("custom context\n"); | |
7572 | |
7573 alcGetIntegerv(dev, ALC_ATTRIBUTES_SIZE, | |
7574 sizeof num_flags, &num_flags ); | |
7575 | |
7576 printf("Number of Flags: %d\n", num_flags); | |
7577 | |
7578 if(num_flags) | |
7579 { | |
7580 flags = malloc(sizeof(num_flags) * sizeof(ALint)); | |
7581 | |
7582 alcGetIntegerv(dev, ALC_ALL_ATTRIBUTES, | |
7583 sizeof num_flags * sizeof(ALint), | |
7584 flags ); | |
7585 } | |
7586 for(i = 0; i < num_flags-1; i += 2) | |
7587 { | |
7588 printf("key 0x%x : value %d\n", | |
7589 flags[i], flags[i+1]); | |
7590 } | |
7591 free(flags); | |
7592 } | |
7593 #endif | |
7594 | |
7595 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7596 void ALmixer_OutputDecoders() |
0 | 7597 { |
7598 Sound_Version sound_compile_version; | |
7599 Sound_Version sound_link_version; | |
7600 | |
7601 const Sound_DecoderInfo **rc = Sound_AvailableDecoders(); | |
7602 const Sound_DecoderInfo **i; | |
7603 const char **ext; | |
7604 FILE* stream = stdout; | |
7605 | |
7606 | |
7607 fprintf(stream, "SDL_sound Information:\n"); | |
7608 | |
7609 SOUND_VERSION(&sound_compile_version); | |
7610 fprintf(stream, "\tCompiled with SDL_sound version: %d.%d.%d\n", | |
7611 sound_compile_version.major, | |
7612 sound_compile_version.minor, | |
7613 sound_compile_version.patch); | |
7614 | |
7615 Sound_GetLinkedVersion(&sound_link_version); | |
7616 fprintf(stream, "\tRunning (linked) with SDL_sound version: %d.%d.%d\n", | |
7617 sound_link_version.major, | |
7618 sound_link_version.minor, | |
7619 sound_link_version.patch); | |
7620 | |
7621 fprintf(stream, "Supported sound formats:\n"); | |
7622 if (rc == NULL) | |
7623 fprintf(stream, " * Apparently, NONE!\n"); | |
7624 else | |
7625 { | |
7626 for (i = rc; *i != NULL; i++) | |
7627 { | |
7628 fprintf(stream, " * %s\n", (*i)->description); | |
7629 | |
7630 for (ext = (*i)->extensions; *ext != NULL; ext++) | |
7631 fprintf(stream, " File extension \"%s\"\n", *ext); | |
7632 | |
7633 fprintf(stream, " Written by %s.\n %s\n\n", | |
7634 (*i)->author, (*i)->url); | |
7635 } /* for */ | |
7636 } /* else */ | |
7637 | |
7638 fprintf(stream, "\n"); | |
7639 } | |
7640 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7641 void ALmixer_OutputOpenALInfo() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7642 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7643 ALmixer_version mixer_compile_version; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7644 const ALmixer_version * mixer_link_version=ALmixer_GetLinkedVersion(); |
0 | 7645 FILE* stream = stdout; |
7646 | |
7647 fprintf(stream, "OpenAL Information:\n"); | |
7648 fprintf(stream, "\tAL_VENDOR: %s\n", alGetString( AL_VENDOR ) ); | |
7649 fprintf(stream, "\tAL_VERSION: %s\n", alGetString( AL_VERSION ) ); | |
7650 fprintf(stream, "\tAL_RENDERER: %s\n", alGetString( AL_RENDERER ) ); | |
7651 fprintf(stream, "\tAL_EXTENSIONS: %s\n", alGetString( AL_EXTENSIONS ) ); | |
7652 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7653 ALMIXER_GET_COMPILED_VERSION(&mixer_compile_version); |
0 | 7654 fprintf(stream, "\nSDL_ALmixer Information:\n"); |
7655 fprintf(stream, "\tCompiled with SDL_ALmixer version: %d.%d.%d\n", | |
7656 mixer_compile_version.major, | |
7657 mixer_compile_version.minor, | |
7658 mixer_compile_version.patch); | |
7659 | |
7660 fprintf(stream, "\tRunning (linked) with SDL_ALmixer version: %d.%d.%d\n", | |
7661 mixer_link_version->major, | |
7662 mixer_link_version->minor, | |
7663 mixer_link_version->patch); | |
7664 | |
7665 fprintf(stream, "\tCompile flags: "); | |
7666 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
7667 fprintf(stream, "ENABLE_LOKI_QUEUE_FIX_HACK "); | |
7668 #endif | |
7669 #ifdef ENABLE_ALMIXER_THREADS | |
7670 fprintf(stream, "ENABLE_ALMIXER_THREADS "); | |
7671 #endif | |
7672 #ifdef ENABLE_ALC_SYNC | |
7673 fprintf(stream, "ENABLE_ALC_SYNC "); | |
7674 #endif | |
7675 fprintf(stream, "\n"); | |
7676 } | |
7677 | |
7678 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7679 ALint ALmixer_AllocateChannels(ALint numchans) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7680 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7681 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7682 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7683 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7684 #endif |
0 | 7685 retval = Internal_AllocateChannels(numchans); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7686 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7687 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7688 #endif |
0 | 7689 return retval; |
7690 } | |
7691 | |
7692 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7693 ALint ALmixer_ReserveChannels(ALint num) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7694 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7695 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7696 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7697 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7698 #endif |
0 | 7699 retval = Internal_ReserveChannels(num); |
2
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7702 #endif |
0 | 7703 return retval; |
7704 } | |
7705 | |
7706 | |
7707 | |
7708 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7709 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
|
7710 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7711 ALuint bytes_decoded; |
0 | 7712 ALmixer_Data* ret_data; |
7713 ALenum error; | |
7714 | |
7715 /* Allocate memory */ | |
7716 ret_data = (ALmixer_Data *)malloc(sizeof(ALmixer_Data)); | |
7717 if (NULL == ret_data) | |
7718 { | |
7719 ALmixer_SetError("Out of memory"); | |
7720 return(NULL); | |
7721 } | |
7722 | |
7723 /* Initialize the data fields */ | |
7724 | |
7725 /* Set the Sound_Sample pointer */ | |
7726 ret_data->sample = sample; | |
7727 | |
7728 /* Flag the data to note that it is not in use */ | |
7729 ret_data->in_use = 0; | |
7730 | |
7731 /* Initialize remaining flags */ | |
7732 ret_data->total_time = -1; | |
7733 ret_data->eof = 0; | |
7734 | |
7735 /* Just initialize */ | |
7736 ret_data->num_buffers_in_use = 0; | |
7737 | |
7738 /* Just initialize */ | |
7739 ret_data->total_bytes = 0; | |
7740 | |
7741 /* Just initialize */ | |
7742 ret_data->loaded_bytes = 0; | |
7743 | |
7744 /* Set the max queue buffers (minimum must be 2) */ | |
7745 if(max_queue_buffers < 2) | |
7746 { | |
7747 max_queue_buffers = ALMIXER_DEFAULT_QUEUE_BUFFERS; | |
7748 } | |
7749 ret_data->max_queue_buffers = max_queue_buffers; | |
7750 /* Set up the start up buffers */ | |
7751 if(0 == num_startup_buffers) | |
7752 { | |
7753 num_startup_buffers = ALMIXER_DEFAULT_STARTUP_BUFFERS; | |
7754 } | |
7755 /* Make sure start up buffers is less or equal to max_queue_buffers */ | |
7756 if(num_startup_buffers > max_queue_buffers) | |
7757 { | |
7758 num_startup_buffers = max_queue_buffers; | |
7759 } | |
7760 ret_data->num_startup_buffers = num_startup_buffers; | |
7761 | |
7762 ret_data->buffer_map_list = NULL; | |
7763 ret_data->current_buffer = 0; | |
7764 | |
7765 ret_data->circular_buffer_queue = NULL; | |
7766 | |
7767 /* Now decode and load the data into a data chunk */ | |
7768 /* Different cases for Streamed and Predecoded | |
7769 * Streamed might turn into a predecoded if buffersize | |
7770 * is large enough */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7771 if(AL_FALSE == decode_mode_is_predecoded) |
0 | 7772 { |
7773 bytes_decoded = Sound_Decode(sample); | |
7774 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7775 { | |
7776 ALmixer_SetError(Sound_GetError()); | |
7777 Sound_FreeSample(sample); | |
7778 free(ret_data); | |
7779 return NULL; | |
7780 } | |
7781 | |
7782 /* If no data, return an error */ | |
7783 if(0 == bytes_decoded) | |
7784 { | |
7785 ALmixer_SetError("File has no data"); | |
7786 Sound_FreeSample(sample); | |
7787 free(ret_data); | |
7788 return NULL; | |
7789 } | |
7790 | |
7791 /* Note, currently, my Ogg conservative modifications | |
7792 * prevent EOF from being detected in the first read | |
7793 * because of the weird packet behavior of ov_read(). | |
7794 * The EAGAIN will get set, but not the EOF. | |
7795 * I don't know the best way to handle this, | |
7796 * so for now, Ogg's can only be explicitly | |
7797 * predecoded. | |
7798 */ | |
7799 | |
7800 /* Correction: Since we no longer actually keep the | |
7801 * streamed data we read here (we rewind and throw | |
7802 * it away, and start over on Play), it is | |
7803 * safe to read another chunk to see if we've hit EOF | |
7804 */ | |
7805 if(sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
7806 { | |
7807 bytes_decoded = Sound_Decode(sample); | |
7808 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7809 { | |
7810 ALmixer_SetError(Sound_GetError()); | |
7811 Sound_FreeSample(sample); | |
7812 free(ret_data); | |
7813 return NULL; | |
7814 } | |
7815 } | |
7816 | |
7817 | |
7818 /* If we found an EOF, the entire file was | |
7819 * decoded, so we can treat it like one. | |
7820 */ | |
7821 | |
7822 if(sample->flags & SOUND_SAMPLEFLAG_EOF) | |
7823 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7824 /* |
0 | 7825 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
|
7826 */ |
0 | 7827 ret_data->decoded_all = 1; |
7828 /* Need to keep this information around for | |
7829 * seek and rewind abilities. | |
7830 */ | |
7831 ret_data->total_bytes = bytes_decoded; | |
7832 /* For now, the loaded bytes is the same as total bytes, but | |
7833 * this could change during a seek operation | |
7834 */ | |
7835 ret_data->loaded_bytes = bytes_decoded; | |
7836 | |
7837 /* Let's compute the total playing time | |
7838 * SDL_sound does not yet provide this (we're working on | |
7839 * that at the moment...) | |
7840 */ | |
7841 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
7842 | |
7843 /* Create one element in the buffer array for data for OpanAL */ | |
7844 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
7845 if(NULL == ret_data->buffer) | |
7846 { | |
7847 ALmixer_SetError("Out of Memory"); | |
7848 Sound_FreeSample(sample); | |
7849 free(ret_data); | |
7850 return NULL; | |
7851 } | |
7852 /* Clear the error code */ | |
7853 alGetError(); | |
7854 /* Now generate an OpenAL buffer using that first element */ | |
7855 alGenBuffers(1, ret_data->buffer); | |
7856 if( (error = alGetError()) != AL_NO_ERROR) | |
7857 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7858 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7859 Sound_FreeSample(sample); |
7860 free(ret_data->buffer); | |
7861 free(ret_data); | |
7862 return NULL; | |
7863 } | |
7864 | |
7865 | |
7866 /* Now copy the data to the OpenAL buffer */ | |
7867 /* We can't just set a pointer because the API needs | |
7868 * its own copy to assist hardware acceleration */ | |
7869 alBufferData(ret_data->buffer[0], | |
7870 TranslateFormat(&sample->desired), | |
7871 sample->buffer, | |
7872 bytes_decoded, | |
7873 sample->desired.rate | |
7874 ); | |
7875 if( (error = alGetError()) != AL_NO_ERROR) | |
7876 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7877 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 7878 Sound_FreeSample(sample); |
7879 alDeleteBuffers(1, ret_data->buffer); | |
7880 free(ret_data->buffer); | |
7881 free(ret_data); | |
7882 return NULL; | |
7883 } | |
7884 | |
7885 /* We should be done with the sample since it's all | |
7886 * predecoded. So we can free the memory */ | |
7887 | |
7888 /* Additional notes: | |
7889 * We need to keep data around in case Seek() is needed | |
7890 * or other Sound_AudioInfo is needed. | |
7891 * This can either be done by not deleting the sample, | |
7892 * or it can be done by dynamically recreating it | |
7893 * when we need it. | |
7894 */ | |
7895 /* Since OpenAL won't let us retrieve it | |
7896 * (aka dynamically), we have to keep the Sample | |
7897 * around because since the user requested | |
7898 * streamed and we offered predecoded, | |
7899 * we don't want to mess up the user who | |
7900 * was expecting seek support | |
7901 * So Don't Do anything | |
7902 */ | |
7903 /* | |
7904 if(0 == access_data) | |
7905 { | |
7906 Sound_FreeSample(sample); | |
7907 ret_data->sample = NULL; | |
7908 } | |
7909 */ | |
7910 /* Else, We keep a copy of the sample around. | |
7911 * so don't do anything. | |
7912 */ | |
7913 | |
7914 #if 0 | |
7915 #if defined(DISABLE_PREDECODED_SEEK) | |
7916 Sound_FreeSample(sample); | |
7917 ret_data->sample = NULL; | |
7918 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
7919 Sound_FreeSample(sample); | |
7920 ret_data->sample = NULL; | |
7921 #else | |
7922 /* We keep a copy of the sample around. | |
7923 * so don't do anything. | |
7924 */ | |
7925 #endif | |
7926 #endif | |
7927 /* okay we're done here */ | |
7928 | |
7929 } | |
7930 /* Else, we need to stream the data, so we'll | |
7931 * create multple buffers for queuing */ | |
7932 else | |
7933 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7934 /* |
0 | 7935 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
|
7936 */ |
0 | 7937 ret_data->decoded_all = 0; |
7938 | |
7939 /* This information is for predecoded. | |
7940 * Set to 0, since we don't know. | |
7941 */ | |
7942 ret_data->total_bytes = 0; | |
7943 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7944 ret_data->total_time = Sound_GetDuration(sample); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7945 |
0 | 7946 /* Create buffers for data |
7947 */ | |
7948 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) * max_queue_buffers); | |
7949 if(NULL == ret_data->buffer) | |
7950 { | |
7951 ALmixer_SetError("Out of Memory"); | |
7952 Sound_FreeSample(sample); | |
7953 free(ret_data); | |
7954 return NULL; | |
7955 } | |
7956 | |
7957 /* Clear the error code */ | |
7958 alGetError(); | |
7959 /* Now generate an OpenAL buffer using that first element */ | |
7960 alGenBuffers(max_queue_buffers, ret_data->buffer); | |
7961 if( (error = alGetError()) != AL_NO_ERROR) | |
7962 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7963 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7964 Sound_FreeSample(sample); |
7965 free(ret_data->buffer); | |
7966 free(ret_data); | |
7967 return NULL; | |
7968 } | |
7969 | |
7970 /* Redesign: Okay, because of the unqueuing problems and such, | |
7971 * I've decided to redesign where and how queuing is handled. | |
7972 * Before, everything was queued up here. However, this | |
7973 * placed a penalty on load and made performance inconsistent | |
7974 * when samples had to be rewound. It did make things easier | |
7975 * to queue because I could let OpenAL decide which buffer | |
7976 * needed to be queued next. | |
7977 * Now, I'm going to push off the queuing to the actual | |
7978 * Play() command. I'm going to add some book keeping, | |
7979 * and allow for additional buffers to be filled at later | |
7980 * times. | |
7981 */ | |
7982 | |
7983 | |
7984 /* So first of all, because of I already decoded the sample | |
7985 * for testing, I need to decide what to do with it. | |
7986 * The best thing would be be to alBufferData() it. | |
7987 * The problem is it may conflict with the rest of | |
7988 * the system because everything now assumes buffers | |
7989 * are entirely stripped (because of the unqueing | |
7990 * problem). | |
7991 * So it looks like I have to do the crappy thing | |
7992 * and throw away the data, and rewind. | |
7993 */ | |
7994 | |
7995 if(0 == Sound_Rewind(ret_data->sample)) | |
7996 { | |
7997 ALmixer_SetError("Cannot use sample for streamed data because it must be rewindable: %s", Sound_GetError() ); | |
7998 Sound_FreeSample(sample); | |
7999 free(ret_data->buffer); | |
8000 free(ret_data); | |
8001 return NULL; | |
8002 } | |
8003 | |
8004 | |
8005 /* If the user has selected access_data, we need to | |
8006 * keep copies of the queuing buffers around because | |
8007 * OpenAL won't let us access the data. | |
8008 * Allocate the memory for the buffers here | |
8009 * and initialize the albuffer-index map | |
8010 */ | |
8011 if(access_data) | |
8012 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8013 ALuint j; |
0 | 8014 /* Create buffers for data access |
8015 * Should be the same number as the number of queue buffers | |
8016 */ | |
1 | 8017 ret_data->buffer_map_list = (ALmixer_Buffer_Map*)malloc( sizeof(ALmixer_Buffer_Map) * max_queue_buffers); |
0 | 8018 if(NULL == ret_data->buffer_map_list) |
8019 { | |
8020 ALmixer_SetError("Out of Memory"); | |
8021 Sound_FreeSample(sample); | |
8022 free(ret_data->buffer); | |
8023 free(ret_data); | |
8024 return NULL; | |
8025 } | |
8026 | |
8027 ret_data->circular_buffer_queue = CircularQueueUnsignedInt_CreateQueue(max_queue_buffers); | |
8028 if(NULL == ret_data->circular_buffer_queue) | |
8029 { | |
8030 ALmixer_SetError("Out of Memory"); | |
8031 free(ret_data->buffer_map_list); | |
8032 Sound_FreeSample(sample); | |
8033 free(ret_data->buffer); | |
8034 free(ret_data); | |
8035 return NULL; | |
8036 } | |
8037 | |
8038 | |
8039 for(j=0; j<max_queue_buffers; j++) | |
8040 { | |
8041 ret_data->buffer_map_list[j].albuffer = ret_data->buffer[j]; | |
8042 ret_data->buffer_map_list[j].index = j; | |
8043 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
|
8044 ret_data->buffer_map_list[j].data = (ALbyte*)malloc( sizeof(ALbyte) * buffersize); |
0 | 8045 if(NULL == ret_data->buffer_map_list[j].data) |
8046 { | |
8047 ALmixer_SetError("Out of Memory"); | |
8048 break; | |
8049 } | |
8050 } | |
8051 /* If an error happened, we have to clean up the memory */ | |
8052 if(j < max_queue_buffers) | |
8053 { | |
8054 fprintf(stderr, "################## Buffer allocation failed\n"); | |
8055 for( ; j>=0; j--) | |
8056 { | |
8057 free(ret_data->buffer_map_list[j].data); | |
8058 } | |
8059 free(ret_data->buffer_map_list); | |
8060 CircularQueueUnsignedInt_FreeQueue(ret_data->circular_buffer_queue); | |
8061 Sound_FreeSample(sample); | |
8062 free(ret_data->buffer); | |
8063 free(ret_data); | |
8064 return NULL; | |
8065 } | |
8066 | |
8067 /* The Buffer_Map_List must be sorted by albuffer for binary searches | |
8068 */ | |
1 | 8069 qsort(ret_data->buffer_map_list, max_queue_buffers, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 8070 } /* End if access_data==true */ |
8071 | |
8072 | |
8073 } /* End of do stream */ | |
8074 } /* end of DECODE_STREAM */ | |
8075 /* 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
|
8076 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
|
8077 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8078 #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
|
8079 /* 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
|
8080 * 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
|
8081 * 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
|
8082 * so looping isn't needed. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8083 * 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
|
8084 * 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
|
8085 * 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
|
8086 * 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
|
8087 * 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
|
8088 * 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
|
8089 * to load a file. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8090 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8091 ALint sound_duration = Sound_GetDuration(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8092 if(sound_duration > 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8093 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8094 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
|
8095 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
|
8096 if(0 == buffer_resize_succeeded) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8097 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8098 ALmixer_SetError(Sound_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8099 Sound_FreeSample(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8100 free(ret_data); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8101 return NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8102 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8103 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8104 #endif /* ALMIXER_DISABLE_PREDECODED_PRECOMPUTE_BUFFER_SIZE_OPTIMIZATION */ |
0 | 8105 bytes_decoded = Sound_DecodeAll(sample); |
8106 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
8107 { | |
8108 ALmixer_SetError(Sound_GetError()); | |
8109 Sound_FreeSample(sample); | |
8110 free(ret_data); | |
8111 return NULL; | |
8112 } | |
8113 | |
8114 /* If no data, return an error */ | |
8115 if(0 == bytes_decoded) | |
8116 { | |
8117 ALmixer_SetError("File has no data"); | |
8118 Sound_FreeSample(sample); | |
8119 free(ret_data); | |
8120 return NULL; | |
8121 } | |
8122 | |
8123 | |
8124 ret_data->decoded_all = 1; | |
8125 /* Need to keep this information around for | |
8126 * seek and rewind abilities. | |
8127 */ | |
8128 ret_data->total_bytes = bytes_decoded; | |
8129 /* For now, the loaded bytes is the same as total bytes, but | |
8130 * this could change during a seek operation | |
8131 */ | |
8132 ret_data->loaded_bytes = bytes_decoded; | |
8133 | |
8134 /* Let's compute the total playing time | |
8135 * SDL_sound does not yet provide this (we're working on | |
8136 * that at the moment...) | |
8137 */ | |
8138 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
8139 | |
8140 /* Create one element in the buffer array for data for OpanAL */ | |
8141 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
8142 if(NULL == ret_data->buffer) | |
8143 { | |
8144 ALmixer_SetError("Out of Memory"); | |
8145 Sound_FreeSample(sample); | |
8146 free(ret_data); | |
8147 return NULL; | |
8148 } | |
8149 /* Clear the error code */ | |
8150 alGetError(); | |
8151 /* Now generate an OpenAL buffer using that first element */ | |
8152 alGenBuffers(1, ret_data->buffer); | |
8153 if( (error = alGetError()) != AL_NO_ERROR) | |
8154 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8155 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 8156 Sound_FreeSample(sample); |
8157 free(ret_data->buffer); | |
8158 free(ret_data); | |
8159 return NULL; | |
8160 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8161 /* |
0 | 8162 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
|
8163 */ |
0 | 8164 /* Now copy the data to the OpenAL buffer */ |
8165 /* We can't just set a pointer because the API needs | |
8166 * its own copy to assist hardware acceleration */ | |
8167 alBufferData(ret_data->buffer[0], | |
8168 TranslateFormat(&sample->desired), | |
8169 sample->buffer, | |
8170 bytes_decoded, | |
8171 sample->desired.rate | |
8172 ); | |
8173 if( (error = alGetError()) != AL_NO_ERROR) | |
8174 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8175 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 8176 Sound_FreeSample(sample); |
8177 alDeleteBuffers(1, ret_data->buffer); | |
8178 free(ret_data->buffer); | |
8179 free(ret_data); | |
8180 return NULL; | |
8181 } | |
8182 | |
8183 /* We should be done with the sample since it's all | |
8184 * predecoded. So we can free the memory */ | |
8185 /* Need to keep around because Seek() needs it */ | |
8186 | |
8187 /* Additional notes: | |
8188 * We need to keep data around in case Seek() is needed | |
8189 * or other Sound_AudioInfo is needed. | |
8190 * This can either be done by not deleting the sample, | |
8191 * or it can be done by dynamically recreating it | |
8192 * when we need it. | |
8193 * Update: I think now it's up to the user by passing the | |
8194 * access_data flag. If they set the flag, then they get | |
8195 * data callbacks and seek support. If not, then they can | |
8196 * get all that stuff at the expense of keeping extra memory | |
8197 * around. | |
8198 */ | |
8199 if(0 == access_data) | |
8200 { | |
8201 Sound_FreeSample(sample); | |
8202 ret_data->sample = NULL; | |
8203 } | |
8204 | |
8205 /* Else, We keep a copy of the sample around. | |
8206 * so don't do anything. | |
8207 */ | |
8208 #if 0 | |
8209 #if defined(DISABLE_PREDECODED_SEEK) | |
8210 Sound_FreeSample(sample); | |
8211 ret_data->sample = NULL; | |
8212 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
8213 Sound_FreeSample(sample); | |
8214 ret_data->sample = NULL; | |
8215 #else | |
8216 /* We keep a copy of the sample around. | |
8217 * so don't do anything. | |
8218 */ | |
8219 #endif | |
8220 #endif | |
8221 | |
8222 /* okay we're done here */ | |
8223 } | |
8224 else | |
8225 { | |
8226 /* Shouldn't get here */ | |
8227 ALmixer_SetError("Unknown decode mode"); | |
8228 Sound_FreeSample(sample); | |
8229 free(ret_data); | |
8230 return NULL; | |
8231 } | |
8232 | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8233 /* 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
|
8234 * 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
|
8235 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8236 LinkedList_PushBack(s_listOfALmixerData, ret_data); |
0 | 8237 return ret_data; |
8238 } | |
8239 | |
8240 | |
8241 /* This will load a sample for us. Most of the uglyness is | |
8242 * error checking and the fact that streamed/predecoded files | |
8243 * must be treated differently. | |
8244 * I don't like the AudioInfo parameter. I removed it once, | |
8245 * but the system will fail on RAW samples because the user | |
8246 * must specify it, so I had to bring it back. | |
8247 * Remember I must close the rwops if there is an error before NewSample() | |
8248 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8249 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 | 8250 { |
8251 Sound_Sample* sample = NULL; | |
8252 Sound_AudioInfo target; | |
8253 | |
8254 /* Initialize target values to defaults | |
8255 * 0 tells SDL_sound to use the "actual" values | |
8256 */ | |
8257 target.channels = 0; | |
8258 target.rate = 0; | |
8259 #if 0 | |
8260 /* This requires my new additions to SDL_sound. It will | |
8261 * convert the sample to the proper endian order. | |
8262 * If the actual is 8-bit, it will do unsigned, if | |
8263 * the actual is 16-bit, it will do signed. | |
8264 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
8265 * in this way. | |
8266 */ | |
8267 target.format = AUDIO_U8S16SYS; | |
8268 #else | |
8269 target.format = AUDIO_S16SYS; | |
8270 #endif | |
8271 | |
8272 /* Set a default buffersize if needed */ | |
8273 if(0 == buffersize) | |
8274 { | |
8275 buffersize = ALMIXER_DEFAULT_BUFFERSIZE; | |
8276 } | |
8277 | |
8278 sample = Sound_NewSample(rwops, fileext, &target, buffersize); | |
8279 if(NULL == sample) | |
8280 { | |
8281 ALmixer_SetError(Sound_GetError()); | |
8282 return NULL; | |
8283 } | |
8284 | |
1 | 8285 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8286 } |
8287 | |
8288 | |
8289 | |
8290 /* This will load a sample for us from | |
8291 * a file (instead of RWops). Most of the uglyness is | |
8292 * error checking and the fact that streamed/predecoded files | |
8293 * must be treated differently. | |
8294 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8295 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 | 8296 { |
8297 Sound_Sample* sample = NULL; | |
8298 Sound_AudioInfo target; | |
8299 | |
8300 /* Initialize target values to defaults | |
8301 * 0 tells SDL_sound to use the "actual" values | |
8302 */ | |
8303 target.channels = 0; | |
8304 target.rate = 0; | |
8305 | |
8306 #if 0 | |
8307 /* This requires my new additions to SDL_sound. It will | |
8308 * convert the sample to the proper endian order. | |
8309 * If the actual is 8-bit, it will do unsigned, if | |
8310 * the actual is 16-bit, it will do signed. | |
8311 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
8312 * in this way. | |
8313 */ | |
8314 target.format = AUDIO_U8S16SYS; | |
8315 #else | |
8316 target.format = AUDIO_S16SYS; | |
8317 #endif | |
8318 | |
8319 #if 0 | |
8320 /* Okay, here's a messy hack. The problem is that we need | |
8321 * to convert the sample to have the correct bitdepth, | |
8322 * endian order, and signedness values. | |
8323 * The bit depth is 8 or 16. | |
8324 * The endian order is the native order of the system. | |
8325 * The signedness depends on what the original value | |
8326 * of the sample. Unfortunately, we can't specify these | |
8327 * values until we after we already know what the original | |
8328 * values were for bitdepth and signedness. | |
8329 * So we must open the file once to get the values, | |
8330 * then close it, and then reopen it with the | |
8331 * correct desired target values. | |
8332 * I tried changing the sample->desired field after | |
8333 * the NewSample call, but it had no effect, so | |
8334 * it looks like it must be set on open. | |
8335 */ | |
8336 /* Pick a small buffersize for the first open to not | |
8337 * waste much time allocating memory */ | |
8338 sample = Sound_NewSampleFromFile(filename, NULL, 512); | |
8339 if(NULL == sample) | |
8340 { | |
8341 ALmixer_SetError(Sound_GetError()); | |
8342 return NULL; | |
8343 } | |
8344 | |
8345 bit_depth = GetBitDepth(sample->actual.format); | |
8346 signedness_value = GetSignednessValue(sample->actual.format); | |
8347 if(8 == bit_depth) | |
8348 { | |
8349 /* If 8 bit, then we don't have to worry about | |
8350 * endian issues. We can just use the actual format | |
8351 * value and it should do the right thing | |
8352 */ | |
8353 target.format = sample->actual.format; | |
8354 } | |
8355 else | |
8356 { | |
8357 /* We'll assume it's 16-bit, and if it's not | |
8358 * hopefully SDL_sound will return an error, | |
8359 * or let us convert to 16-bit | |
8360 */ | |
8361 /* Now we need to get the correct signedness */ | |
8362 if(ALMIXER_UNSIGNED_VALUE == signedness_value) | |
8363 { | |
8364 /* Set to Unsigned 16-bit, system endian order */ | |
8365 target.format = AUDIO_U16SYS; | |
8366 } | |
8367 else | |
8368 { | |
8369 /* Again, we'll assume it's Signed 16-bit system order | |
8370 * or force the conversion and hope it works out | |
8371 */ | |
8372 target.format = AUDIO_S16SYS; | |
8373 } | |
8374 } | |
8375 | |
8376 /* Now we have the correct info. We need to close and reopen */ | |
8377 Sound_FreeSample(sample); | |
8378 #endif | |
8379 | |
8380 sample = Sound_NewSampleFromFile(filename, &target, buffersize); | |
8381 if(NULL == sample) | |
8382 { | |
8383 ALmixer_SetError(Sound_GetError()); | |
8384 return NULL; | |
8385 } | |
8386 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8387 /* |
0 | 8388 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
|
8389 */ |
1 | 8390 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8391 } |
8392 | |
8393 | |
8394 /* This is a back door for RAW samples or if you need the | |
8395 * AudioInfo field. Use at your own risk. | |
8396 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8397 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 | 8398 { |
8399 Sound_Sample* sample = NULL; | |
1 | 8400 Sound_AudioInfo sound_desired; |
8401 /* Rather than copying the data from struct to struct, I could just | |
8402 * cast the thing since the structs are meant to be identical. | |
8403 * But if SDL_sound changes it's implementation, bad things | |
8404 * will probably happen. (Or if I change my implementation and | |
8405 * forget about the cast, same bad scenario.) Since this is a load | |
8406 * function, performance of this is negligible. | |
8407 */ | |
8408 if(NULL == desired) | |
8409 { | |
8410 sample = Sound_NewSample(rwops, fileext, NULL, buffersize); | |
8411 } | |
8412 else | |
8413 { | |
8414 sound_desired.format = desired->format; | |
8415 sound_desired.channels = desired->channels; | |
8416 sound_desired.rate = desired->rate; | |
8417 sample = Sound_NewSample(rwops, fileext, &sound_desired, buffersize); | |
8418 } | |
0 | 8419 if(NULL == sample) |
8420 { | |
8421 ALmixer_SetError(Sound_GetError()); | |
8422 return NULL; | |
8423 } | |
1 | 8424 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8425 } |
8426 | |
8427 | |
8428 | |
8429 | |
8430 /* This is a back door for RAW samples or if you need the | |
8431 * AudioInfo field. Use at your own risk. | |
8432 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8433 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 | 8434 { |
8435 Sound_Sample* sample = NULL; | |
1 | 8436 Sound_AudioInfo sound_desired; |
8437 /* Rather than copying the data from struct to struct, I could just | |
8438 * cast the thing since the structs are meant to be identical. | |
8439 * But if SDL_sound changes it's implementation, bad things | |
8440 * will probably happen. (Or if I change my implementation and | |
8441 * forget about the cast, same bad scenario.) Since this is a load | |
8442 * function, performance of this is negligible. | |
8443 */ | |
8444 if(NULL == desired) | |
8445 { | |
8446 sample = Sound_NewSampleFromFile(filename, NULL, buffersize); | |
8447 } | |
8448 else | |
8449 { | |
8450 sound_desired.format = desired->format; | |
8451 sound_desired.channels = desired->channels; | |
8452 sound_desired.rate = desired->rate; | |
8453 sample = Sound_NewSampleFromFile(filename, &sound_desired, buffersize); | |
8454 } | |
8455 | |
0 | 8456 if(NULL == sample) |
8457 { | |
8458 ALmixer_SetError(Sound_GetError()); | |
8459 return NULL; | |
8460 } | |
1 | 8461 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8462 } |
8463 | |
8464 | |
8465 | |
8466 | |
8467 void ALmixer_FreeData(ALmixer_Data* data) | |
8468 { | |
8469 ALenum error; | |
8470 if(NULL == data) | |
8471 { | |
8472 return; | |
8473 } | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8474 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8475 /* Bypass if in interruption event */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8476 if(NULL == alcGetCurrentContext()) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8477 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8478 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
|
8479 return; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8480 } |
0 | 8481 |
8482 if(data->decoded_all) | |
8483 { | |
8484 /* If access_data was enabled, then the Sound_Sample* | |
8485 * still exists. We need to free it | |
8486 */ | |
8487 if(data->sample != NULL) | |
8488 { | |
8489 Sound_FreeSample(data->sample); | |
8490 } | |
8491 alDeleteBuffers(1, data->buffer); | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8492 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8493 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8494 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
|
8495 } |
0 | 8496 } |
8497 else | |
8498 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8499 ALuint i; |
0 | 8500 |
8501 /* Delete buffer copies if access_data was enabled */ | |
8502 if(data->buffer_map_list != NULL) | |
8503 { | |
8504 for(i=0; i<data->max_queue_buffers; i++) | |
8505 { | |
8506 free(data->buffer_map_list[i].data); | |
8507 } | |
8508 free(data->buffer_map_list); | |
8509 } | |
8510 if(data->circular_buffer_queue != NULL) | |
8511 { | |
8512 CircularQueueUnsignedInt_FreeQueue(data->circular_buffer_queue); | |
8513 } | |
8514 | |
8515 Sound_FreeSample(data->sample); | |
8516 alDeleteBuffers(data->max_queue_buffers, data->buffer); | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8517 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8518 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8519 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
|
8520 } |
0 | 8521 } |
8522 free(data->buffer); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8523 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8524 LinkedList_Remove(s_listOfALmixerData, |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8525 LinkedList_Find(s_listOfALmixerData, data, NULL) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8526 ); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8527 |
0 | 8528 free(data); |
8529 } | |
8530 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8531 ALint ALmixer_GetTotalTime(ALmixer_Data* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8532 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8533 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8534 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8535 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8536 } |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8537 |
0 | 8538 return data->total_time; |
8539 } | |
8540 | |
8541 /* This function will look up the source for the corresponding channel */ | |
8542 /* 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
|
8543 ALuint ALmixer_GetSource(ALint channel) |
0 | 8544 { |
8545 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8546 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8547 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8548 #endif |
0 | 8549 retval = Internal_GetSource(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8550 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8551 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8552 #endif |
0 | 8553 return retval; |
8554 } | |
8555 | |
8556 /* 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
|
8557 ALint ALmixer_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8558 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8559 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8560 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8561 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8562 #endif |
0 | 8563 retval = Internal_GetChannel(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8564 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8565 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8566 #endif |
0 | 8567 return retval; |
8568 } | |
8569 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8570 ALint ALmixer_FindFreeChannel(ALint start_channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8571 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8572 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8573 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8574 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8575 #endif |
0 | 8576 retval = Internal_FindFreeChannel(start_channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8577 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8578 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8579 #endif |
0 | 8580 return retval; |
8581 } | |
8582 | |
8583 | |
8584 | |
8585 /* API update function. | |
8586 * It should return the number of buffers that were | |
8587 * queued during the call. The value might be | |
8588 * used to guage how long you might wait to | |
8589 * call the next update loop in case you are worried | |
8590 * about preserving CPU cycles. The idea is that | |
8591 * when a buffer is queued, there was probably some | |
8592 * CPU intensive looping which took awhile. | |
8593 * 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
|
8594 * Timing the call with ALmixer_GetTicks() would produce |
0 | 8595 * more accurate information. |
8596 * Returns a negative value if there was an error, | |
8597 * the value being the number of errors. | |
8598 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8599 ALint ALmixer_Update() |
0 | 8600 { |
8601 #ifdef ENABLE_ALMIXER_THREADS | |
8602 /* The thread will handle all updates by itself. | |
8603 * Don't allow the user to explicitly call update. | |
8604 */ | |
8605 return 0; | |
8606 #else | |
8607 return( Update_ALmixer(NULL) ); | |
8608 #endif | |
8609 } | |
8610 | |
8611 | |
8612 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8613 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
|
8614 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8615 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8616 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8617 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8618 Channel_Done_Callback = playback_finished_callback; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8619 Channel_Done_Callback_Userdata = user_data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8620 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8621 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8622 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8623 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8624 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8625 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8626 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
|
8627 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8628 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8629 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8630 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8631 Channel_Data_Callback = playback_data_callback; |
1 | 8632 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
|
8633 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8634 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8635 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8636 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8637 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8638 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8639 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8640 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8641 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8642 ALint 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
|
8643 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8644 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8645 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8646 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8647 #endif |
0 | 8648 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
|
8649 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8650 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8651 #endif |
0 | 8652 return retval; |
8653 } | |
8654 | |
8655 | |
8656 /* In case the user wants to specify a source instead of a channel, | |
8657 * they may use this function. This function will look up the | |
8658 * source-to-channel map, and convert the call into a | |
8659 * PlayChannelTimed() function call. | |
8660 * Returns the channel it's being played on. | |
8661 * Note: If you are prefer this method, then you need to be careful | |
8662 * about using PlayChannel, particularly if you request the | |
8663 * first available channels because source and channels have | |
8664 * a one-to-one mapping in this API. It is quite easy for | |
8665 * a channel/source to already be in use because of this. | |
8666 * In this event, an error message will be returned to you. | |
8667 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8668 ALuint ALmixer_PlaySourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALint ticks) |
0 | 8669 { |
8670 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8671 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8672 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8673 #endif |
0 | 8674 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
|
8675 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8676 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8677 #endif |
0 | 8678 return retval; |
8679 } | |
8680 | |
8681 | |
8682 /* Will return the number of channels halted | |
8683 * or 0 for error | |
8684 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8685 ALint ALmixer_HaltChannel(ALint channel) |
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 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8688 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8689 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8690 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8691 retval = Internal_HaltChannel(channel, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8692 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8693 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8694 #endif |
0 | 8695 return retval; |
8696 } | |
8697 | |
8698 /* Will return the number of channels halted | |
8699 * or 0 for error | |
8700 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8701 ALint ALmixer_HaltSource(ALuint source) |
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 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8704 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8705 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8706 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8707 retval = Internal_HaltSource(source, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8708 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8709 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8710 #endif |
0 | 8711 return retval; |
8712 } | |
8713 | |
8714 | |
8715 /* This will rewind the SDL_Sound sample for streamed | |
8716 * samples and start buffering up the data for the next | |
8717 * playback. This may require samples to be halted | |
8718 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8719 ALboolean ALmixer_RewindData(ALmixer_Data* data) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8720 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8721 ALboolean retval; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8722 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8723 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8724 #endif |
0 | 8725 retval = Internal_RewindData(data); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8726 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8727 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8728 #endif |
0 | 8729 return retval; |
8730 } | |
8731 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8732 ALint ALmixer_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8733 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8734 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8735 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8736 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8737 #endif |
0 | 8738 retval = Internal_RewindChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8739 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8740 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8741 #endif |
0 | 8742 return retval; |
8743 } | |
8744 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8745 ALint ALmixer_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8746 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8747 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8748 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8749 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8750 #endif |
0 | 8751 retval = Internal_RewindSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8752 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8753 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8754 #endif |
0 | 8755 return retval; |
8756 } | |
8757 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8758 ALint ALmixer_PauseChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8759 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8760 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8761 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8762 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8763 #endif |
0 | 8764 retval = Internal_PauseChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8765 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8766 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8767 #endif |
0 | 8768 return retval; |
8769 } | |
8770 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8771 ALint ALmixer_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8772 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8773 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8774 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8775 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8776 #endif |
0 | 8777 retval = Internal_PauseSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8778 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8779 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8780 #endif |
0 | 8781 return retval; |
8782 } | |
8783 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8784 ALint ALmixer_ResumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8785 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8786 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8787 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8788 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8789 #endif |
0 | 8790 retval = Internal_ResumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8791 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8792 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8793 #endif |
0 | 8794 return retval; |
8795 } | |
8796 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8797 ALint ALmixer_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8798 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8799 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8800 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8801 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8802 #endif |
0 | 8803 retval = Internal_ResumeSource(source); |
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8806 #endif |
0 | 8807 return retval; |
8808 } | |
8809 | |
8810 /* Might consider setting eof to 0 as a "feature" | |
8811 * This will allow seek to end to stay there because | |
8812 * Play automatically rewinds if at the end */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8813 ALboolean ALmixer_SeekData(ALmixer_Data* data, ALuint msec) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8814 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8815 ALboolean retval; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8816 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8817 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8818 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8819 retval = Internal_SeekData(data, msec); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8820 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8821 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8822 #endif |
0 | 8823 return retval; |
8824 } | |
8825 | |
20
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8826 ALint ALmixer_SeekChannel(ALint channel, ALuint msec) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8827 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8828 ALint retval; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8829 #ifdef ENABLE_ALMIXER_THREADS |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8830 SDL_LockMutex(s_simpleLock); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8831 #endif |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8832 retval = Internal_SeekChannel(channel, msec); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8833 #ifdef ENABLE_ALMIXER_THREADS |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8834 SDL_UnlockMutex(s_simpleLock); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8835 #endif |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8836 return retval; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8837 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8838 |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8839 ALint ALmixer_SeekSource(ALuint source, ALuint msec) |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8840 { |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8841 ALint retval; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8842 #ifdef ENABLE_ALMIXER_THREADS |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8843 SDL_LockMutex(s_simpleLock); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8844 #endif |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8845 retval = Internal_SeekSource(source, msec); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8846 #ifdef ENABLE_ALMIXER_THREADS |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8847 SDL_UnlockMutex(s_simpleLock); |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8848 #endif |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8849 return retval; |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8850 } |
9365e714fc4b
Added SeekChannel, SeekSource.
Eric Wing <ewing@anscamobile.com>
parents:
16
diff
changeset
|
8851 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8852 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
|
8853 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8854 ALint retval; |
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_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
|
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 ALuint ALmixer_FadeInSourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 8866 { |
8867 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8868 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8869 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8870 #endif |
0 | 8871 retval = Internal_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
|
8872 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8873 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8874 #endif |
0 | 8875 return retval; |
8876 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8877 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8878 ALint ALmixer_FadeOutChannel(ALint channel, ALuint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8879 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8880 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8881 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8882 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8883 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8884 retval = Internal_FadeOutChannel(channel, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8885 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8886 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8887 #endif |
0 | 8888 return retval; |
8889 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8890 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8891 ALint ALmixer_FadeOutSource(ALuint source, ALuint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8892 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8893 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8894 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8895 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8896 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8897 retval = Internal_FadeOutSource(source, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8898 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8899 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8900 #endif |
0 | 8901 return retval; |
8902 } | |
8903 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8904 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
|
8905 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8906 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8907 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8908 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8909 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8910 retval = Internal_FadeChannel(channel, ticks, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8911 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8912 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8913 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8914 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8915 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8916 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8917 ALint 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
|
8918 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8919 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8920 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8921 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8922 #endif |
0 | 8923 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
|
8924 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8925 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8926 #endif |
0 | 8927 return retval; |
8928 } | |
8929 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8930 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8931 ALboolean ALmixer_SetVolumeChannel(ALint channel, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8932 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8933 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8934 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8935 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8936 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8937 retval = Internal_SetVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8938 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8939 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8940 #endif |
0 | 8941 return retval; |
8942 } | |
8943 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8944 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
|
8945 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8946 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8947 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8948 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8949 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8950 retval = Internal_SetVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8951 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8952 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8953 #endif |
0 | 8954 return retval; |
8955 } | |
8956 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8957 ALfloat ALmixer_GetVolumeChannel(ALint channel) |
0 | 8958 { |
8959 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8960 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8961 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8962 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8963 retval = Internal_GetVolumeChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8964 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8965 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8966 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8967 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8968 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8969 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8970 ALfloat ALmixer_GetVolumeSource(ALuint source) |
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 ALfloat retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8973 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8974 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8975 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8976 retval = Internal_GetVolumeSource(source); |
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8979 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8980 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8981 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8982 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8983 ALboolean ALmixer_SetMaxVolumeChannel(ALint channel, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8984 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8985 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8986 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8987 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8988 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8989 retval = Internal_SetMaxVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8990 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8991 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8992 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8993 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8994 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8995 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8996 ALboolean ALmixer_SetMaxVolumeSource(ALuint source, ALfloat volume) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8997 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8998 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8999 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9000 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9001 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9002 retval = Internal_SetMaxVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9003 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9004 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9005 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9006 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9007 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9008 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9009 ALfloat ALmixer_GetMaxVolumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9010 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9011 ALfloat retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9012 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9013 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9014 #endif |
0 | 9015 retval = Internal_GetMaxVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9016 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9017 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9018 #endif |
0 | 9019 return retval; |
9020 } | |
9021 | |
9022 ALfloat ALmixer_GetMaxVolumeSource(ALuint source) | |
9023 { | |
9024 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9025 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9026 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9027 #endif |
0 | 9028 retval = Internal_GetMaxVolumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9029 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9030 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9031 #endif |
0 | 9032 return retval; |
9033 } | |
9034 | |
9035 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9036 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
|
9037 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9038 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9039 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9040 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9041 #endif |
0 | 9042 retval = Internal_SetMinVolumeChannel(channel, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9043 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9044 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9045 #endif |
0 | 9046 return retval; |
9047 } | |
9048 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9049 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
|
9050 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9051 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9052 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9053 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9054 #endif |
0 | 9055 retval = Internal_SetMinVolumeSource(source, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9056 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9057 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9058 #endif |
0 | 9059 return retval; |
9060 } | |
9061 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9062 ALfloat ALmixer_GetMinVolumeChannel(ALint channel) |
0 | 9063 { |
9064 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9065 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9066 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9067 #endif |
0 | 9068 retval = Internal_GetMinVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9069 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9070 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9071 #endif |
0 | 9072 return retval; |
9073 } | |
9074 | |
9075 ALfloat ALmixer_GetMinVolumeSource(ALuint source) | |
9076 { | |
9077 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9078 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9079 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9080 #endif |
0 | 9081 retval = Internal_GetMinVolumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9082 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9083 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9084 #endif |
0 | 9085 return retval; |
9086 } | |
9087 | |
9088 | |
9089 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9090 ALboolean ALmixer_SetMasterVolume(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; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9093 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9094 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9095 #endif |
0 | 9096 retval = Internal_SetMasterVolume(volume); |
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_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9099 #endif |
0 | 9100 return retval; |
9101 } | |
9102 | |
9103 ALfloat ALmixer_GetMasterVolume() | |
9104 { | |
9105 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9106 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9107 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9108 #endif |
0 | 9109 retval = Internal_GetMasterVolume(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9110 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9111 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9112 #endif |
0 | 9113 return retval; |
9114 } | |
9115 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9116 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
|
9117 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9118 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9119 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9120 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9121 #endif |
0 | 9122 retval = Internal_ExpireChannel(channel, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9123 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9124 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9125 #endif |
0 | 9126 return retval; |
9127 } | |
9128 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9129 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
|
9130 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9131 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9132 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9133 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9134 #endif |
0 | 9135 retval = Internal_ExpireSource(source, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9136 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9137 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9138 #endif |
0 | 9139 return retval; |
9140 } | |
9141 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9142 ALint ALmixer_IsActiveChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9143 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9144 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9145 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9146 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9147 #endif |
0 | 9148 retval = Internal_QueryChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9149 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9150 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9151 #endif |
0 | 9152 return retval; |
9153 } | |
9154 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9155 ALint ALmixer_IsActiveSource(ALuint source) |
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 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9158 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9159 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9160 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9161 retval = Internal_QuerySource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9162 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9163 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9164 #endif |
0 | 9165 return retval; |
9166 } | |
9167 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9168 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9169 ALint ALmixer_IsPlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9170 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9171 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9172 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9173 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9174 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9175 retval = Internal_PlayingChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9176 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9177 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9178 #endif |
0 | 9179 return retval; |
9180 } | |
9181 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9182 ALint ALmixer_IsPlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9183 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9184 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9185 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9186 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9187 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9188 retval = Internal_PlayingSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9189 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9190 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9191 #endif |
0 | 9192 return retval; |
9193 } | |
9194 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9195 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9196 ALint ALmixer_IsPausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9197 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9198 ALint retval; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9202 retval = Internal_PausedChannel(channel); |
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 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9209 ALint ALmixer_IsPausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9210 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9211 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9212 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9213 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9214 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9215 retval = Internal_PausedSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9216 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9217 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9218 #endif |
0 | 9219 return retval; |
9220 } | |
9221 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9222 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9223 ALuint ALmixer_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9224 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9225 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9226 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9227 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9228 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9229 retval = Internal_CountAllFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9230 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9231 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9232 #endif |
0 | 9233 return retval; |
9234 } | |
9235 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9236 ALuint ALmixer_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9237 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9238 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9239 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9240 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9241 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9242 retval = Internal_CountUnreservedFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9243 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9244 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9245 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9246 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9247 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9248 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9249 ALuint ALmixer_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9250 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9251 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9252 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9253 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9254 #endif |
0 | 9255 retval = Internal_CountAllUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9256 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9257 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9258 #endif |
0 | 9259 return retval; |
9260 } | |
9261 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9262 ALuint ALmixer_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9263 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9264 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9265 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9266 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9267 #endif |
0 | 9268 retval = Internal_CountUnreservedUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9269 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9270 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9271 #endif |
0 | 9272 return retval; |
9273 } | |
9274 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9275 ALboolean ALmixer_IsPredecoded(ALmixer_Data* data) |
1 | 9276 { |
9277 if(NULL == data) | |
9278 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9279 return AL_FALSE; |
1 | 9280 } |
9281 return data->decoded_all; | |
9282 } | |
9283 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9284 ALboolean ALmixer_CompiledWithThreadBackend() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9285 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9286 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9287 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9288 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9289 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9290 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9291 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9292 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9293 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9294 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9295 |