Mercurial > almixer_isolated
annotate ALmixer.c @ 22:58f03008ea05
- Added Seek APIs
- Added new API for interruption handling like on iOS
- Made support for ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING an opt-in compile define because iOS kept reporting it supported this even though it didn't and some people reported that on Mac, this sometimes failed (but I couldn't reproduce).
- Made number of sources unsigned
- Some minor 64-bit clean ups
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Fri, 24 Dec 2010 03:23:02 -0800 |
parents | 038baa026db3 |
children | e085cbc573cf |
rev | line source |
---|---|
0 | 1 |
2 /* Here's an OpenAL implementation modeled after | |
3 * the SDL_SoundMixer which was built ontop of SDL_Mixer | |
4 * and SDL_Sound. | |
5 * Eric Wing | |
6 */ | |
7 | |
3
a929285e1db0
Added CMake build system.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
2
diff
changeset
|
8 #include "ALmixer.h" |
0 | 9 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
10 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
11 #include "ALmixer_RWops.h" |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
12 #include "SoundDecoder.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
13 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
14 #include "SDL_sound.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
15 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
16 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
17 #include "al.h" /* OpenAL */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
18 #include "alc.h" /* For creating OpenAL contexts */ |
0 | 19 |
1 | 20 #ifdef __APPLE__ |
21 /* For performance things like ALC_CONVERT_DATA_UPON_LOADING */ | |
22 /* Note: ALC_CONVERT_DATA_UPON_LOADING used to be in the alc.h header. | |
23 * But in the Tiger OpenAL 1.1 release (10.4.7 and Xcode 2.4), the | |
24 * define was moved to a new header file and renamed to | |
25 * ALC_MAC_OSX_CONVERT_DATA_UPON_LOADING. | |
26 */ | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
27 #include <TargetConditionals.h> |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
28 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
29 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
30 #include <AudioToolbox/AudioToolbox.h> |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
31 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
32 #include <OpenAL/MacOSX_OALExtensions.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
33 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
34 */ |
1 | 35 #endif |
36 | |
0 | 37 /* For malloc, bsearch, qsort */ |
38 #include <stdlib.h> | |
39 | |
40 /* For memcpy */ | |
41 #include <string.h> | |
42 | |
43 #if 0 | |
44 /* for toupper */ | |
45 #include <ctype.h> | |
46 /* for strrchr */ | |
47 #include <string.h> | |
48 #endif | |
49 | |
50 /* Currently used in the output debug functions */ | |
51 #include <stdio.h> | |
52 | |
53 /* My own CircularQueue implementation needed | |
54 * to work around the Nvidia problem of the | |
55 * lack of a buffer query. | |
56 */ | |
57 #include "CircularQueue.h" | |
58 | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
59 /* SDL_sound keeps a private linked list of sounds which get auto-deleted |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
60 * on Sound_Quit. This might actually create some leaks for me in certain |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
61 * usage patterns. To be safe, I should do the same. |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
62 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
63 #include "LinkedList.h" |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
64 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
65 #ifdef ENABLE_ALMIXER_THREADS |
0 | 66 /* Needed for the Mutex locks (and threads if enabled) */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
67 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
68 #include "SimpleMutex.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
69 #include "SimpleThread.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
70 typedef struct SimpleMutex SDL_mutex; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
71 typedef struct SimpleThread SDL_Thread; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
72 #define SDL_CreateMutex SimpleMutex_CreateMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
73 #define SDL_DestroyMutex SimpleMutex_DestroyMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
74 #define SDL_LockMutex SimpleMutex_LockMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
75 #define SDL_UnlockMutex SimpleMutex_UnlockMutex |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
76 #define SDL_CreateThread SimpleThread_CreateThread |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
77 #define SDL_WaitThread SimpleThread_WaitThread |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
78 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
79 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
80 #include "SDL_thread.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
81 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
82 #endif |
0 | 83 |
84 /* Because of the API differences between the Loki | |
85 * and Creative distributions, we need to know which | |
86 * version to use. The LOKI distribution currently | |
87 * has AL_BYTE_LOKI defined in altypes.h which | |
88 * I will use as a flag to identify the distributions. | |
89 * If this is ever removed, I might revert back to the | |
90 * if defined(_WIN32) or defined(__APPLE__) test to | |
91 * identify the Creative dist. | |
92 * I'm not sure if or how the Nvidia distribution differs | |
93 * from the Creative distribution. So for | |
94 * now, the Nvidia distribution gets lumped with the | |
95 * Creative dist and I hope nothing will break. | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
96 * My alGetString may be the most vulnerable. |
0 | 97 */ |
98 #ifdef AL_BYTE_LOKI | |
99 #define USING_LOKI_AL_DIST | |
100 /* This is a short term fix to get around the | |
101 * queuing problem with non-power of two buffer sizes. | |
102 * Hopefully the maintainers will fix this before | |
103 * we're ready to ship. | |
104 */ | |
105 #define ENABLE_LOKI_QUEUE_FIX_HACK | |
106 | |
107 /* The AL_GAIN in the Loki dist doesn't seem to do | |
108 * what I want/expect it to do. I want to use it for | |
109 * Fading, but it seems to work like an off/on switch. | |
110 * 0 = off, >0 = on. | |
111 * The AL_GAIN_LINEAR_LOKI switch seems to do what | |
112 * I want, so I'll redefine it here so the code is consistent | |
113 */ | |
114 /* Update: I've changed the source volume implementations | |
115 * to use AL_MAX_GAIN, so I don't think I need this block | |
116 * of code anymore. The listener uses AL_GAIN, but I | |
117 * hope they got this one right since there isn't a AL_MAX_GAIN | |
118 * for the listener. | |
119 */ | |
120 /* | |
121 #undef AL_GAIN | |
122 #include "alexttypes.h" | |
123 #define AL_GAIN AL_GAIN_LINEAR_LOKI | |
124 */ | |
125 #else | |
126 /* Might need to run other tests to figure out the DIST */ | |
127 /* I've been told that Nvidia doesn't define constants | |
128 * in the headers like Creative. Instead of | |
129 * #define AL_REFERENCE_DISTANCE 0x1020, | |
130 * Nvidia prefers you query OpenAL for a value. | |
131 * int AL_REFERENCE_DISTANCE = alGetEnumValue(ALubyte*)"AL_REFERNECE_DISTANCE"); | |
132 * So I'm assuming this means the Nvidia lacks this value. | |
133 * If this is the case, | |
134 * I guess we can use it to identify the Nvidia dist | |
135 */ | |
136 #ifdef AL_REFERENCE_DISTANCE | |
137 #define USING_CREATIVE_AL_DIST | |
138 #else | |
139 #define USING_NVIDIA_AL_DIST | |
140 #endif | |
141 #endif | |
142 | |
143 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
144 /* Need memset to zero out data */ | |
145 #include <string.h> | |
146 #endif | |
147 | |
148 | |
149 /* Seek issues for predecoded samples: | |
150 * The problem is that OpenAL makes us copy an | |
151 * entire buffer if we want to use it. This | |
152 * means we potentially have two copies of the | |
153 * same data. For predecoded data, this can be a | |
154 * large amount of memory. However, for seek | |
155 * support, I need to be able to get access to | |
156 * the original data so I can set byte positions. | |
157 * The following flags let you disable seek support | |
158 * if you don't want the memory hit, keep everything, | |
159 * or let you try to minimize the memory wasted by | |
160 * fetching it from the OpenAL buffer if needed | |
161 * and making a copy of it. | |
162 * Update: I don't think I need this flag anymore. I've made the | |
163 * effects of this user customizable by the access_data flag on load. | |
164 * If set to true, then seek and data callbacks work, with the | |
165 * cost of more memory and possibly CPU for copying the data through | |
166 * the callbacks. If false, then the extra memory is freed, but | |
167 * you don't get the features. | |
168 */ | |
169 /* | |
170 #define DISABLE_PREDECODED_SEEK | |
171 */ | |
172 /* Problem: Even though alGetBufferi(., AL_DATA, .) | |
173 * is in the Creative Programmer's reference, | |
174 * it actually isn't in the dist. (Invalid enum | |
175 * in Creative, can't compile in Loki.) | |
176 * So we have to keep it disabled | |
177 */ | |
178 #define DISABLE_SEEK_MEMORY_OPTIMIZATION | |
179 | |
180 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION | |
181 /* Needed for memcpy */ | |
182 #include <string.h> | |
183 #endif | |
184 | |
185 /* Old way of doing things: | |
186 #if defined(_WIN32) || defined(__APPLE__) | |
187 #define USING_CREATIVE_AL_DIST | |
188 #else | |
189 #define USING_LOKI_AL_DIST | |
190 #endif | |
191 */ | |
192 | |
193 /************ REMOVE ME (Don't need anymore) ********/ | |
194 #if 0 | |
195 /* Let's get fancy and see if triple buffering | |
196 * does anything good for us | |
197 * Must be 2 or more or things will probably break | |
198 */ | |
199 #define NUMBER_OF_QUEUE_BUFFERS 5 | |
200 /* This is the number of buffers that are queued up | |
201 * when play first starts up. This should be at least 1 | |
202 * and no more than NUMBER_OF_QUEUE_BUFFERS | |
203 */ | |
204 #define NUMBER_OF_START_UP_BUFFERS 2 | |
205 #endif | |
206 /************ END REMOVE ME (Don't need anymore) ********/ | |
207 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
208 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
209 #include "tErrorLib.h" |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
210 static TErrorPool* s_ALmixerErrorPool = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
211 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
212 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
213 static ALboolean ALmixer_Initialized = 0; |
0 | 214 /* This should be set correctly by Init */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
215 static ALuint ALmixer_Frequency_global = ALMIXER_DEFAULT_FREQUENCY; |
0 | 216 |
217 /* Will be initialized in Init */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
218 static ALint Number_of_Channels_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
219 static ALint Number_of_Reserve_Channels_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
220 static ALuint Is_Playing_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
221 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
222 #ifdef ENABLE_ALMIXER_THREADS |
0 | 223 /* This is for a simple lock system. It is not meant to be good, |
224 * but just sufficient to minimize/avoid threading issues | |
225 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
226 static SDL_mutex* s_simpleLock; |
0 | 227 static SDL_Thread* Stream_Thread_global = NULL; |
228 #endif | |
229 | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
230 static LinkedList* s_listOfALmixerData = NULL; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
231 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
232 /* Special stuff for iOS interruption handling */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
233 static ALCcontext* s_interruptionContext = NULL; |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
234 |
0 | 235 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
236 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
237 static ALvoid Internal_alcMacOSXMixerOutputRate(const ALdouble sample_rate) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
238 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
239 static void (*alcMacOSXMixerOutputRateProcPtr)(const ALdouble) = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
240 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
241 if(NULL == alcMacOSXMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
242 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
243 alcMacOSXMixerOutputRateProcPtr = alGetProcAddress((const ALCchar*) "alcMacOSXMixerOutputRate"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
244 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
245 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
246 if(NULL != alcMacOSXMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
247 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
248 alcMacOSXMixerOutputRateProcPtr(sample_rate); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
249 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
250 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
251 return; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
252 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
253 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
254 ALdouble Internal_alcMacOSXGetMixerOutputRate() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
255 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
256 static ALdouble (*alcMacOSXGetMixerOutputRateProcPtr)(void) = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
257 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
258 if(NULL == alcMacOSXGetMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
259 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
260 alcMacOSXGetMixerOutputRateProcPtr = alGetProcAddress((const ALCchar*) "alcMacOSXGetMixerOutputRate"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
261 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
262 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
263 if(NULL != alcMacOSXGetMixerOutputRateProcPtr) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
264 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
265 return alcMacOSXGetMixerOutputRateProcPtr(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
266 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
267 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
268 return 0.0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
269 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
270 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
271 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
272 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
273 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
274 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
275 #include <QuartzCore/QuartzCore.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
276 #include <unistd.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
277 static CFTimeInterval s_ticksBaseTime = 0.0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
278 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
279 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
280 #define WIN32_LEAN_AND_MEAN |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
281 #include <windows.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
282 #include <winbase.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
283 LARGE_INTEGER s_hiResTicksPerSecond; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
284 double s_hiResSecondsPerTick; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
285 LARGE_INTEGER s_ticksBaseTime; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
286 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
287 #include <unistd.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
288 #include <time.h> |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
289 static struct timespec s_ticksBaseTime; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
290 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
291 static void ALmixer_InitTime() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
292 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
293 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
294 s_ticksBaseTime = CACurrentMediaTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
295 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
296 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
297 LARGE_INTEGER hi_res_ticks_per_second; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
298 if(TRUE == QueryPerformanceFrequency(&hi_res_ticks_per_second)) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
299 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
300 QueryPerformanceCounter(&s_ticksBaseTime); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
301 s_hiResSecondsPerTick = 1.0 / hi_res_ticks_per_second; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
302 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
303 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
304 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
305 ALMixer_SetError("Windows error: High resolution clock failed."); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
306 fprintf(stderr, "Windows error: High resolution clock failed. Audio will not work correctly.\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
307 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
308 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
309 /* clock_gettime is POSIX.1-2001 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
310 clock_gettime(CLOCK_MONOTONIC, &s_ticksBaseTime); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
311 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
312 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
313 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
314 static ALuint ALmixer_GetTicks() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
315 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
316 #if defined(__APPLE__) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
317 return (ALuint)((CACurrentMediaTime()-s_ticksBaseTime)*1000.0); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
318 #elif defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
319 LARGE_INTEGER current_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
320 QueryPerformanceCounter(¤t_time); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
321 return (ALuint)((current_time.QuadPart - s_ticksBaseTime.QuadPart) * 1000 * s_hiResSecondsPerTick); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
322 #else /* assuming POSIX */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
323 /* clock_gettime is POSIX.1-2001 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
324 struct timespec current_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
325 clock_gettime(CLOCK_MONOTONIC, ¤t_time); |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
326 return (ALuint)((current_time.tv_sec - s_ticksBaseTime.tv_sec)*1000.0 + (current_time.tv_nsec - s_ticksBaseTime.tv_nsec) / 1000000); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
327 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
328 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
329 static void ALmixer_Delay(ALuint milliseconds_delay) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
330 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
331 #if defined(_WIN32) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
332 Sleep(milliseconds_delay); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
333 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
334 usleep(milliseconds_delay); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
335 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
336 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
337 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
338 #include "SDL.h" /* For SDL_GetTicks(), SDL_Delay */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
339 #define ALmixer_GetTicks SDL_GetTicks |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
340 #define ALmixer_Delay SDL_Delay |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
341 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
342 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
343 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
344 |
0 | 345 /* If ENABLE_PARANOID_SIGNEDNESS_CHECK is used, |
346 * these values will be reset on Init() | |
347 * Consider these values Read-Only. | |
348 */ | |
349 | |
350 #define ALMIXER_SIGNED_VALUE 127 | |
351 #define ALMIXER_UNSIGNED_VALUE 255 | |
352 | |
353 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
354 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
|
355 static ALushort SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; |
0 | 356 #else |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
357 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
|
358 static const ALushort SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; |
0 | 359 #endif |
360 | |
1 | 361 |
362 /* This can be private instead of being in the header now that I moved | |
363 * ALmixer_Data inside here. | |
364 */ | |
365 typedef struct ALmixer_Buffer_Map ALmixer_Buffer_Map; | |
366 | |
367 | |
368 struct ALmixer_Data | |
369 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
370 ALboolean decoded_all; /* dictates different behaviors */ |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
371 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
|
372 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
373 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
|
374 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
|
375 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
376 ALuint total_bytes; /* For predecoded */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
377 ALuint loaded_bytes; /* For predecoded (for seek) */ |
1 | 378 |
379 Sound_Sample* sample; /* SDL_Sound provides the data */ | |
380 ALuint* buffer; /* array of OpenAL buffers (at least 1 for predecoded) */ | |
381 | |
382 /* Needed for streamed buffers */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
383 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
|
384 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
|
385 ALuint num_buffers_in_use; /* number of buffers in use */ |
1 | 386 |
387 /* This stuff is for streamed buffers that require data access */ | |
388 ALmixer_Buffer_Map* buffer_map_list; /* translate ALbuffer to index | |
389 and holds pointer to copy of data for | |
390 data access */ | |
391 ALuint current_buffer; /* The current playing buffer */ | |
392 | |
393 /* Nvidia distribution refuses to recognize a simple buffer query command | |
394 * unlike all other distributions. It's forcing me to redo the code | |
395 * to accomodate this Nvidia flaw by making me maintain a "best guess" | |
396 * copy of what I think the buffer queue state looks like. | |
397 * A circular queue would a helpful data structure for this task, | |
398 * but I wanted to avoid making an additional header requirement, | |
399 * so I'm making it a void* | |
400 */ | |
401 void* circular_buffer_queue; | |
402 | |
403 | |
404 }; | |
405 | |
0 | 406 static struct ALmixer_Channel |
407 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
408 ALboolean channel_in_use; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
409 ALboolean callback_update; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
410 ALboolean needs_stream; /* For streaming determination */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
411 ALboolean halted; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
412 ALboolean paused; |
0 | 413 ALuint alsource; |
414 ALmixer_Data* almixer_data; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
415 ALint loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
416 ALint expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
417 ALuint start_time; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
418 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
419 ALboolean fade_enabled; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
420 ALuint fade_expire_ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
421 ALuint fade_start_time; |
0 | 422 ALfloat fade_inv_time; |
423 ALfloat fade_start_volume; | |
424 ALfloat fade_end_volume; | |
425 ALfloat max_volume; | |
426 ALfloat min_volume; | |
427 | |
428 /* Do we need other flags? | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
429 ALbyte *samples; |
0 | 430 int volume; |
431 int looping; | |
432 int tag; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
433 ALuint expire; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
434 ALuint start_time; |
0 | 435 Mix_Fading fading; |
436 int fade_volume; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
437 ALuint fade_length; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
438 ALuint ticks_fade; |
0 | 439 effect_info *effects; |
440 */ | |
441 } *ALmixer_Channel_List = NULL; | |
442 | |
1 | 443 struct ALmixer_Buffer_Map |
444 { | |
445 ALuint albuffer; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
446 ALint index; /* might not need */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
447 ALbyte* data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
448 ALuint num_bytes; |
1 | 449 }; |
450 | |
0 | 451 /* This will be used to find a channel if the user supplies a source */ |
452 typedef struct Source_Map | |
453 { | |
454 ALuint source; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
455 ALint channel; |
0 | 456 } Source_Map; |
457 /* Keep an array of all sources with their associated channel */ | |
458 static Source_Map* Source_Map_List; | |
459 | |
460 static int Compare_Source_Map(const void* a, const void* b) | |
461 { | |
462 return ( ((Source_Map*)a)->source - ((Source_Map*)b)->source ); | |
463 } | |
464 | |
465 /* Sort by channel instead of source */ | |
466 static int Compare_Source_Map_by_channel(const void* a, const void* b) | |
467 { | |
468 return ( ((Source_Map*)a)->channel - ((Source_Map*)b)->channel ); | |
469 } | |
470 | |
471 /* Compare by albuffer */ | |
472 static int Compare_Buffer_Map(const void* a, const void* b) | |
473 { | |
1 | 474 return ( ((ALmixer_Buffer_Map*)a)->albuffer - ((ALmixer_Buffer_Map*)b)->albuffer ); |
0 | 475 } |
476 | |
477 /* This is for the user defined callback via | |
478 * ALmixer_ChannelFinished() | |
479 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
480 static void (*Channel_Done_Callback)(ALint which_channel, ALuint al_source, ALmixer_Data* almixer_data, ALboolean finished_naturally, void* user_data) = NULL; |
0 | 481 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
|
482 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 | 483 static void* Channel_Data_Callback_Userdata = NULL; |
0 | 484 |
485 | |
486 static void PrintQueueStatus(ALuint source) | |
487 { | |
488 ALint buffers_queued = 0; | |
489 ALint buffers_processed = 0; | |
490 ALenum error; | |
491 | |
492 /* Get the number of buffers still queued */ | |
493 alGetSourcei( | |
494 source, | |
495 AL_BUFFERS_QUEUED, | |
496 &buffers_queued | |
497 ); | |
498 | |
499 if((error = alGetError()) != AL_NO_ERROR) | |
500 { | |
501 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
|
502 alGetString(error)); |
0 | 503 } |
504 /* Get the number of buffers processed | |
505 * so we know if we need to refill | |
506 */ | |
507 alGetSourcei( | |
508 source, | |
509 AL_BUFFERS_PROCESSED, | |
510 &buffers_processed | |
511 ); | |
512 if((error = alGetError()) != AL_NO_ERROR) | |
513 { | |
514 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
|
515 alGetString(error)); |
0 | 516 } |
517 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
518 /* |
0 | 519 fprintf(stderr, "For source: %d, buffers_queued=%d, buffers_processed=%d\n", |
520 source, | |
521 buffers_queued, | |
522 buffers_processed); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
523 */ |
0 | 524 } |
525 | |
526 | |
527 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
528 static void Init_Channel(ALint channel) |
0 | 529 { |
530 ALmixer_Channel_List[channel].channel_in_use = 0; | |
531 ALmixer_Channel_List[channel].callback_update = 0; | |
532 ALmixer_Channel_List[channel].needs_stream = 0; | |
533 ALmixer_Channel_List[channel].paused = 0; | |
534 ALmixer_Channel_List[channel].halted = 0; | |
535 ALmixer_Channel_List[channel].loops = 0; | |
536 | |
537 ALmixer_Channel_List[channel].expire_ticks = 0; | |
538 ALmixer_Channel_List[channel].start_time = 0; | |
539 | |
540 ALmixer_Channel_List[channel].fade_enabled = 0; | |
541 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
542 ALmixer_Channel_List[channel].fade_start_time = 0; | |
543 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
544 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
545 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
546 ALmixer_Channel_List[channel].max_volume = 1.0f; | |
547 ALmixer_Channel_List[channel].min_volume = 0.0f; | |
548 | |
549 ALmixer_Channel_List[channel].almixer_data = NULL; | |
550 } | |
551 /* Quick helper function to clean up a channel | |
552 * after it's done playing */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
553 static void Clean_Channel(ALint channel) |
0 | 554 { |
555 ALenum error; | |
556 ALmixer_Channel_List[channel].channel_in_use = 0; | |
557 ALmixer_Channel_List[channel].callback_update = 0; | |
558 ALmixer_Channel_List[channel].needs_stream = 0; | |
559 ALmixer_Channel_List[channel].paused = 0; | |
560 ALmixer_Channel_List[channel].halted = 0; | |
561 ALmixer_Channel_List[channel].loops = 0; | |
562 | |
563 | |
564 ALmixer_Channel_List[channel].expire_ticks = 0; | |
565 ALmixer_Channel_List[channel].start_time = 0; | |
566 | |
567 ALmixer_Channel_List[channel].fade_enabled = 0; | |
568 ALmixer_Channel_List[channel].fade_expire_ticks = 0; | |
569 ALmixer_Channel_List[channel].fade_start_time = 0; | |
570 ALmixer_Channel_List[channel].fade_inv_time = 0.0f; | |
571 ALmixer_Channel_List[channel].fade_start_volume = 0.0f; | |
572 ALmixer_Channel_List[channel].fade_end_volume = 0.0f; | |
573 | |
574 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MAX_GAIN, | |
575 ALmixer_Channel_List[channel].max_volume); | |
576 | |
577 if((error = alGetError()) != AL_NO_ERROR) | |
578 { | |
579 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
|
580 alGetString(error)); |
0 | 581 } |
582 | |
583 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MIN_GAIN, | |
584 ALmixer_Channel_List[channel].min_volume); | |
585 if((error = alGetError()) != AL_NO_ERROR) | |
586 { | |
587 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
|
588 alGetString(error)); |
0 | 589 } |
590 | |
591 if(ALmixer_Channel_List[channel].almixer_data != NULL) | |
592 { | |
593 if(ALmixer_Channel_List[channel].almixer_data->in_use > 0) | |
594 { | |
595 ALmixer_Channel_List[channel].almixer_data->in_use--; | |
596 } | |
597 } | |
598 /* Needed to determine if rewind is needed, can't reset */ | |
599 /* | |
600 ALmixer_Channel_List[channel].almixer_data->eof = 0; | |
601 */ | |
602 | |
603 ALmixer_Channel_List[channel].almixer_data = NULL; | |
604 } | |
605 | |
606 /* What shoud this return? | |
607 * 127 for signed, 255 for unsigned | |
608 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
609 static ALubyte GetSignednessValue(ALushort format) |
0 | 610 { |
611 switch(format) | |
612 { | |
613 case AUDIO_U8: | |
614 case AUDIO_U16LSB: | |
615 case AUDIO_U16MSB: | |
616 return ALMIXER_UNSIGNED_VALUE; | |
617 break; | |
618 case AUDIO_S8: | |
619 case AUDIO_S16LSB: | |
620 case AUDIO_S16MSB: | |
621 return ALMIXER_SIGNED_VALUE; | |
622 break; | |
623 default: | |
624 return 0; | |
625 } | |
626 return 0; | |
627 } | |
628 | |
629 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
630 static ALubyte GetBitDepth(ALushort format) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
631 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
632 ALubyte bit_depth = 16; |
0 | 633 |
634 switch(format) | |
635 { | |
636 case AUDIO_U8: | |
637 case AUDIO_S8: | |
638 bit_depth = 8; | |
639 break; | |
640 | |
641 case AUDIO_U16LSB: | |
642 /* | |
643 case AUDIO_U16: | |
644 */ | |
645 case AUDIO_S16LSB: | |
646 /* | |
647 case AUDIO_S16: | |
648 */ | |
649 case AUDIO_U16MSB: | |
650 case AUDIO_S16MSB: | |
651 /* | |
652 case AUDIO_U16SYS: | |
653 case AUDIO_S16SYS: | |
654 */ | |
655 bit_depth = 16; | |
656 break; | |
657 default: | |
658 bit_depth = 0; | |
659 } | |
660 return bit_depth; | |
661 } | |
662 | |
663 /* Need to translate between SDL/SDL_Sound audiospec | |
664 * and OpenAL conventions */ | |
665 static ALenum TranslateFormat(Sound_AudioInfo* info) | |
666 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
667 ALubyte bit_depth; |
0 | 668 |
669 bit_depth = GetBitDepth(info->format); | |
670 if(0 == bit_depth) | |
671 { | |
672 fprintf(stderr, "Warning: Unknown bit depth. Setting to 16\n"); | |
673 bit_depth = 16; | |
674 } | |
675 | |
676 if(2 == info->channels) | |
677 { | |
678 if(16 == bit_depth) | |
679 { | |
680 return AL_FORMAT_STEREO16; | |
681 } | |
682 else | |
683 { | |
684 return AL_FORMAT_STEREO8; | |
685 } | |
686 } | |
687 else | |
688 { | |
689 if(16 == bit_depth) | |
690 { | |
691 return AL_FORMAT_MONO16; | |
692 } | |
693 else | |
694 { | |
695 return AL_FORMAT_MONO8; | |
696 } | |
697 } | |
698 /* Make compiler happy. Shouldn't get here */ | |
699 return AL_FORMAT_STEREO16; | |
700 } | |
701 | |
1 | 702 |
703 /* This will compute the total playing time | |
704 * based upon the number of bytes and audio info. | |
705 * (In prinicple, it should compute the time for any given length) | |
706 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
707 static ALuint Compute_Total_Time_Decomposed(ALuint bytes_per_sample, ALuint frequency, ALubyte channels, size_t total_bytes) |
1 | 708 { |
709 double total_sec; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
710 ALuint total_msec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
711 ALuint bytes_per_sec; |
1 | 712 |
713 if(0 == total_bytes) | |
714 { | |
715 return 0; | |
716 } | |
717 /* To compute Bytes per second, do | |
718 * samples_per_sec * bytes_per_sample * number_of_channels | |
719 */ | |
720 bytes_per_sec = frequency * bytes_per_sample * channels; | |
721 | |
722 /* Now to get total time (sec), do | |
723 * total_bytes / bytes_per_sec | |
724 */ | |
725 total_sec = total_bytes / (double)bytes_per_sec; | |
726 | |
727 /* Now convert seconds to milliseconds | |
728 * Add .5 to the float to do rounding before the final cast | |
729 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
730 total_msec = (ALuint) ( (total_sec * 1000) + 0.5 ); |
1 | 731 /* |
732 fprintf(stderr, "freq=%d, bytes_per_sample=%d, channels=%d, total_msec=%d\n", frequency, bytes_per_sample, channels, total_msec); | |
733 */ | |
734 return total_msec; | |
735 } | |
736 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
737 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
|
738 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
739 ALuint bytes_per_sample; |
1 | 740 |
741 if(0 == total_bytes) | |
742 { | |
743 return 0; | |
744 } | |
745 /* 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
|
746 * 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
|
747 * 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
|
748 * 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
|
749 * 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
|
750 * 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
|
751 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
752 bytes_per_sample = (ALuint) ((info->format & 0xFF) / 8); |
1 | 753 |
754 return Compute_Total_Time_Decomposed(bytes_per_sample, info->rate, info->channels, total_bytes); | |
755 } /* End Compute_Total_Time */ | |
756 | |
757 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
758 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
|
759 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
760 double total_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
761 ALuint bytes_per_sec; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
762 size_t total_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
763 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
764 if(0 >= total_msec) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
765 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
766 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
767 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
768 /* To compute Bytes per second, do |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
769 * 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
|
770 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
771 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
|
772 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
773 /* convert milliseconds to seconds */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
774 total_sec = total_msec / 1000.0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
775 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
776 /* Now to get total bytes */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
777 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
|
778 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
779 /* 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
|
780 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
781 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
782 return total_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
783 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
784 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
785 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
|
786 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
787 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
788 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
789 if(0 >= total_msec) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
790 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
791 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
792 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
793 /* 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
|
794 * 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
|
795 * 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
|
796 * 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
|
797 * 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
|
798 * 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
|
799 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
800 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
|
801 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
802 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
|
803 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
804 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
805 /* 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
|
806 * 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
|
807 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
808 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
|
809 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
810 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
811 ALuint bytes_per_frame; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
812 size_t evenly_divisible_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
813 size_t remainder_frames; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
814 size_t return_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 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
|
817 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
818 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
|
819 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
820 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
|
821 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
822 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
|
823 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
|
824 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
825 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
|
826 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
827 /* 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
|
828 * 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
|
829 * 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
|
830 * 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
|
831 * 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
|
832 * 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
|
833 * 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
|
834 * 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
|
835 * 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
|
836 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
837 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
838 return_bytes += 64; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
839 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
840 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
841 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
|
842 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
843 return return_bytes; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
844 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
845 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
846 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
847 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
848 |
1 | 849 |
0 | 850 /**************** REMOVED ****************************/ |
851 /* This was removed because I originally thought | |
852 * OpenAL could return a pointer to the buffer data, | |
853 * but I was wrong. If something like that is ever | |
854 * implemented, then this might become useful. | |
855 */ | |
856 #if 0 | |
857 /* Reconstruct_Sound_Sample and Set_AudioInfo only | |
858 * are needed if the Seek memory optimization is | |
859 * used. Also, the Loki dist doesn't seem to support | |
860 * AL_DATA which I need for it. | |
861 */ | |
862 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION | |
863 | |
864 static void Set_AudioInfo(Sound_AudioInfo* info, ALint frequency, ALint bits, ALint channels) | |
865 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
866 info->rate = (ALuint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
867 info->channels = (ALubyte)channels; |
0 | 868 |
869 /* Not sure if it should be signed or unsigned. Hopefully | |
870 * that detail won't be needed. | |
871 */ | |
872 if(8 == bits) | |
873 { | |
874 info->format = AUDIO_U8; | |
875 } | |
876 else | |
877 { | |
878 info->format = AUDIO_U16SYS; | |
879 } | |
880 fprintf(stderr, "Audio info: freq=%d, chan=%d, format=%d\n", | |
881 info->rate, info->channels, info->format); | |
882 | |
883 } | |
884 | |
885 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
886 static ALint Reconstruct_Sound_Sample(ALmixer_Data* data) |
0 | 887 { |
888 ALenum error; | |
889 ALint* data_from_albuffer; | |
890 ALint freq; | |
891 ALint bits; | |
892 ALint channels; | |
893 ALint size; | |
894 | |
895 /* Create memory all initiallized to 0. */ | |
896 data->sample = (Sound_Sample*)calloc(1, sizeof(Sound_Sample)); | |
897 if(NULL == data->sample) | |
898 { | |
899 ALmixer_SetError("Out of memory for Sound_Sample"); | |
900 return -1; | |
901 } | |
902 | |
903 /* Clear errors */ | |
904 alGetError(); | |
905 | |
906 alGetBufferi(data->buffer[0], AL_FREQUENCY, &freq); | |
907 if((error = alGetError()) != AL_NO_ERROR) | |
908 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
909 ALmixer_SetError("alGetBufferi(AL_FREQUENCY): %s", alGetString(error) ); |
0 | 910 free(data->sample); |
911 data->sample = NULL; | |
912 return -1; | |
913 } | |
914 | |
915 alGetBufferi(data->buffer[0], AL_BITS, &bits); | |
916 if((error = alGetError()) != AL_NO_ERROR) | |
917 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
918 ALmixer_SetError("alGetBufferi(AL_BITS): %s", alGetString(error) ); |
0 | 919 free(data->sample); |
920 data->sample = NULL; | |
921 return -1; | |
922 } | |
923 | |
924 alGetBufferi(data->buffer[0], AL_CHANNELS, &channels); | |
925 if((error = alGetError()) != AL_NO_ERROR) | |
926 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
927 ALmixer_SetError("alGetBufferi(AL_CHANNELS): %s", alGetString(error) ); |
0 | 928 free(data->sample); |
929 data->sample = NULL; | |
930 return -1; | |
931 } | |
932 | |
933 alGetBufferi(data->buffer[0], AL_SIZE, &size); | |
934 if((error = alGetError()) != AL_NO_ERROR) | |
935 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
936 ALmixer_SetError("alGetBufferi(AL_SIZE): %s", alGetString(error) ); |
0 | 937 free(data->sample); |
938 data->sample = NULL; | |
939 return -1; | |
940 } | |
941 | |
942 alGetBufferi(data->buffer[0], AL_DATA, data_from_albuffer); | |
943 if((error = alGetError()) != AL_NO_ERROR) | |
944 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
945 ALmixer_SetError("alGetBufferi(AL_DATA): %s", alGetString(error) ); |
0 | 946 free(data->sample); |
947 data->sample = NULL; | |
948 return -1; | |
949 } | |
950 | |
951 if(size <= 0) | |
952 { | |
953 ALmixer_SetError("No data in al buffer"); | |
954 free(data->sample); | |
955 data->sample = NULL; | |
956 return -1; | |
957 } | |
958 | |
959 /* Now that we have all the attributes, we need to | |
960 * allocate memory for the buffer and reconstruct | |
961 * the AudioInfo attributes. | |
962 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
963 data->sample->buffer = malloc(size*sizeof(ALbyte)); |
0 | 964 if(NULL == data->sample->buffer) |
965 { | |
966 ALmixer_SetError("Out of memory for sample->buffer"); | |
967 free(data->sample); | |
968 data->sample = NULL; | |
969 return -1; | |
970 } | |
971 | |
972 memcpy(data->sample->buffer, data_from_albuffer, size); | |
973 data->sample->buffer_size = size; | |
974 | |
975 /* Fill up the Sound_AudioInfo structures */ | |
976 Set_AudioInfo(&data->sample->desired, freq, bits, channels); | |
977 Set_AudioInfo(&data->sample->actual, freq, bits, channels); | |
978 | |
979 return 0; | |
980 } | |
981 | |
982 #endif /* End DISABLE_SEEK_MEMORY_OPTIMIZATION */ | |
983 #endif | |
984 /*************** END REMOVED *************************/ | |
985 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
986 static void Invoke_Channel_Done_Callback(ALint which_channel, ALboolean did_finish_naturally) |
0 | 987 { |
988 if(NULL == Channel_Done_Callback) | |
989 { | |
990 return; | |
991 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
992 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
|
993 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
994 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
995 static ALint LookUpBuffer(ALuint buffer, ALmixer_Buffer_Map* buffer_map_list, ALuint num_items_in_list) |
0 | 996 { |
997 /* Only the first value is used for the key */ | |
1 | 998 ALmixer_Buffer_Map key = { 0, 0, NULL, 0 }; |
999 ALmixer_Buffer_Map* found_item = NULL; | |
0 | 1000 key.albuffer = buffer; |
1001 | |
1002 /* Use the ANSI C binary search feature (yea!) */ | |
1 | 1003 found_item = (ALmixer_Buffer_Map*)bsearch(&key, buffer_map_list, num_items_in_list, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 1004 if(NULL == found_item) |
1005 { | |
1006 ALmixer_SetError("Can't find buffer"); | |
1007 return -1; | |
1008 } | |
1009 return found_item->index; | |
1010 } | |
1011 | |
1012 | |
1013 /* FIXME: Need to pass back additional info to be useful. | |
1014 * Bit rate, stereo/mono (num chans), time in msec? | |
1015 * Precoded/streamed flag so user can plan for future data? | |
1016 */ | |
1 | 1017 /* |
1018 * channels: 1 for mono, 2 for stereo | |
1019 * | |
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_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
|
1022 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1023 ALboolean is_unsigned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1024 ALubyte bits_per_sample = GetBitDepth(format); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1025 ALuint bytes_per_sample; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1026 ALuint length_in_msec; |
1 | 1027 |
1028 if(GetSignednessValue(format) == ALMIXER_UNSIGNED_VALUE) | |
1029 { | |
1030 is_unsigned = 1; | |
1031 } | |
1032 else | |
1033 { | |
1034 is_unsigned = 0; | |
1035 } | |
1036 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1037 bytes_per_sample = (ALuint) (bits_per_sample / 8); |
1 | 1038 |
1039 length_in_msec = Compute_Total_Time_Decomposed(bytes_per_sample, frequency, channels, num_bytes); | |
1040 | |
0 | 1041 /* |
1042 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); | |
1043 */ | |
1044 if(NULL == Channel_Data_Callback) | |
1045 { | |
1046 return; | |
1047 } | |
1 | 1048 /* |
1049 * Channel_Data_Callback(which_channel, data, num_bytes, frequency, channels, GetBitDepth(format), format, decode_mode_is_predecoded); | |
1050 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1051 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
|
1052 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1053 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1054 static void Invoke_Predecoded_Channel_Data_Callback(ALint channel, ALmixer_Data* data) |
0 | 1055 { |
1056 if(NULL == data->sample) | |
1057 { | |
1058 return; | |
1059 } | |
1060 /* The buffer position is complicated because if the current data was seeked, | |
1061 * we must adjust the buffer to the seek position | |
1062 */ | |
1063 Invoke_Channel_Data_Callback(channel, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1064 (((ALbyte*) data->sample->buffer) + (data->total_bytes - data->loaded_bytes) ), |
0 | 1065 data->loaded_bytes, |
1066 data->sample->desired.rate, | |
1067 data->sample->desired.channels, | |
1068 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1069 AL_TRUE |
0 | 1070 ); |
1071 } | |
1072 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1073 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
|
1074 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1075 ALint index; |
0 | 1076 if(NULL == data->buffer_map_list) |
1077 { | |
1078 return; | |
1079 } | |
1080 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1081 /* This should catch the case where all buffers are unqueued | |
1082 * and the "current" buffer is id: 0 | |
1083 */ | |
1084 if(-1 == index) | |
1085 { | |
1086 return; | |
1087 } | |
1088 Invoke_Channel_Data_Callback(channel, | |
1089 data->buffer_map_list[index].data, | |
1090 data->buffer_map_list[index].num_bytes, | |
1091 data->sample->desired.rate, | |
1092 data->sample->desired.channels, | |
1093 data->sample->desired.format, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1094 AL_FALSE |
0 | 1095 ); |
1096 } | |
1097 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1098 /* Converts milliseconds to byte positions. |
0 | 1099 * This is needed for seeking on predecoded samples |
1100 */ | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1101 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
|
1102 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1103 ALuint bytes_per_sample; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1104 ALuint bytes_per_frame; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1105 float bytes_per_millisecond; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1106 float byte_position; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1107 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1108 if(audio_info == NULL) |
0 | 1109 { |
1110 fprintf(stderr, "Error, info is NULL\n"); | |
1111 } | |
1112 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1113 /* 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
|
1114 * 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
|
1115 * 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
|
1116 * 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
|
1117 * 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
|
1118 * Uint32 to unspecified size types like ALuint. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1119 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1120 bytes_per_sample = (ALuint) ((audio_info->format & 0xFF) / 8); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1121 bytes_per_frame = bytes_per_sample * audio_info->channels; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1122 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
|
1123 byte_position = ((float)(number_of_milliseconds)) * bytes_per_millisecond; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
1124 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
|
1125 } |
0 | 1126 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1127 static ALint Set_Predecoded_Seek_Position(ALmixer_Data* data, ALuint byte_position) |
0 | 1128 { |
1129 ALenum error; | |
1130 /* clear error */ | |
1131 alGetError(); | |
1132 | |
1133 /* Is it greater than, or greater-than or equal to ?? */ | |
1134 if(byte_position > data->total_bytes) | |
1135 { | |
1136 /* 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
|
1137 /* |
0 | 1138 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
|
1139 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1140 |
0 | 1141 /* In case the below thing doesn't work, |
1142 * just rewind the whole thing. | |
1143 * | |
1144 alBufferData(data->buffer[0], | |
1145 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1146 (ALbyte*) data->sample->buffer, |
0 | 1147 data->total_bytes, |
1148 data->sample->desired.rate | |
1149 ); | |
1150 */ | |
1151 | |
1152 /* I was trying to set to the end, (1 byte remaining), | |
1153 * but I was getting freezes. I'm thinking it might be | |
1154 * another Power of 2 bug in the Loki dist. I tried 2, | |
1155 * and it still hung. 4 didn't hang, but I got a clip | |
1156 * artifact. 8 seemed to work okay. | |
1157 */ | |
1158 alBufferData(data->buffer[0], | |
1159 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1160 (((ALbyte*) data->sample->buffer) + (data->total_bytes - 8) ), |
0 | 1161 8, |
1162 data->sample->desired.rate | |
1163 ); | |
1164 if( (error = alGetError()) != AL_NO_ERROR) | |
1165 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1166 ALmixer_SetError("Can't seek past end and alBufferData failed: %s\n", alGetString(error)); |
0 | 1167 return -1; |
1168 } | |
1169 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1170 * query command to work because I don't know if it will mutilate the | |
1171 * size for its own purposes or return the original size | |
1172 */ | |
1173 data->loaded_bytes = 8; | |
1174 | |
1175 /* Not sure if this should be an error or not */ | |
1176 /* | |
1177 ALmixer_SetError("Can't Seek past end"); | |
1178 return -1; | |
1179 */ | |
1180 return 0; | |
1181 } | |
1182 | |
1183 alBufferData(data->buffer[0], | |
1184 TranslateFormat(&data->sample->desired), | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1185 &(((ALbyte*)data->sample->buffer)[byte_position]), |
0 | 1186 data->total_bytes - byte_position, |
1187 data->sample->desired.rate | |
1188 ); | |
1189 if( (error = alGetError()) != AL_NO_ERROR) | |
1190 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1191 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1192 return -1; |
1193 } | |
1194 /* Need to set the loaded_bytes field because I don't trust the OpenAL | |
1195 * query command to work because I don't know if it will mutilate the | |
1196 * size for its own purposes or return the original size | |
1197 */ | |
1198 data->loaded_bytes = data->total_bytes - byte_position; | |
1199 | |
1200 return 0; | |
1201 } | |
1202 | |
1203 /* Because we have multiple queue buffers and OpenAL won't let | |
1204 * us access them, we need to keep copies of each buffer around | |
1205 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1206 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
|
1207 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1208 ALint index; |
0 | 1209 /* We only want to copy if access_data is true. |
1210 * This is determined by whether memory has been | |
1211 * allocated in the buffer_map_list or not | |
1212 */ | |
1213 if(NULL == data->buffer_map_list) | |
1214 { | |
1215 return -1; | |
1216 } | |
1217 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers); | |
1218 if(-1 == index) | |
1219 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1220 /* |
0 | 1221 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
|
1222 */ |
0 | 1223 return -1; |
1224 } | |
1225 /* Copy the data to the access buffer */ | |
1226 memcpy(data->buffer_map_list[index].data, data->sample->buffer, num_bytes); | |
1227 data->buffer_map_list[index].num_bytes = data->sample->buffer_size; | |
1228 | |
1229 return 0; | |
1230 } | |
1231 | |
1232 | |
1233 /* For streamed data, gets more data | |
1234 * and prepares it in the active Mix_chunk | |
1235 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1236 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
|
1237 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1238 ALuint bytes_decoded; |
0 | 1239 ALenum error; |
1240 if(NULL == data) | |
1241 { | |
1242 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1243 return 0; | |
1244 } | |
1245 | |
1246 bytes_decoded = Sound_Decode(data->sample); | |
1247 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1248 { | |
1249 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1250 ALmixer_SetError(Sound_GetError()); | |
1251 /* Force cleanup through FreeData | |
1252 Sound_FreeSample(data->sample); | |
1253 */ | |
1254 return 0; | |
1255 } | |
1256 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1257 /* 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
|
1258 |
0 | 1259 /* Don't forget to add check for EOF */ |
1260 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1261 if(0 == bytes_decoded) | |
1262 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1263 data->eof = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1264 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1265 #if 0 |
0 | 1266 fprintf(stderr, "Hit eof while trying to buffer\n"); |
1267 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1268 { | |
1269 fprintf(stderr, "\tEOF flag\n"); | |
1270 } | |
1271 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1272 { | |
1273 fprintf(stderr, "\tCanSeek flag\n"); | |
1274 } | |
1275 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1276 { | |
1277 fprintf(stderr, "\tEAGAIN flag\n"); | |
1278 } | |
1279 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1280 { | |
1281 fprintf(stderr, "\tNONE flag\n"); | |
1282 } | |
1283 #endif | |
1284 return 0; | |
1285 } | |
1286 | |
1287 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
1288 /******* REMOVE ME ********************************/ | |
1289 /***************** ANOTHER EXPERIEMENT *******************/ | |
1290 /* The PROBLEM: It seems that the Loki distribution has problems | |
1291 * with Queuing when the buffer size is not a power of two | |
1292 * and additional buffers must come after it. | |
1293 * The behavior is inconsistent, but one of several things | |
1294 * usually happens: | |
1295 * Playback is normal | |
1296 * Playback immediately stops after the non-pow2 buffer | |
1297 * Playback gets distorted on the non-pow2 buffer | |
1298 * The entire program segfaults. | |
1299 * The workaround is to always specify a power of two buffer size | |
1300 * and hope that SDL_sound always fill it. (By lucky coincidence, | |
1301 * I already submitted the Ogg fix.) However, this won't catch | |
1302 * cases where a loop happens because the read at the end of the | |
1303 * file is typically less than the buffer size. | |
1304 * | |
1305 * This fix addresses this issue, however it may break in | |
1306 * other conditions. Always decode in buffer sizes of powers of 2. | |
1307 * | |
1308 * The HACK: | |
1309 * If the buffer is short, try filling it up with 0's | |
1310 * to meet the user requested buffer_size which | |
1311 * is probably a nice number OpenAL likes, in | |
1312 * hopes to avoid a possible Loki bug with | |
1313 * short buffers. If looping (which is the main | |
1314 * reason for this), the negative side effect is | |
1315 * that it may take longer for the loop to start | |
1316 * because it must play dead silence. Or if the decoder | |
1317 * doesn't guarantee to return the requested bytes | |
1318 * (like Ogg), then you will get breakup in between | |
1319 * packets. | |
1320 */ | |
1321 if( (bytes_decoded) < data->sample->buffer_size) | |
1322 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1323 ALubyte bit_depth; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1324 ALubyte signedness_value; |
0 | 1325 int silence_value; |
1326 /* Crap, memset value needs to be the "silent" value, | |
1327 * but it will differ for signed/unsigned and bit depth | |
1328 */ | |
1329 bit_depth = GetBitDepth(data->sample->desired.format); | |
1330 signedness_value = GetSignednessValue(data->sample->desired.format); | |
1331 if(ALMIXER_SIGNED_VALUE == signedness_value) | |
1332 { | |
1333 /* I'm guessing that if it's signed, then 0 is the | |
1334 * "silent" value */ | |
1335 silence_value = 0; | |
1336 } | |
1337 else | |
1338 { | |
1339 if(8 == bit_depth) | |
1340 { | |
1341 /* If 8 bit, I'm guessing it's (2^7)-1 = 127 */ | |
1342 silence_value = 127; | |
1343 } | |
1344 else | |
1345 { | |
1346 /* For 16 bit, I'm guessing it's (2^15)-1 = 32767 */ | |
1347 silence_value = 32767; | |
1348 } | |
1349 } | |
1350 /* Now fill up the rest of the data buffer with the | |
1351 * silence_value. | |
1352 * I don't think I have to worry about endian issues for | |
1353 * this part since the data is for internal use only | |
1354 * at this point. | |
1355 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1356 memset( &( ((ALbyte*)(data->sample->buffer))[bytes_decoded] ), silence_value, data->sample->buffer_size - bytes_decoded); |
0 | 1357 /* Now reset the bytes_decoded to reflect the entire |
1358 * buffer to tell alBufferData what our full size is. | |
1359 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
1360 /* |
0 | 1361 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
|
1362 */ |
0 | 1363 bytes_decoded = data->sample->buffer_size; |
1364 } | |
1365 /*********** END EXPERIMENT ******************************/ | |
1366 /******* END REMOVE ME ********************************/ | |
1367 #endif | |
1368 | |
1369 /* Now copy the data to the OpenAL buffer */ | |
1370 /* We can't just set a pointer because the API needs | |
1371 * its own copy to assist hardware acceleration */ | |
1372 alBufferData(buffer, | |
1373 TranslateFormat(&data->sample->desired), | |
1374 data->sample->buffer, | |
1375 bytes_decoded, | |
1376 data->sample->desired.rate | |
1377 ); | |
1378 if( (error = alGetError()) != AL_NO_ERROR) | |
1379 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1380 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1381 return 0; |
1382 } | |
1383 | |
1384 /* If we need to, copy the data also to the access area | |
1385 * (the function will do the check for us) | |
1386 */ | |
1387 CopyDataToAccessBuffer(data, bytes_decoded, buffer); | |
1388 return bytes_decoded; | |
1389 } | |
1390 | |
1391 | |
1392 | |
1393 | |
1394 /******************** EXPERIEMENT **************************** | |
1395 * Test function to force maximum buffer filling during loops | |
1396 * REMOVE LATER | |
1397 *********************************************/ | |
1398 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1399 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
|
1400 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1401 ALint bytes_decoded; |
0 | 1402 ALenum error; |
1403 if(NULL == data) | |
1404 { | |
1405 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n"); | |
1406 return -1; | |
1407 } | |
1408 | |
1409 if(AL_FALSE == alIsBuffer(buffer)) | |
1410 { | |
1411 fprintf(stderr, "NOT A BUFFER>>>>>>>>>>>>>>>\n"); | |
1412 return -1; | |
1413 } | |
1414 fprintf(stderr, "Entered GetMoreData222222: buffer id is %d\n", buffer); | |
1415 | |
1416 /* | |
1417 fprintf(stderr, "Decode in GetMoreData\n"); | |
1418 */ | |
1419 | |
1420 #if 0 | |
1421 if(buffer%2 == 1) | |
1422 { | |
1423 fprintf(stderr, "Setting buffer size to 16384\n"); | |
1424 Sound_SetBufferSize(data->sample, 16384); | |
1425 } | |
1426 else | |
1427 { | |
1428 fprintf(stderr, "Setting buffer size to 8192\n"); | |
1429 Sound_SetBufferSize(data->sample, 8192); | |
1430 } | |
1431 #endif | |
1432 | |
1433 bytes_decoded = Sound_Decode(data->sample); | |
1434 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
1435 { | |
1436 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n"); | |
1437 ALmixer_SetError(Sound_GetError()); | |
1438 /* | |
1439 Sound_FreeSample(data->sample); | |
1440 */ | |
1441 return -1; | |
1442 } | |
1443 /* Don't forget to add check for EOF */ | |
1444 /* Will return 0 bytes and pass the buck to check sample->flags */ | |
1445 if(0 == bytes_decoded) | |
1446 { | |
1447 #if 1 | |
1448 fprintf(stderr, "Hit eof while trying to buffer\n"); | |
1449 data->eof = 1; | |
1450 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF) | |
1451 { | |
1452 fprintf(stderr, "\tEOF flag\n"); | |
1453 } | |
1454 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK) | |
1455 { | |
1456 fprintf(stderr, "\tCanSeek flag\n"); | |
1457 } | |
1458 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
1459 { | |
1460 fprintf(stderr, "\tEAGAIN flag\n"); | |
1461 } | |
1462 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE) | |
1463 { | |
1464 fprintf(stderr, "\tNONE flag\n"); | |
1465 } | |
1466 #endif | |
1467 return 0; | |
1468 } | |
1469 | |
1470 if(bytes_decoded < 16384) | |
1471 { | |
1472 char* tempbuffer1 = (char*)malloc(16384); | |
1473 char* tempbuffer2 = (char*)malloc(16384); | |
1474 int retval; | |
1475 memcpy(tempbuffer1, data->sample->buffer, bytes_decoded); | |
1476 retval = Sound_SetBufferSize(data->sample, 16384-bytes_decoded); | |
1477 if(retval == 1) | |
1478 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1479 ALuint new_bytes; |
0 | 1480 Sound_Rewind(data->sample); |
1481 new_bytes = Sound_Decode(data->sample); | |
1482 fprintf(stderr, "Orig bytes: %d, Make up bytes_decoded=%d, total=%d\n", bytes_decoded, new_bytes, new_bytes+bytes_decoded); | |
1483 | |
1484 memcpy(tempbuffer2, data->sample->buffer, new_bytes); | |
1485 | |
1486 retval = Sound_SetBufferSize(data->sample, 16384); | |
1487 fprintf(stderr, "Finished reset...now danger copy\n"); | |
1488 memcpy(data->sample->buffer, tempbuffer1,bytes_decoded); | |
1489 | |
1490 fprintf(stderr, "Finished reset...now danger copy2\n"); | |
1491 memcpy( &( ((char*)(data->sample->buffer))[bytes_decoded] ), tempbuffer2, new_bytes); | |
1492 | |
1493 fprintf(stderr, "Finished \n"); | |
1494 | |
1495 free(tempbuffer1); | |
1496 free(tempbuffer2); | |
1497 bytes_decoded += new_bytes; | |
1498 fprintf(stderr, "ASSERT bytes should equal 16384: %d\n", bytes_decoded); | |
1499 } | |
1500 else | |
1501 { | |
1502 fprintf(stderr, "Experiment failed: %s\n", Sound_GetError()); | |
1503 } | |
1504 } | |
1505 | |
1506 /* Now copy the data to the OpenAL buffer */ | |
1507 /* We can't just set a pointer because the API needs | |
1508 * its own copy to assist hardware acceleration */ | |
1509 alBufferData(buffer, | |
1510 TranslateFormat(&data->sample->desired), | |
1511 data->sample->buffer, | |
1512 bytes_decoded, | |
1513 data->sample->desired.rate | |
1514 ); | |
1515 if( (error = alGetError()) != AL_NO_ERROR) | |
1516 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1517 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 1518 return -1; |
1519 } | |
1520 | |
1521 fprintf(stderr, "GetMoreData2222 returning %d bytes decoded\n", bytes_decoded); | |
1522 return bytes_decoded; | |
1523 } | |
1524 #endif | |
1525 | |
1526 /************ END EXPERIEMENT - REMOVE ME *************************/ | |
1527 | |
1528 | |
1529 | |
1530 | |
1531 | |
1532 | |
1533 | |
1534 | |
1535 | |
1536 /* This function will look up the source for the corresponding channel */ | |
1537 /* 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
|
1538 static ALuint Internal_GetSource(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1539 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1540 ALint i; |
0 | 1541 /* Make sure channel is in bounds */ |
1542 if(channel >= Number_of_Channels_global) | |
1543 { | |
1544 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); | |
1545 return 0; | |
1546 } | |
1547 /* If the user specified -1, then return the an available source */ | |
1548 if(channel < 0) | |
1549 { | |
1550 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1551 { | |
1552 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1553 { | |
1554 return ALmixer_Channel_List[i].alsource; | |
1555 } | |
1556 } | |
1557 /* If we get here, all sources are in use */ | |
1558 /* Error message seems too harsh | |
1559 ALmixer_SetError("All sources are in use"); | |
1560 */ | |
1561 return 0; | |
1562 } | |
1563 /* Last case: Return the source for the channel */ | |
1564 return ALmixer_Channel_List[channel].alsource; | |
1565 } | |
1566 | |
1567 /* 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
|
1568 static ALint Internal_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1569 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1570 ALint i; |
0 | 1571 /* Only the first value is used for the key */ |
1572 Source_Map key = { 0, 0 }; | |
1573 Source_Map* found_item = NULL; | |
1574 key.source = source; | |
1575 | |
1576 /* If the source is 0, look up the first available channel */ | |
1577 if(0 == source) | |
1578 { | |
1579 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
1580 { | |
1581 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1582 { | |
1583 return i; | |
1584 } | |
1585 } | |
1586 /* If we get here, all sources are in use */ | |
1587 /* Error message seems too harsh | |
1588 ALmixer_SetError("All channels are in use"); | |
1589 */ | |
1590 return -1; | |
1591 } | |
1592 | |
1593 | |
1594 /* Else, look up the source and return the channel */ | |
1595 if(AL_FALSE == alIsSource(source)) | |
1596 { | |
1597 ALmixer_SetError("Is not a source"); | |
1598 return -1; | |
1599 } | |
1600 | |
1601 /* Use the ANSI C binary search feature (yea!) */ | |
1602 found_item = (Source_Map*)bsearch(&key, Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
1603 if(NULL == found_item) | |
1604 { | |
1605 ALmixer_SetError("Source is valid but not registered with ALmixer (to a channel)"); | |
1606 return -1; | |
1607 } | |
1608 return found_item->channel; | |
1609 } | |
1610 | |
1611 | |
1612 | |
1613 /* This function will find the first available channel (not in use) | |
1614 * from the specified start channel. Reserved channels to not qualify | |
1615 * as available. | |
1616 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1617 static ALint Internal_FindFreeChannel(ALint start_channel) |
0 | 1618 { |
1619 /* Start at the number of reserved so we skip over | |
1620 * all the reserved channels. | |
1621 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1622 ALint i = Number_of_Reserve_Channels_global; |
0 | 1623 /* Quick check to see if we're out of bounds */ |
1624 if(start_channel >= Number_of_Channels_global) | |
1625 { | |
1626 return -1; | |
1627 } | |
1628 | |
1629 /* If the start channel is even higher than the reserved, | |
1630 * then start at the higher value. | |
1631 */ | |
1632 if(start_channel > Number_of_Reserve_Channels_global) | |
1633 { | |
1634 i = start_channel; | |
1635 } | |
1636 | |
1637 /* i has already been set */ | |
1638 for( ; i<Number_of_Channels_global; i++) | |
1639 { | |
1640 if( ! ALmixer_Channel_List[i].channel_in_use ) | |
1641 { | |
1642 return i; | |
1643 } | |
1644 } | |
1645 /* If we get here, all sources are in use */ | |
1646 return -1; | |
1647 } | |
1648 | |
1649 | |
1650 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1651 /* 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
|
1652 * or 0 for error |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1653 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1654 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
|
1655 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1656 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1657 ALint counter = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1658 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1659 ALint buffers_still_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1660 ALint buffers_processed; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1661 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1662 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1663 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1664 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
|
1665 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1666 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1667 /* 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
|
1668 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1669 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1670 /* 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
|
1671 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
|
1672 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1673 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1674 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1675 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1676 fprintf(stderr, "14Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1677 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1678 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1679 /* 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
|
1680 * 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
|
1681 * 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
|
1682 * 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
|
1683 * 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
|
1684 * 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
|
1685 * 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
|
1686 * 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
|
1687 * 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
|
1688 * 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
|
1689 * still-queued buffers. |
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 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1692 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1693 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1694 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1695 if((error = alGetError()) != AL_NO_ERROR) |
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 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
|
1698 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1699 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
|
1700 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1701 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1702 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1703 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1704 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1705 AL_BUFFERS_PROCESSED, &buffers_processed |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1706 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1707 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1708 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1709 fprintf(stderr, "17Testing Error with buffers_processed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1710 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1711 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
|
1712 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1713 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1714 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1715 /* 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
|
1716 * to clear the source |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1717 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1718 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
|
1719 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1720 alSourcei(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1721 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1722 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1723 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1724 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1725 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
|
1726 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1727 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
|
1728 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1729 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1730 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1731 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1732 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1733 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
|
1734 |
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
|
1735 /* 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
|
1736 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
|
1737 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1738 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1739 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1740 counter++; |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1743 /* 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
|
1744 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1745 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1746 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1747 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
|
1748 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1749 /* 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
|
1750 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
|
1751 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1752 alSourceStop(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1753 if((error = alGetError()) != AL_NO_ERROR) |
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 fprintf(stderr, "19Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1756 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1757 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1758 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1759 /* 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
|
1760 * 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
|
1761 * 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
|
1762 * 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
|
1763 * 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
|
1764 * 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
|
1765 * 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
|
1766 * 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
|
1767 * 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
|
1768 * 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
|
1769 * still-queued buffers. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1770 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1771 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1772 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1773 AL_BUFFERS_QUEUED, &buffers_still_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1774 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1775 if((error = alGetError()) != AL_NO_ERROR) |
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 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
|
1778 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1779 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
|
1780 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1781 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1782 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1783 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1784 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1785 AL_BUFFERS_PROCESSED, &buffers_processed |
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 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1788 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1789 fprintf(stderr, "17Testing Error with buffers_processed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1790 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1791 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
|
1792 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1793 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1794 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1795 /* 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
|
1796 * to clear the source |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1797 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1798 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
|
1799 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1800 alSourcei(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1801 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1802 AL_NONE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1803 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1804 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1805 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
|
1806 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1807 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
|
1808 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1809 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1810 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1811 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1812 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1813 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
|
1814 |
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
|
1815 /* 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
|
1816 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
|
1817 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1818 Clean_Channel(i); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1819 Is_Playing_global--; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1820 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1821 /* Increment the counter */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1822 counter++; |
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 /* 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
|
1825 * are bugs. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1826 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1827 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1828 else |
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 alSourceStop(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1831 / * 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
|
1832 * data will get messed up * / |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1833 Clean_Channel(channel); |
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 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1836 /* Just in case */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1837 Is_Playing_global = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1838 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1839 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1840 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1841 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1842 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1843 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1844 return counter; |
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 /* 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
|
1849 * 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
|
1850 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1851 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
|
1852 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1853 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1854 if(0 == source) |
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 /* 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
|
1857 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
|
1858 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1859 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1860 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1861 if(-1 == channel) |
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 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
|
1864 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1865 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1866 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
|
1867 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1868 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1869 |
0 | 1870 |
1871 /* Note: Behaves, almost like SDL_mixer, but keep in mind | |
1872 * that there is no "music" channel anymore, so 0 | |
1873 * will remove everything. (Note, I no longer allow 0 | |
1874 * so it gets set to the default number.) | |
1875 * Also, callbacks for deleted channels will not be called. | |
1876 * I really need to do error checking, for realloc and | |
1877 * GenSources, but reversing the damage is too painful | |
1878 * for me to think about at the moment, so it's not in here. | |
1879 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1880 static ALint Internal_AllocateChannels(ALint numchans) |
0 | 1881 { |
1882 ALenum error; | |
1883 int i; | |
1884 /* Return info */ | |
1885 if(numchans < 0) | |
1886 { | |
1887 return Number_of_Channels_global; | |
1888 } | |
1889 if(0 == numchans) | |
1890 { | |
1891 numchans = ALMIXER_DEFAULT_NUM_CHANNELS; | |
1892 } | |
1893 /* No change */ | |
1894 if(numchans == Number_of_Channels_global) | |
1895 { | |
1896 return Number_of_Channels_global; | |
1897 } | |
1898 /* We need to increase the number of channels */ | |
1899 if(numchans > Number_of_Channels_global) | |
1900 { | |
1901 /* Not sure how safe this is, but SDL_mixer does it | |
1902 * the same way */ | |
1903 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1904 | |
1905 /* Allocate memory for the list of sources that map to the channels */ | |
1906 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
1907 | |
1908 for(i=Number_of_Channels_global; i<numchans; i++) | |
1909 { | |
1910 Init_Channel(i); | |
1911 /* Generate a new source and associate it with the channel */ | |
1912 alGenSources(1, &ALmixer_Channel_List[i].alsource); | |
1913 if((error = alGetError()) != AL_NO_ERROR) | |
1914 { | |
1915 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
|
1916 alGetString(error)); |
0 | 1917 } |
1918 /* Copy the source so the SourceMap has it too */ | |
1919 Source_Map_List[i].source = ALmixer_Channel_List[i].alsource; | |
1920 Source_Map_List[i].channel = i; | |
1921 /* Clean the channel because there are some things that need to | |
1922 * be done that can't happen until the source is set | |
1923 */ | |
1924 Clean_Channel(i); | |
1925 } | |
1926 | |
1927 /* The Source_Map_List must be sorted by source for binary searches | |
1928 */ | |
1929 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
1930 | |
1931 Number_of_Channels_global = numchans; | |
1932 return numchans; | |
1933 } | |
1934 /* Need to remove channels. This might be dangerous */ | |
1935 if(numchans < Number_of_Channels_global) | |
1936 { | |
1937 for(i=numchans; i<Number_of_Channels_global; i++) | |
1938 { | |
1939 /* Halt the channel */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1940 Internal_HaltChannel(i, AL_FALSE); |
0 | 1941 |
1942 /* Delete source associated with the channel */ | |
1943 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
1944 if((error = alGetError()) != AL_NO_ERROR) | |
1945 { | |
1946 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
|
1947 alGetString(error)); |
0 | 1948 } |
1949 } | |
1950 | |
1951 | |
1952 /* Not sure how safe this is, but SDL_mixer does it | |
1953 * the same way */ | |
1954 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel)); | |
1955 | |
1956 /* The tricky part is that we must remove the entries | |
1957 * in the source map that correspond to the deleted channels. | |
1958 * We'll resort the map by channels so we can pick them off | |
1959 * in order. | |
1960 */ | |
1961 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map_by_channel); | |
1962 | |
1963 /* Deallocate memory for the list of sources that map to the channels */ | |
1964 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map)); | |
1965 | |
1966 /* Now resort the map by source and the correct num of chans */ | |
1967 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map); | |
1968 | |
1969 /* Reset the number of channels */ | |
1970 Number_of_Channels_global = numchans; | |
1971 return numchans; | |
1972 } | |
1973 /* Shouldn't ever reach here */ | |
1974 return -1; | |
1975 | |
1976 } | |
1977 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
1978 static ALint Internal_ReserveChannels(ALint num) |
0 | 1979 { |
1980 /* Can't reserve more than the max num of channels */ | |
1981 /* Actually, I'll allow it for people who just want to | |
1982 * set the value really high to effectively disable | |
1983 * auto-assignment | |
1984 */ | |
1985 | |
1986 /* Return the current number of reserved channels */ | |
1987 if(num < 0) | |
1988 { | |
1989 return Number_of_Reserve_Channels_global; | |
1990 } | |
1991 Number_of_Reserve_Channels_global = num; | |
1992 return Number_of_Reserve_Channels_global; | |
1993 } | |
1994 | |
1995 | |
1996 /* This will rewind the SDL_Sound sample for streamed | |
1997 * samples and start buffering up the data for the next | |
1998 * playback. This may require samples to be halted | |
1999 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2000 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
|
2001 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2002 ALint retval = 0; |
0 | 2003 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2004 ALint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2005 ALint i; |
0 | 2006 */ |
2007 if(NULL == data) | |
2008 { | |
2009 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
|
2010 return AL_FALSE; |
0 | 2011 } |
2012 | |
2013 | |
2014 /* Might have to require Halt */ | |
2015 /* Okay, we assume Halt or natural stop has already | |
2016 * cleared the data buffers | |
2017 */ | |
2018 if(data->in_use) | |
2019 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2020 /* |
0 | 2021 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
|
2022 */ |
0 | 2023 /* |
2024 ALmixer_SetError("Data is in use. Cannot rewind unless all sources using the data are halted\n"); | |
2025 return -1; | |
2026 */ | |
2027 } | |
2028 | |
2029 | |
2030 /* Because Seek can alter things even in predecoded data, | |
2031 * decoded data must also be rewound | |
2032 */ | |
2033 if(data->decoded_all) | |
2034 { | |
2035 data->eof = 0; | |
2036 | |
2037 #if 0 | |
2038 #if defined(DISABLE_PREDECODED_SEEK) | |
2039 /* 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
|
2040 return AL_TRUE; |
0 | 2041 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) |
2042 /* This case is if the Sound_Sample has been deleted. | |
2043 * It assumes the data is already at the beginning. | |
2044 */ | |
2045 if(NULL == data->sample) | |
2046 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2047 return AL_TRUE; |
0 | 2048 } |
2049 /* Else, the sample has already been reallocated, | |
2050 * and we can fall to normal behavior | |
2051 */ | |
2052 #endif | |
2053 #endif | |
2054 /* If access_data, was enabled, the sound sample | |
2055 * still exists and we can do stuff. | |
2056 * If it's NULL, we can't do anything, but | |
2057 * it should already be "rewound". | |
2058 */ | |
2059 if(NULL == data->sample) | |
2060 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2061 return AL_TRUE; |
0 | 2062 } |
2063 /* Else, the sample has already been reallocated, | |
2064 * and we can fall to normal behavior | |
2065 */ | |
2066 | |
2067 Set_Predecoded_Seek_Position(data, 0); | |
2068 /* | |
2069 return data->total_bytes; | |
2070 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2071 return AL_TRUE; |
0 | 2072 } |
2073 | |
2074 /* Remaining stuff for streamed data */ | |
2075 | |
2076 data->eof = 0; | |
2077 retval = Sound_Rewind(data->sample); | |
2078 if(0 == retval) | |
2079 { | |
2080 ALmixer_SetError( Sound_GetError() ); | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2081 return AL_FALSE; |
0 | 2082 } |
2083 #if 0 | |
2084 /* Clear error */ | |
2085 alGetError(); | |
2086 for(i=0; i<data->num_buffers; i++) | |
2087 { | |
2088 bytes_returned = GetMoreData(data, data->buffer[i]); | |
2089 if(-1 == bytes_returned) | |
2090 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2091 return AL_FALSE; |
0 | 2092 } |
2093 else if(0 == bytes_returned) | |
2094 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2095 return AL_FALSE; |
0 | 2096 } |
2097 retval += bytes_returned; | |
2098 | |
2099 } | |
2100 #endif | |
2101 | |
2102 | |
2103 | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2104 return AL_TRUE; |
0 | 2105 } |
2106 | |
2107 | |
2108 | |
2109 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2110 static ALint Internal_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2111 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2112 ALint retval = 0; |
0 | 2113 ALenum error; |
2114 ALint state; | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2115 ALint running_count = 0; |
0 | 2116 |
2117 if(channel >= Number_of_Channels_global) | |
2118 { | |
2119 ALmixer_SetError("Cannot rewind channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2120 return -1; | |
2121 } | |
2122 | |
2123 if((error = alGetError()) != AL_NO_ERROR) | |
2124 { | |
2125 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
|
2126 alGetString(error)); |
0 | 2127 } |
2128 /* Clear error */ | |
2129 alGetError(); | |
2130 | |
2131 /* If the user specified a specific channel */ | |
2132 if(channel >= 0) | |
2133 { | |
2134 /* only need to process channel if in use */ | |
2135 if(ALmixer_Channel_List[channel].channel_in_use) | |
2136 { | |
2137 | |
2138 /* What should I do? Do I just rewind the channel | |
2139 * or also rewind the data? Since the data is | |
2140 * shared, let's make it the user's responsibility | |
2141 * to rewind the data. | |
2142 */ | |
2143 if(ALmixer_Channel_List[channel].almixer_data->decoded_all) | |
2144 { | |
2145 alGetSourcei( | |
2146 ALmixer_Channel_List[channel].alsource, | |
2147 AL_SOURCE_STATE, &state | |
2148 ); | |
2149 if((error = alGetError()) != AL_NO_ERROR) | |
2150 { | |
2151 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
|
2152 alGetString(error)); |
0 | 2153 } |
2154 alSourceRewind(ALmixer_Channel_List[channel].alsource); | |
2155 if((error = alGetError()) != AL_NO_ERROR) | |
2156 { | |
2157 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2158 alGetString(error) ); |
0 | 2159 retval = -1; |
2160 } | |
2161 /* Need to resume playback if it was originally playing */ | |
2162 if(AL_PLAYING == state) | |
2163 { | |
2164 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2165 if((error = alGetError()) != AL_NO_ERROR) | |
2166 { | |
2167 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2168 alGetString(error) ); |
0 | 2169 retval = -1; |
2170 } | |
2171 } | |
2172 else if(AL_PAUSED == state) | |
2173 { | |
2174 /* HACK: The problem is that when paused, after | |
2175 * the Rewind, I can't get it off the INITIAL | |
2176 * state without restarting | |
2177 */ | |
2178 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
2179 if((error = alGetError()) != AL_NO_ERROR) | |
2180 { | |
2181 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
|
2182 alGetString(error)); |
0 | 2183 } |
2184 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2185 if((error = alGetError()) != AL_NO_ERROR) | |
2186 { | |
2187 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2188 alGetString(error) ); |
0 | 2189 retval = -1; |
2190 } | |
2191 } | |
2192 } | |
2193 else | |
2194 { | |
2195 /* Streamed data is different. Rewinding the channel | |
2196 * does no good. Rewinding the data will have an | |
2197 * effect, but it will be lagged based on how | |
2198 * much data is queued. Recommend users call Halt | |
2199 * before rewind if they want immediate results. | |
2200 */ | |
2201 retval = Internal_RewindData(ALmixer_Channel_List[channel].almixer_data); | |
2202 } | |
2203 } | |
2204 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2205 /* The user wants to rewind all channels */ |
0 | 2206 else |
2207 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2208 ALint i; |
0 | 2209 for(i=0; i<Number_of_Channels_global; i++) |
2210 { | |
2211 /* only need to process channel if in use */ | |
2212 if(ALmixer_Channel_List[i].channel_in_use) | |
2213 { | |
2214 /* What should I do? Do I just rewind the channel | |
2215 * or also rewind the data? Since the data is | |
2216 * shared, let's make it the user's responsibility | |
2217 * to rewind the data. | |
2218 */ | |
2219 if(ALmixer_Channel_List[i].almixer_data->decoded_all) | |
2220 { | |
2221 alGetSourcei( | |
2222 ALmixer_Channel_List[i].alsource, | |
2223 AL_SOURCE_STATE, &state | |
2224 ); | |
2225 if((error = alGetError()) != AL_NO_ERROR) | |
2226 { | |
2227 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
|
2228 alGetString(error)); |
0 | 2229 } |
2230 alSourceRewind(ALmixer_Channel_List[i].alsource); | |
2231 if((error = alGetError()) != AL_NO_ERROR) | |
2232 { | |
2233 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2234 alGetString(error) ); |
0 | 2235 retval = -1; |
2236 } | |
2237 /* Need to resume playback if it was originally playing */ | |
2238 if(AL_PLAYING == state) | |
2239 { | |
2240 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2241 if((error = alGetError()) != AL_NO_ERROR) | |
2242 { | |
2243 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2244 alGetString(error) ); |
0 | 2245 retval = -1; |
2246 } | |
2247 } | |
2248 else if(AL_PAUSED == state) | |
2249 { | |
2250 /* HACK: The problem is that when paused, after | |
2251 * the Rewind, I can't get it off the INITIAL | |
2252 * state without restarting | |
2253 */ | |
2254 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
2255 if((error = alGetError()) != AL_NO_ERROR) | |
2256 { | |
2257 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
|
2258 alGetString(error)); |
0 | 2259 } |
2260 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2261 if((error = alGetError()) != AL_NO_ERROR) | |
2262 { | |
2263 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2264 alGetString(error) ); |
0 | 2265 retval = -1; |
2266 } | |
2267 } | |
2268 } | |
2269 else | |
2270 { | |
2271 /* Streamed data is different. Rewinding the channel | |
2272 * does no good. Rewinding the data will have an | |
2273 * effect, but it will be lagged based on how | |
2274 * much data is queued. Recommend users call Halt | |
2275 * before rewind if they want immediate results. | |
2276 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2277 running_count += Internal_RewindData(ALmixer_Channel_List[i].almixer_data); |
0 | 2278 } |
2279 } | |
2280 } | |
2281 } | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2282 if(-1 == retval) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2283 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2284 return -1; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2285 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2286 else |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2287 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2288 return running_count; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2289 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
2290 |
0 | 2291 } |
2292 | |
2293 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2294 static ALint Internal_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2295 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2296 ALint channel; |
0 | 2297 if(0 == source) |
2298 { | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
2299 return Internal_RewindChannel(-1); |
0 | 2300 } |
2301 | |
2302 channel = Internal_GetChannel(source); | |
2303 if(-1 == channel) | |
2304 { | |
2305 ALmixer_SetError("Cannot rewind source: %s", ALmixer_GetError()); | |
2306 return 0; | |
2307 } | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
2308 return Internal_RewindChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2309 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2310 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2311 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2312 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2313 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2314 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2315 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
|
2316 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2317 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2318 int ret_flag = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2319 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2320 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2321 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
|
2322 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2323 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2324 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2325 /* 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
|
2326 * 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
|
2327 * 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
|
2328 * 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
|
2329 * 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
|
2330 * to prevent sharing |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2331 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2332 if(0 == data->decoded_all) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2333 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2334 if(data->in_use) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2335 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2336 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
|
2337 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2338 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2339 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2340 /* 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
|
2341 * This mainly affects streamed files, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2342 * so the check is placed here |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2343 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2344 if(data->eof) |
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 if( -1 == Internal_RewindData(data) ) |
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 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
|
2349 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2350 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2351 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2352 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2353 /* 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
|
2354 if(-1 == channel) |
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 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2357 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
|
2358 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2359 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
|
2360 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2361 channel = i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2362 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2363 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2364 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2365 /* if 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
|
2366 if(i == Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2367 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2368 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
|
2369 return -1; |
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2372 /* 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
|
2373 * out of bounds or in use */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2374 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2375 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2376 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2377 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2378 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
|
2379 return -1; |
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 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
|
2382 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2383 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
|
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 /* 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
|
2388 if(loops < -1) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2389 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2390 loops = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2391 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2392 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2393 /* 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
|
2394 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2395 /* 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
|
2396 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
|
2397 data->in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2398 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2399 /* 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
|
2400 * (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
|
2401 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2402 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
|
2403 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
|
2404 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
|
2405 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2406 /* 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
|
2407 if(ticks < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2408 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2409 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
|
2410 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2411 else |
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_Channel_List[channel].expire_ticks = ticks; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2414 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2415 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2416 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2417 ALmixer_Channel_List[channel].halted = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2418 ALmixer_Channel_List[channel].paused = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2419 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2420 /* 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
|
2421 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2422 if( (-1 == loops) && (data->decoded_all) ) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2423 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2424 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
|
2425 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2426 else |
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 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
|
2429 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2430 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2431 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2432 fprintf(stderr, "13Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2433 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2434 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2435 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2436 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2437 /* Because of the corner case, predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2438 * 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
|
2439 * Streams do not have this problem |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2440 * 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
|
2441 * avoid the conflict. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2442 * 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
|
2443 * Since streams, cannot share, only predecoded |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2444 * files are affected |
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 if(data->decoded_all) |
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 /* 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
|
2449 * 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
|
2450 * 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
|
2451 * must be +1 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2452 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2453 if(-1 == loops) |
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 /* -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
|
2456 * to add +1 to it */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2457 ALmixer_Channel_List[channel].loops = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2458 alSourcei(ALmixer_Channel_List[channel].alsource, AL_LOOPING, AL_TRUE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2459 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2460 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2461 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2462 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
|
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 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2466 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2467 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2468 ALmixer_Channel_List[channel].loops = loops; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2469 /* 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
|
2470 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
|
2471 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2472 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2473 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2474 /* 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
|
2475 /* 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
|
2476 * 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
|
2477 * 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
|
2478 * 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
|
2479 * 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
|
2480 * 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
|
2481 * easier to maintain. |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2484 /* Clear the error flag */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2485 alGetError(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2486 if(data->decoded_all) |
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 /* Bind the data to the source */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2489 alSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2490 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2491 AL_BUFFER, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2492 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2493 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2494 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2495 ALmixer_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
|
2496 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2497 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2498 return -1; |
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 /* 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
|
2502 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
|
2503 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2504 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2505 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2506 /* 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
|
2507 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2508 ALuint bytes_returned; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2509 ALuint j; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2510 data->num_buffers_in_use=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2511 /****** MODIFICATION must go here *********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2512 /* 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
|
2513 * 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
|
2514 * 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
|
2515 * 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
|
2516 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2517 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2518 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2519 data->buffer[0]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2520 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2521 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2522 /* No data or error */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2523 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
|
2524 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2525 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2526 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2527 /* 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
|
2528 data->num_buffers_in_use++; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2531 /* 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
|
2532 * 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
|
2533 * before the last buffer is filled. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2534 * 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
|
2535 * 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
|
2536 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2537 |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2538 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2539 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
|
2540 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2541 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
|
2542 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2543 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2544 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
|
2545 fprintf(stderr, ">>>>>>>>>>>>>>>>>>HACK for GetMoreData2\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2546 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2547 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2548 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2549 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2550 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2551 * 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
|
2552 * 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
|
2553 * 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
|
2554 * 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
|
2555 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2556 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2557 if(bytes_returned < 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2558 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2559 /* Error found */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2560 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
|
2561 /* 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
|
2562 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2563 break; |
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 else if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2566 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2567 if(0 == bytes_returned) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2568 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2569 /* No more data to buffer */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2570 /* Check for loops */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2571 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
|
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, "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
|
2575 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2576 if(0 == Sound_Rewind(data->sample)) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2577 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2578 fprintf(stderr, "error in rewind\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2579 ALmixer_SetError( Sound_GetError() ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2580 ALmixer_Channel_List[channel].loops = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2581 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2582 /* 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
|
2583 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2584 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2585 /* 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
|
2586 data->eof = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2587 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
|
2588 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2589 ALmixer_Channel_List[channel].loops--; |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
2590 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2591 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
|
2592 */ |
2
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 /* 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
|
2595 * 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
|
2596 * into an infinite loop |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2597 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2598 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2599 data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2600 data->buffer[j]); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2601 if(bytes_returned <= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2602 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2603 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
|
2604 /* 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
|
2605 ret_flag = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2606 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2607 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2608 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2609 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2610 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2611 /* 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
|
2612 break; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2613 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2614 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2615 /* 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
|
2616 data->num_buffers_in_use++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2617 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2618 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2619 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
|
2620 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2621 data->num_buffers_in_use); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2622 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2623 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2624 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2625 ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2626 data->num_buffers_in_use, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2627 data->buffer); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2628 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2629 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2630 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
|
2631 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2632 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2633 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2634 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2635 /* 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
|
2636 * 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
|
2637 * 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
|
2638 * 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
|
2639 * "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
|
2640 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2641 if(data->circular_buffer_queue != NULL) |
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 ALuint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2644 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2645 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
|
2646 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2647 // fprintf(stderr, "56c: CircularQueue_PushBack.\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2648 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
|
2649 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2650 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2651 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
|
2652 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
|
2653 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2654 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2655 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2656 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2657 fprintf(stderr, "Queue in PlayTimed\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2658 CircularQueueUnsignedInt_Print(data->circular_buffer_queue); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2659 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2660 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2661 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2662 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2663 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2664 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2665 /****** END **********/ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2666 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2667 /* 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
|
2668 * so now we can play |
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 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2671 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2672 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2673 ALmixer_SetError("Play failed: %s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2674 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2675 Clean_Channel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2676 return -1; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2679 /* 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
|
2680 Is_Playing_global++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2681 if(-1 == ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2682 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2683 fprintf(stderr, "BACKDOOR ERROR >>>>>>>>>>>>>>>>>>\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2684 return -1; |
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 return channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2687 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2688 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2689 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2690 /* 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
|
2691 * 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
|
2692 * 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
|
2693 * PlayChannelTimed() function call. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2694 * 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
|
2695 * 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
|
2696 * 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
|
2697 * 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
|
2698 * 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
|
2699 * 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
|
2700 * 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
|
2701 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2702 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
|
2703 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2704 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2705 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2706 if(0 == source) |
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 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
|
2709 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2710 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2711 return 0; |
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 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2714 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2715 return Internal_GetSource(retval); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2716 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2717 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2718 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2719 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2720 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2721 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2722 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
|
2723 return 0; |
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 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
|
2726 if(-1 == retval) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2727 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2728 return 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2729 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2730 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2731 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2732 return source; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2733 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2734 /* make compiler happy */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2735 return 0; |
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 |
0 | 2738 |
2739 | |
2740 | |
2741 /* Returns the channel or number of channels actually paused */ | |
2742 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2743 static ALint Internal_PauseChannel(ALint channel) |
0 | 2744 { |
2745 ALenum error; | |
2746 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2747 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2748 ALint counter = 0; |
0 | 2749 |
2750 if(channel >= Number_of_Channels_global) | |
2751 { | |
2752 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2753 return -1; | |
2754 } | |
2755 | |
2756 if((error = alGetError()) != AL_NO_ERROR) | |
2757 { | |
2758 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
|
2759 alGetString(error)); |
0 | 2760 } |
2761 /* Clear error */ | |
2762 alGetError(); | |
2763 | |
2764 /* If the user specified a specific channel */ | |
2765 if(channel >= 0) | |
2766 { | |
2767 /* only need to process channel if in use */ | |
2768 if(ALmixer_Channel_List[channel].channel_in_use) | |
2769 { | |
2770 /* We don't want to repause if already | |
2771 * paused because the fadeout/expire | |
2772 * timing will get messed up | |
2773 */ | |
2774 alGetSourcei( | |
2775 ALmixer_Channel_List[channel].alsource, | |
2776 AL_SOURCE_STATE, &state | |
2777 ); | |
2778 if((error = alGetError()) != AL_NO_ERROR) | |
2779 { | |
2780 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
|
2781 alGetString(error)); |
0 | 2782 } |
2783 if(AL_PLAYING == state) | |
2784 { | |
2785 /* Count the actual number of channels being paused */ | |
2786 counter++; | |
2787 | |
2788 alSourcePause(ALmixer_Channel_List[channel].alsource); | |
2789 if((error = alGetError()) != AL_NO_ERROR) | |
2790 { | |
2791 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2792 alGetString(error) ); |
0 | 2793 retval = -1; |
2794 } | |
2795 /* We need to pause the expire time count down */ | |
2796 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
2797 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2798 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2799 ALuint diff_time; |
0 | 2800 diff_time = current_time - |
2801 ALmixer_Channel_List[channel].start_time; | |
2802 /* When we unpause, we will want to reset | |
2803 * the start time so we can continue | |
2804 * to base calculations off GetTicks(). | |
2805 * This means we need to subtract the amount | |
2806 * of time already used up from expire_ticks. | |
2807 */ | |
2808 ALmixer_Channel_List[channel].expire_ticks = | |
2809 ALmixer_Channel_List[channel].expire_ticks - | |
2810 diff_time; | |
2811 /* Because -1 is a special value, we can't | |
2812 * allow the time to go negative | |
2813 */ | |
2814 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2815 { | |
2816 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2817 } | |
2818 } | |
2819 /* Do the same as expire time for fading */ | |
2820 if(ALmixer_Channel_List[channel].fade_enabled) | |
2821 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2822 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2823 ALuint diff_time; |
0 | 2824 diff_time = current_time - |
2825 ALmixer_Channel_List[channel].fade_start_time; | |
2826 /* When we unpause, we will want to reset | |
2827 * the start time so we can continue | |
2828 * to base calculations off GetTicks(). | |
2829 * This means we need to subtract the amount | |
2830 * of time already used up from expire_ticks. | |
2831 */ | |
2832 ALmixer_Channel_List[channel].fade_expire_ticks = | |
2833 ALmixer_Channel_List[channel].fade_expire_ticks - | |
2834 diff_time; | |
2835 /* Don't allow the time to go negative */ | |
2836 if(ALmixer_Channel_List[channel].expire_ticks < 0) | |
2837 { | |
2838 ALmixer_Channel_List[channel].expire_ticks = 0; | |
2839 } | |
2840 } /* End fade check */ | |
2841 } /* End if PLAYING */ | |
2842 } /* End If in use */ | |
2843 } /* End specific channel */ | |
2844 /* The user wants to halt all channels */ | |
2845 else | |
2846 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2847 ALint i; |
0 | 2848 for(i=0; i<Number_of_Channels_global; i++) |
2849 { | |
2850 /* only need to process channel if in use */ | |
2851 if(ALmixer_Channel_List[i].channel_in_use) | |
2852 { | |
2853 /* We don't want to repause if already | |
2854 * paused because the fadeout/expire | |
2855 * timing will get messed up | |
2856 */ | |
2857 alGetSourcei( | |
2858 ALmixer_Channel_List[i].alsource, | |
2859 AL_SOURCE_STATE, &state | |
2860 ); | |
2861 if((error = alGetError()) != AL_NO_ERROR) | |
2862 { | |
2863 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
|
2864 alGetString(error)); |
0 | 2865 } |
2866 if(AL_PLAYING == state) | |
2867 { | |
2868 /* Count the actual number of channels being paused */ | |
2869 counter++; | |
2870 | |
2871 alSourcePause(ALmixer_Channel_List[i].alsource); | |
2872 if((error = alGetError()) != AL_NO_ERROR) | |
2873 { | |
2874 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2875 alGetString(error) ); |
0 | 2876 retval = -1; |
2877 } | |
2878 /* We need to pause the expire time count down */ | |
2879 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
2880 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2881 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2882 ALuint diff_time; |
0 | 2883 diff_time = current_time - |
2884 ALmixer_Channel_List[i].start_time; | |
2885 /* When we unpause, we will want to reset | |
2886 * the start time so we can continue | |
2887 * to base calculations off GetTicks(). | |
2888 * This means we need to subtract the amount | |
2889 * of time already used up from expire_ticks. | |
2890 */ | |
2891 ALmixer_Channel_List[i].expire_ticks = | |
2892 ALmixer_Channel_List[i].expire_ticks - | |
2893 diff_time; | |
2894 /* Because -1 is a special value, we can't | |
2895 * allow the time to go negative | |
2896 */ | |
2897 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2898 { | |
2899 ALmixer_Channel_List[i].expire_ticks = 0; | |
2900 } | |
2901 } | |
2902 /* Do the same as expire time for fading */ | |
2903 if(ALmixer_Channel_List[i].fade_enabled) | |
2904 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2905 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2906 ALuint diff_time; |
0 | 2907 diff_time = current_time - |
2908 ALmixer_Channel_List[i].fade_start_time; | |
2909 /* When we unpause, we will want to reset | |
2910 * the start time so we can continue | |
2911 * to base calculations off GetTicks(). | |
2912 * This means we need to subtract the amount | |
2913 * of time already used up from expire_ticks. | |
2914 */ | |
2915 ALmixer_Channel_List[i].fade_expire_ticks = | |
2916 ALmixer_Channel_List[i].fade_expire_ticks - | |
2917 diff_time; | |
2918 /* Don't allow the time to go negative */ | |
2919 if(ALmixer_Channel_List[i].expire_ticks < 0) | |
2920 { | |
2921 ALmixer_Channel_List[i].expire_ticks = 0; | |
2922 } | |
2923 } /* End fade check */ | |
2924 } /* End if PLAYING */ | |
2925 } /* End channel in use */ | |
2926 } /* End for-loop */ | |
2927 } | |
2928 if(-1 == retval) | |
2929 { | |
2930 return -1; | |
2931 } | |
2932 return counter; | |
2933 } | |
2934 | |
2935 /* 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
|
2936 static ALint Internal_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2937 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2938 ALint channel; |
0 | 2939 if(0 == source) |
2940 { | |
2941 return Internal_PauseChannel(-1); | |
2942 } | |
2943 | |
2944 channel = Internal_GetChannel(source); | |
2945 if(-1 == channel) | |
2946 { | |
2947 ALmixer_SetError("Cannot pause source: %s", ALmixer_GetError()); | |
2948 return -1; | |
2949 } | |
2950 return Internal_PauseChannel(channel); | |
2951 } | |
2952 | |
2953 | |
2954 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2955 static ALint Internal_ResumeChannel(ALint channel) |
0 | 2956 { |
2957 ALint state; | |
2958 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2959 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2960 ALint counter = 0; |
0 | 2961 |
2962 if(channel >= Number_of_Channels_global) | |
2963 { | |
2964 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); | |
2965 return -1; | |
2966 } | |
2967 | |
2968 if((error = alGetError()) != AL_NO_ERROR) | |
2969 { | |
2970 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
|
2971 alGetString(error)); |
0 | 2972 } |
2973 /* Clear error */ | |
2974 alGetError(); | |
2975 | |
2976 /* If the user specified a specific channel */ | |
2977 if(channel >= 0) | |
2978 { | |
2979 /* only need to process channel if in use */ | |
2980 if(ALmixer_Channel_List[channel].channel_in_use) | |
2981 { | |
2982 alGetSourcei( | |
2983 ALmixer_Channel_List[channel].alsource, | |
2984 AL_SOURCE_STATE, &state | |
2985 ); | |
2986 if((error = alGetError()) != AL_NO_ERROR) | |
2987 { | |
2988 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
|
2989 alGetString(error)); |
0 | 2990 } |
2991 if(AL_PAUSED == state) | |
2992 { | |
2993 /* Count the actual number of channels resumed */ | |
2994 counter++; | |
2995 | |
2996 /* We need to resume the expire time count down */ | |
2997 if(ALmixer_Channel_List[channel].expire_ticks != -1) | |
2998 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
2999 ALmixer_Channel_List[channel].start_time = ALmixer_GetTicks(); |
0 | 3000 } |
3001 /* Do the same as expire time for fading */ | |
3002 if(ALmixer_Channel_List[channel].fade_enabled) | |
3003 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3004 ALmixer_Channel_List[channel].fade_start_time = ALmixer_GetTicks(); |
0 | 3005 } |
3006 | |
3007 alSourcePlay(ALmixer_Channel_List[channel].alsource); | |
3008 if((error = alGetError()) != AL_NO_ERROR) | |
3009 { | |
3010 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3011 alGetString(error) ); |
0 | 3012 retval = -1; |
3013 } | |
3014 } | |
3015 } | |
3016 } | |
3017 /* The user wants to halt all channels */ | |
3018 else | |
3019 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3020 ALint i; |
0 | 3021 for(i=0; i<Number_of_Channels_global; i++) |
3022 { | |
3023 /* only need to process channel if in use */ | |
3024 if(ALmixer_Channel_List[i].channel_in_use) | |
3025 { | |
3026 alGetSourcei( | |
3027 ALmixer_Channel_List[i].alsource, | |
3028 AL_SOURCE_STATE, &state | |
3029 ); | |
3030 if((error = alGetError()) != AL_NO_ERROR) | |
3031 { | |
3032 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
|
3033 alGetString(error)); |
0 | 3034 } |
3035 if(AL_PAUSED == state) | |
3036 { | |
3037 /* Count the actual number of channels resumed */ | |
3038 counter++; | |
3039 | |
3040 /* We need to resume the expire time count down */ | |
3041 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
3042 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3043 ALmixer_Channel_List[i].start_time = ALmixer_GetTicks(); |
0 | 3044 } |
3045 /* Do the same as expire time for fading */ | |
3046 if(ALmixer_Channel_List[i].fade_enabled) | |
3047 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3048 ALmixer_Channel_List[i].fade_start_time = ALmixer_GetTicks(); |
0 | 3049 } |
3050 | |
3051 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
3052 if((error = alGetError()) != AL_NO_ERROR) | |
3053 { | |
3054 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3055 alGetString(error) ); |
0 | 3056 retval = -1; |
3057 } | |
3058 } | |
3059 } | |
3060 } | |
3061 } | |
3062 if(-1 == retval) | |
3063 { | |
3064 return -1; | |
3065 } | |
3066 return counter; | |
3067 } | |
3068 | |
3069 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3070 static ALint Internal_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3071 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3072 ALint channel; |
0 | 3073 if(0 == source) |
3074 { | |
3075 return Internal_ResumeChannel(-1); | |
3076 } | |
3077 | |
3078 channel = Internal_GetChannel(source); | |
3079 if(-1 == channel) | |
3080 { | |
3081 ALmixer_SetError("Cannot resume source: %s", ALmixer_GetError()); | |
3082 return -1; | |
3083 } | |
3084 return Internal_ResumeChannel(channel); | |
3085 } | |
3086 | |
3087 | |
3088 /* Might consider setting eof to 0 as a "feature" | |
3089 * This will allow seek to end to stay there because | |
3090 * Play automatically rewinds if at the end */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3091 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
|
3092 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3093 ALint retval; |
0 | 3094 |
3095 if(NULL == data) | |
3096 { | |
3097 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
|
3098 return AL_FALSE; |
0 | 3099 } |
3100 | |
3101 /* Seek for predecoded files involves moving the chunk pointer around */ | |
3102 if(data->decoded_all) | |
3103 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3104 ALuint byte_position; |
0 | 3105 |
3106 /* OpenAL doesn't seem to like it if I change the buffer | |
3107 * while playing (crashes), so I must require that Seek only | |
3108 * be done when the data is not in use. | |
3109 * Since data may be shared among multiple sources, | |
3110 * I can't shut them down myself, so I have to return an error. | |
3111 */ | |
3112 if(data->in_use) | |
3113 { | |
3114 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
|
3115 return AL_FALSE; |
0 | 3116 } |
3117 #if 0 | |
3118 #if defined(DISABLE_PREDECODED_SEEK) | |
3119 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
|
3120 return AL_FALSE; |
0 | 3121 |
3122 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
3123 /* By default, ALmixer frees the Sound_Sample for predecoded | |
3124 * samples because of the potential memory waste. | |
3125 * However, to seek a sample, we need to have a full | |
3126 * copy of the data around. So the strategy is to | |
3127 * recreate a hackish Sound_Sample to be used for seeking | |
3128 * purposes. If Sound_Sample is NULL, we will reallocate | |
3129 * memory for it and then procede as if everything | |
3130 * was normal. | |
3131 */ | |
3132 if(NULL == data->sample) | |
3133 { | |
3134 if( -1 == Reconstruct_Sound_Sample(data) ) | |
3135 { | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3136 return AL_FALSE; |
0 | 3137 } |
3138 } | |
3139 #endif | |
3140 #endif | |
3141 /* If access_data was set, then we still have the | |
3142 * Sound_Sample and we can move around in the data. | |
3143 * If it was not set, the data has been freed and we | |
3144 * cannot do anything because there is no way to | |
3145 * recover the data because OpenAL won't let us | |
3146 * get access to the buffers | |
3147 */ | |
3148 if(NULL == data->sample) | |
3149 { | |
3150 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
|
3151 return AL_FALSE; |
0 | 3152 } |
3153 | |
3154 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
|
3155 retval = Set_Predecoded_Seek_Position(data, byte_position); |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3156 if(-1 == retval) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3157 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3158 return AL_FALSE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3159 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3160 else |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3161 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3162 return AL_TRUE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3163 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3164 |
0 | 3165 } |
3166 else | |
3167 { | |
3168 /* Reset eof flag?? */ | |
3169 data->eof = 0; | |
3170 retval = Sound_Seek(data->sample, msec); | |
3171 if(0 == retval) | |
3172 { | |
3173 ALmixer_SetError(Sound_GetError()); | |
3174 | |
3175 fprintf(stderr, "Sound seek error: %s\n", ALmixer_GetError()); | |
3176 /* Try rewinding to clean up? */ | |
3177 /* | |
3178 Internal_RewindData(data); | |
3179 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3180 return AL_FALSE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3181 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3182 return AL_TRUE; |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3183 } |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3184 |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
3185 return AL_TRUE; |
0 | 3186 } |
3187 | |
3188 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3189 static ALint Internal_SeekChannel(ALint channel, ALuint msec) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3190 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3191 ALint retval = 0; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3192 ALenum error; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3193 ALint state; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3194 ALint running_count = 0; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3195 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3196 if(0 == msec) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3197 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3198 return Internal_RewindChannel(channel); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3199 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3200 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3201 if(channel >= Number_of_Channels_global) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3202 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3203 ALmixer_SetError("Cannot seek channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3204 return -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3205 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3206 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3207 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3208 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3209 fprintf(stderr, "24Testing error: %s\n", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3210 alGetString(error)); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3211 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3212 /* Clear error */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3213 alGetError(); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3214 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3215 /* If the user specified a specific channel */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3216 if(channel >= 0) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3217 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3218 /* only need to process channel if in use */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3219 if(ALmixer_Channel_List[channel].channel_in_use) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3220 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3221 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3222 /* What should I do? Do I just rewind the channel |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3223 * or also rewind the data? Since the data is |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3224 * shared, let's make it the user's responsibility |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3225 * to rewind the data. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3226 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3227 if(ALmixer_Channel_List[channel].almixer_data->decoded_all) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3228 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3229 /* convert milliseconds to seconds */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3230 ALfloat sec_offset = msec / 1000.0f; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3231 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3232 alGetSourcei( |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3233 ALmixer_Channel_List[channel].alsource, |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3234 AL_SOURCE_STATE, &state |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3235 ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3236 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3237 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3238 fprintf(stderr, "25Testing error: %s\n", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3239 alGetString(error)); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3240 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3241 /* OpenAL seek */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3242 alSourcef(ALmixer_Channel_List[channel].alsource, AL_SEC_OFFSET, sec_offset); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3243 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3244 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3245 ALmixer_SetError("%s", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3246 alGetString(error) ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3247 retval = -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3248 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3249 /* Need to resume playback if it was originally playing */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3250 if(AL_PLAYING == state) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3251 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3252 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3253 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3254 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3255 ALmixer_SetError("%s", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3256 alGetString(error) ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3257 retval = -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3258 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3259 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3260 else if(AL_PAUSED == state) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3261 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3262 /* HACK: The problem is that when paused, after |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3263 * the Rewind, I can't get it off the INITIAL |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3264 * state without restarting |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3265 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3266 alSourcePlay(ALmixer_Channel_List[channel].alsource); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3267 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3268 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3269 fprintf(stderr, "25Testing error: %s\n", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3270 alGetString(error)); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3271 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3272 alSourcePause(ALmixer_Channel_List[channel].alsource); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3273 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3274 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3275 ALmixer_SetError("%s", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3276 alGetString(error) ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3277 retval = -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3278 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3279 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3280 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3281 else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3282 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3283 /* Streamed data is different. Rewinding the channel |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3284 * does no good. Rewinding the data will have an |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3285 * effect, but it will be lagged based on how |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3286 * much data is queued. Recommend users call Halt |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3287 * before rewind if they want immediate results. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3288 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3289 retval = Internal_SeekData(ALmixer_Channel_List[channel].almixer_data, msec); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3290 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3291 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3292 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3293 /* The user wants to rewind all channels */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3294 else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3295 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3296 ALint i; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3297 ALfloat sec_offset = msec / 1000.0f; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3298 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3299 for(i=0; i<Number_of_Channels_global; i++) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3300 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3301 /* only need to process channel if in use */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3302 if(ALmixer_Channel_List[i].channel_in_use) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3303 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3304 /* What should I do? Do I just rewind the channel |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3305 * or also rewind the data? Since the data is |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3306 * shared, let's make it the user's responsibility |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3307 * to rewind the data. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3308 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3309 if(ALmixer_Channel_List[i].almixer_data->decoded_all) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3310 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3311 alGetSourcei( |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3312 ALmixer_Channel_List[i].alsource, |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3313 AL_SOURCE_STATE, &state |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3314 ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3315 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3316 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3317 fprintf(stderr, "26Testing error: %s\n", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3318 alGetString(error)); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3319 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3320 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3321 alSourcef(ALmixer_Channel_List[channel].alsource, AL_SEC_OFFSET, sec_offset); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3322 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3323 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3324 ALmixer_SetError("%s", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3325 alGetString(error) ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3326 retval = -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3327 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3328 /* Need to resume playback if it was originally playing */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3329 if(AL_PLAYING == state) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3330 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3331 alSourcePlay(ALmixer_Channel_List[i].alsource); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3332 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3333 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3334 ALmixer_SetError("%s", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3335 alGetString(error) ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3336 retval = -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3337 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3338 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3339 else if(AL_PAUSED == state) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3340 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3341 /* HACK: The problem is that when paused, after |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3342 * the Rewind, I can't get it off the INITIAL |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3343 * state without restarting |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3344 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3345 alSourcePlay(ALmixer_Channel_List[i].alsource); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3346 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3347 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3348 fprintf(stderr, "27Testing error: %s\n", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3349 alGetString(error)); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3350 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3351 alSourcePause(ALmixer_Channel_List[i].alsource); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3352 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3353 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3354 ALmixer_SetError("%s", |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3355 alGetString(error) ); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3356 retval = -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3357 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3358 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3359 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3360 else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3361 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3362 /* Streamed data is different. Rewinding the channel |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3363 * does no good. Rewinding the data will have an |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3364 * effect, but it will be lagged based on how |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3365 * much data is queued. Recommend users call Halt |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3366 * before rewind if they want immediate results. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3367 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3368 running_count += Internal_SeekData(ALmixer_Channel_List[i].almixer_data, msec); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3369 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3370 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3371 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3372 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3373 if(-1 == retval) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3374 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3375 return -1; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3376 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3377 else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3378 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3379 return running_count; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3380 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3381 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3382 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3383 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3384 static ALint Internal_SeekSource(ALuint source, ALuint msec) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3385 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3386 ALint channel; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3387 if(0 == source) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3388 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3389 return Internal_SeekChannel(-1, msec); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3390 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3391 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3392 channel = Internal_GetChannel(source); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3393 if(-1 == channel) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3394 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3395 ALmixer_SetError("Cannot seek source: %s", ALmixer_GetError()); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3396 return 0; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3397 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3398 return Internal_SeekChannel(channel, msec); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3399 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3400 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
3401 |
0 | 3402 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3403 static ALint Internal_FadeInChannelTimed(ALint channel, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 3404 { |
3405 ALfloat value; | |
3406 ALenum error; | |
3407 ALfloat original_value; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3408 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3409 ALint retval; |
0 | 3410 |
3411 | |
3412 | |
3413 if(channel >= Number_of_Channels_global) | |
3414 { | |
3415 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); | |
3416 return -1; | |
3417 } | |
3418 /* Let's call PlayChannelTimed to do the job. | |
3419 * There are two catches: | |
3420 * First is that we must set the volumes before the play call(s). | |
3421 * Second is that we must initialize the channel values | |
3422 */ | |
3423 | |
3424 if(channel < 0) | |
3425 { | |
3426 /* This might cause a problem for threads/race conditions. | |
3427 * We need to set the volume on an unknown channel, | |
3428 * so we need to request a channel first. Remember | |
3429 * that requesting a channel doesn't lock and it | |
3430 * could be surrendered to somebody else before we claim it. | |
3431 */ | |
3432 channel = Internal_GetChannel(0); | |
3433 if(-1 == channel) | |
3434 { | |
3435 return -1; | |
3436 } | |
3437 } | |
3438 else if(ALmixer_Channel_List[channel].channel_in_use) | |
3439 { | |
3440 ALmixer_SetError("Channel %d is already in use", channel); | |
3441 return -1; | |
3442 } | |
3443 | |
3444 | |
3445 /* Get the original volume in case of a problem */ | |
3446 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
|
3447 AL_GAIN, &original_value); |
0 | 3448 |
3449 if((error = alGetError()) != AL_NO_ERROR) | |
3450 { | |
3451 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
|
3452 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3453 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3454 ALmixer_Channel_List[channel].fade_end_volume = original_value; |
0 | 3455 |
3456 /* Get the Min volume */ | |
3457 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3458 AL_MIN_GAIN, &value); | |
3459 if((error = alGetError()) != AL_NO_ERROR) | |
3460 { | |
3461 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
|
3462 alGetString(error)); |
0 | 3463 } |
3464 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3465 | |
3466 /* Set the actual volume */ | |
3467 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
|
3468 AL_GAIN, value); |
0 | 3469 if((error = alGetError()) != AL_NO_ERROR) |
3470 { | |
3471 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
|
3472 alGetString(error)); |
0 | 3473 } |
3474 | |
3475 | |
3476 /* Now call PlayChannelTimed */ | |
3477 retval = Internal_PlayChannelTimed(channel, data, loops, expire_ticks); | |
3478 if(-1 == retval) | |
3479 { | |
3480 /* Chance of failure is actually pretty high since | |
3481 * a channel might already be in use or streamed | |
3482 * data can be shared | |
3483 */ | |
3484 /* Restore the original value to avoid accidental | |
3485 * distruption of playback | |
3486 */ | |
3487 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
|
3488 AL_GAIN, original_value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3489 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3490 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3491 fprintf(stderr, "38Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3492 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3493 } |
0 | 3494 return retval; |
3495 } | |
3496 | |
3497 /* We can't accept 0 as a value because of div-by-zero. | |
3498 * If zero, just call PlayChannelTimed at normal | |
3499 * volume | |
3500 */ | |
3501 if(0 == fade_ticks) | |
3502 { | |
3503 alSourcef(ALmixer_Channel_List[channel].alsource, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3504 AL_GAIN, |
0 | 3505 ALmixer_Channel_List[channel].fade_end_volume |
3506 ); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3507 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3508 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3509 fprintf(stderr, "39Testing error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3510 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3511 } |
0 | 3512 |
3513 return retval; | |
3514 } | |
3515 | |
3516 /* Enable fading effects via the flag */ | |
3517 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3518 /* Set fade start time */ | |
3519 ALmixer_Channel_List[channel].fade_start_time | |
3520 = ALmixer_Channel_List[channel].start_time; | |
3521 /* Set the fade expire ticks */ | |
3522 ALmixer_Channel_List[channel].fade_expire_ticks = fade_ticks; | |
3523 | |
3524 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3525 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / fade_ticks; | |
3526 | |
3527 return retval; | |
3528 | |
3529 } | |
3530 | |
3531 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3532 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
|
3533 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3534 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3535 ALint retval; |
0 | 3536 if(0 == source) |
3537 { | |
3538 retval = Internal_FadeInChannelTimed(-1, data, loops, fade_ticks, expire_ticks); | |
3539 if(-1 == retval) | |
3540 { | |
3541 return 0; | |
3542 } | |
3543 else | |
3544 { | |
3545 return Internal_GetSource(retval); | |
3546 } | |
3547 } | |
3548 | |
3549 channel = Internal_GetChannel(source); | |
3550 if(-1 == channel) | |
3551 { | |
3552 ALmixer_SetError("Cannot FadeIn source: %s", ALmixer_GetError()); | |
3553 return 0; | |
3554 } | |
3555 retval = Internal_FadeInChannelTimed(channel, data, loops, fade_ticks, expire_ticks); | |
3556 if(-1 == retval) | |
3557 { | |
3558 return 0; | |
3559 } | |
3560 else | |
3561 { | |
3562 return source; | |
3563 } | |
3564 /* make compiler happy */ | |
3565 return 0; | |
3566 } | |
3567 | |
3568 | |
3569 | |
3570 | |
3571 /* Will fade out currently playing channels. | |
3572 * 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
|
3573 static ALint Internal_FadeOutChannel(ALint channel, ALuint ticks) |
0 | 3574 { |
3575 ALfloat value; | |
3576 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3577 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3578 ALuint counter = 0; |
0 | 3579 |
3580 /* We can't accept 0 as a value because of div-by-zero. | |
3581 * If zero, just call Halt at normal | |
3582 * volume | |
3583 */ | |
3584 if(0 == ticks) | |
3585 { | |
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
|
3586 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 3587 } |
3588 | |
3589 | |
3590 if(channel >= Number_of_Channels_global) | |
3591 { | |
3592 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); | |
3593 return -1; | |
3594 } | |
3595 | |
3596 if(channel >= 0) | |
3597 { | |
3598 if(ALmixer_Channel_List[channel].channel_in_use) | |
3599 { | |
3600 /* Get the current volume */ | |
3601 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
|
3602 AL_GAIN, &value); |
0 | 3603 ALmixer_Channel_List[channel].fade_start_volume = value; |
3604 if((error = alGetError()) != AL_NO_ERROR) | |
3605 { | |
3606 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
|
3607 alGetString(error)); |
0 | 3608 } |
3609 | |
3610 /* Get the Min volume */ | |
3611 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
3612 AL_MIN_GAIN, &value); | |
3613 if((error = alGetError()) != AL_NO_ERROR) | |
3614 { | |
3615 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
|
3616 alGetString(error)); |
0 | 3617 } |
3618 ALmixer_Channel_List[channel].fade_end_volume = value; | |
3619 | |
3620 /* Set expire start time */ | |
3621 ALmixer_Channel_List[channel].start_time = current_time; | |
3622 /* Set the expire ticks */ | |
3623 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
3624 /* Set fade start time */ | |
3625 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3626 /* Set the fade expire ticks */ | |
3627 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3628 /* Enable fading effects via the flag */ | |
3629 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3630 | |
3631 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3632 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3633 | |
3634 counter++; | |
3635 } | |
3636 } | |
3637 /* Else need to fade out all channels */ | |
3638 else | |
3639 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3640 ALint i; |
0 | 3641 for(i=0; i<Number_of_Channels_global; i++) |
3642 { | |
3643 if(ALmixer_Channel_List[i].channel_in_use) | |
3644 { | |
3645 /* Get the current volume */ | |
3646 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
|
3647 AL_GAIN, &value); |
0 | 3648 ALmixer_Channel_List[i].fade_start_volume = value; |
3649 if((error = alGetError()) != AL_NO_ERROR) | |
3650 { | |
3651 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
|
3652 alGetString(error)); |
0 | 3653 } |
3654 | |
3655 /* Get the Min volume */ | |
3656 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
3657 AL_MIN_GAIN, &value); | |
3658 if((error = alGetError()) != AL_NO_ERROR) | |
3659 { | |
3660 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
|
3661 alGetString(error)); |
0 | 3662 } |
3663 ALmixer_Channel_List[i].fade_end_volume = value; | |
3664 | |
3665 /* Set expire start time */ | |
3666 ALmixer_Channel_List[i].start_time = current_time; | |
3667 /* Set the expire ticks */ | |
3668 ALmixer_Channel_List[i].expire_ticks = ticks; | |
3669 /* Set fade start time */ | |
3670 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3671 /* Set the fade expire ticks */ | |
3672 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3673 /* Enable fading effects via the flag */ | |
3674 ALmixer_Channel_List[i].fade_enabled = 1; | |
3675 | |
3676 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3677 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3678 | |
3679 counter++; | |
3680 } | |
3681 } /* End for loop */ | |
3682 } | |
3683 return counter; | |
3684 } | |
3685 | |
3686 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3687 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
|
3688 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3689 ALint channel; |
0 | 3690 if(0 == source) |
3691 { | |
3692 return Internal_FadeOutChannel(-1, ticks); | |
3693 } | |
3694 | |
3695 channel = Internal_GetChannel(source); | |
3696 if(-1 == channel) | |
3697 { | |
3698 ALmixer_SetError("Cannot FadeOut source: %s", ALmixer_GetError()); | |
3699 return -1; | |
3700 } | |
3701 return Internal_FadeOutChannel(channel, ticks); | |
3702 } | |
3703 | |
3704 | |
3705 /* Will fade currently playing channels. | |
3706 * It starts at the current volume level and go to target | |
3707 * Only affects channels that are playing | |
3708 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3709 static ALint Internal_FadeChannel(ALint channel, ALuint ticks, ALfloat volume) |
0 | 3710 { |
3711 ALfloat value; | |
3712 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3713 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3714 ALuint counter = 0; |
0 | 3715 |
3716 if(channel >= Number_of_Channels_global) | |
3717 { | |
3718 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); | |
3719 return -1; | |
3720 } | |
3721 | |
3722 if(channel >= 0) | |
3723 { | |
3724 if(volume < ALmixer_Channel_List[channel].min_volume) | |
3725 { | |
3726 volume = ALmixer_Channel_List[channel].min_volume; | |
3727 } | |
3728 else if(volume > ALmixer_Channel_List[channel].max_volume) | |
3729 { | |
3730 volume = ALmixer_Channel_List[channel].max_volume; | |
3731 } | |
3732 | |
3733 if(ALmixer_Channel_List[channel].channel_in_use) | |
3734 { | |
3735 if(ticks > 0) | |
3736 { | |
3737 /* Get the current volume */ | |
3738 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
|
3739 AL_GAIN, &value); |
0 | 3740 if((error = alGetError()) != AL_NO_ERROR) |
3741 { | |
3742 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
|
3743 alGetString(error)); |
0 | 3744 } |
3745 ALmixer_Channel_List[channel].fade_start_volume = value; | |
3746 | |
3747 /* Set the target volume */ | |
3748 ALmixer_Channel_List[channel].fade_end_volume = volume; | |
3749 | |
3750 /* Set fade start time */ | |
3751 ALmixer_Channel_List[channel].fade_start_time = current_time; | |
3752 /* Set the fade expire ticks */ | |
3753 ALmixer_Channel_List[channel].fade_expire_ticks = ticks; | |
3754 /* Enable fading effects via the flag */ | |
3755 ALmixer_Channel_List[channel].fade_enabled = 1; | |
3756 | |
3757 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3758 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks; | |
3759 } | |
3760 else | |
3761 { | |
3762 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
|
3763 AL_GAIN, volume); |
0 | 3764 if((error = alGetError()) != AL_NO_ERROR) |
3765 { | |
3766 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
|
3767 alGetString(error)); |
0 | 3768 } |
3769 } | |
3770 counter++; | |
3771 } | |
3772 } | |
3773 /* Else need to fade out all channels */ | |
3774 else | |
3775 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3776 ALint i; |
0 | 3777 for(i=0; i<Number_of_Channels_global; i++) |
3778 { | |
3779 if(volume < ALmixer_Channel_List[i].min_volume) | |
3780 { | |
3781 volume = ALmixer_Channel_List[i].min_volume; | |
3782 } | |
3783 else if(volume > ALmixer_Channel_List[i].max_volume) | |
3784 { | |
3785 volume = ALmixer_Channel_List[i].max_volume; | |
3786 } | |
3787 | |
3788 if(ALmixer_Channel_List[i].channel_in_use) | |
3789 { | |
3790 if(ticks > 0) | |
3791 { | |
3792 /* Get the current volume */ | |
3793 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
|
3794 AL_GAIN, &value); |
0 | 3795 if((error = alGetError()) != AL_NO_ERROR) |
3796 { | |
3797 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
|
3798 alGetString(error)); |
0 | 3799 } |
3800 ALmixer_Channel_List[i].fade_start_volume = value; | |
3801 | |
3802 /* Set target volume */ | |
3803 ALmixer_Channel_List[i].fade_end_volume = volume; | |
3804 | |
3805 /* Set fade start time */ | |
3806 ALmixer_Channel_List[i].fade_start_time = current_time; | |
3807 /* Set the fade expire ticks */ | |
3808 ALmixer_Channel_List[i].fade_expire_ticks = ticks; | |
3809 /* Enable fading effects via the flag */ | |
3810 ALmixer_Channel_List[i].fade_enabled = 1; | |
3811 | |
3812 /* Set 1/(endtime-starttime) or 1/deltaT */ | |
3813 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks; | |
3814 } | |
3815 else | |
3816 { | |
3817 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
|
3818 AL_GAIN, volume); |
0 | 3819 if((error = alGetError()) != AL_NO_ERROR) |
3820 { | |
3821 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
|
3822 alGetString(error)); |
0 | 3823 } |
3824 } | |
3825 counter++; | |
3826 } | |
3827 } /* End for loop */ | |
3828 } | |
3829 return counter; | |
3830 } | |
3831 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3832 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
|
3833 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3834 ALint channel; |
0 | 3835 if(0 == source) |
3836 { | |
3837 return Internal_FadeChannel(-1, ticks, volume); | |
3838 } | |
3839 | |
3840 channel = Internal_GetChannel(source); | |
3841 if(-1 == channel) | |
3842 { | |
3843 ALmixer_SetError("Cannot Fade source: %s", ALmixer_GetError()); | |
3844 return -1; | |
3845 } | |
3846 return Internal_FadeChannel(channel, ticks, volume); | |
3847 } | |
3848 | |
3849 | |
3850 | |
3851 | |
3852 /* Set a volume regardless if it's in use or not. | |
3853 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3854 static ALboolean Internal_SetVolumeChannel(ALint channel, ALfloat volume) |
0 | 3855 { |
3856 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3857 ALboolean retval = AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3858 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3859 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3860 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3861 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
|
3862 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3863 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3864 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3865 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3866 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3867 if(volume < 0.0f) |
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 volume = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3870 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3871 else if(volume > 1.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3872 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3873 volume = 1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3874 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3875 alSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3876 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3877 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3878 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3879 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3880 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3881 retval = AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3882 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3883 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3884 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3885 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3886 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3887 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
|
3888 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3889 if(volume < 0.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3890 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3891 volume = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3892 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3893 else if(volume > 1.0f) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3894 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3895 volume = 1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3896 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3897 alSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3898 AL_GAIN, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3899 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3900 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3901 ALmixer_SetError("%s", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3902 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3903 retval = AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3904 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3905 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3906 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3907 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3908 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3909 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3910 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
|
3911 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3912 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3913 if(0 == source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3914 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3915 return Internal_SetVolumeChannel(-1, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3916 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3917 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3918 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3919 if(-1 == channel) |
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 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
|
3922 return AL_FALSE; |
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 return Internal_SetVolumeChannel(channel, volume); |
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 |
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 static ALfloat Internal_GetVolumeChannel(ALint channel) |
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 ALfloat value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3931 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3932 ALfloat running_total = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3933 ALfloat retval = 0.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3934 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3935 if(channel >= Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3936 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3937 ALmixer_SetError("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
|
3938 return -1.0f; |
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 if(channel >= 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3942 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3943 alGetSourcef(ALmixer_Channel_List[channel].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3944 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3945 if((error = alGetError()) != AL_NO_ERROR) |
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 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3948 retval = -1.0f; |
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 else |
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 retval = value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3953 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3954 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3955 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3956 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3957 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3958 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
|
3959 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3960 alGetSourcef(ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3961 AL_GAIN, &value); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3962 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3963 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3964 ALmixer_SetError("%s", alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3965 retval = -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3966 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3967 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3968 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3969 running_total += value; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3970 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3971 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3972 if(0 == Number_of_Channels_global) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3973 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3974 ALmixer_SetError("No channels are allocated"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3975 retval = -1.0f; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3976 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3977 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3978 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3979 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
|
3980 } |
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 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3983 } |
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 static ALfloat Internal_GetVolumeSource(ALuint source) |
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 ALint channel; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3988 if(0 == source) |
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 return Internal_GetVolumeChannel(-1); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3991 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3992 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3993 channel = Internal_GetChannel(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3994 if(-1 == channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3995 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
3996 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
|
3997 return -1.0f; |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4000 return Internal_GetVolumeChannel(channel); |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4003 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4004 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4005 /* 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
|
4006 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4007 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
|
4008 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4009 ALenum error; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4010 ALboolean retval = AL_TRUE; |
0 | 4011 |
4012 if(channel >= Number_of_Channels_global) | |
4013 { | |
4014 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
|
4015 return AL_FALSE; |
0 | 4016 } |
4017 | |
4018 if(channel >= 0) | |
4019 { | |
4020 if(volume < 0.0f) | |
4021 { | |
4022 volume = 0.0f; | |
4023 } | |
4024 else if(volume > 1.0f) | |
4025 { | |
4026 volume = 1.0f; | |
4027 } | |
4028 ALmixer_Channel_List[channel].max_volume = volume; | |
4029 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4030 AL_MAX_GAIN, volume); | |
4031 if((error = alGetError()) != AL_NO_ERROR) | |
4032 { | |
4033 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4034 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4035 retval = AL_FALSE; |
0 | 4036 } |
4037 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
4038 { | |
4039 ALmixer_Channel_List[channel].min_volume = volume; | |
4040 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4041 AL_MIN_GAIN, volume); | |
4042 if((error = alGetError()) != AL_NO_ERROR) | |
4043 { | |
4044 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4045 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4046 retval = AL_FALSE; |
0 | 4047 } |
4048 } | |
4049 } | |
4050 else | |
4051 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4052 ALint i; |
0 | 4053 for(i=0; i<Number_of_Channels_global; i++) |
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[i].max_volume = volume; | |
4064 alSourcef(ALmixer_Channel_List[i].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[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
4073 { | |
4074 ALmixer_Channel_List[i].min_volume = volume; | |
4075 alSourcef(ALmixer_Channel_List[i].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 } | |
4086 return retval; | |
4087 } | |
4088 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4089 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
|
4090 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4091 ALint channel; |
0 | 4092 if(0 == source) |
4093 { | |
4094 return Internal_SetMaxVolumeChannel(-1, volume); | |
4095 } | |
4096 | |
4097 channel = Internal_GetChannel(source); | |
4098 if(-1 == channel) | |
4099 { | |
4100 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
|
4101 return AL_FALSE; |
0 | 4102 } |
4103 return Internal_SetMaxVolumeChannel(channel, volume); | |
4104 } | |
4105 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4106 static ALfloat Internal_GetMaxVolumeChannel(ALint channel) |
0 | 4107 { |
4108 /* | |
4109 ALfloat value; | |
4110 ALenum error; | |
4111 */ | |
4112 ALfloat running_total = 0.0f; | |
4113 ALfloat retval = 0.0f; | |
4114 | |
4115 if(channel >= Number_of_Channels_global) | |
4116 { | |
4117 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); | |
4118 return -1.0f; | |
4119 } | |
4120 | |
4121 if(channel >= 0) | |
4122 { | |
4123 /* | |
4124 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
4125 AL_GAIN, &value); | |
4126 if((error = alGetError()) != AL_NO_ERROR) | |
4127 { | |
4128 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4129 alGetString(error) ); |
0 | 4130 retval = -1.0f; |
4131 } | |
4132 else | |
4133 { | |
4134 retval = value; | |
4135 } | |
4136 */ | |
4137 retval = ALmixer_Channel_List[channel].max_volume; | |
4138 | |
4139 } | |
4140 else | |
4141 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4142 ALint i; |
0 | 4143 for(i=0; i<Number_of_Channels_global; i++) |
4144 { | |
4145 /* | |
4146 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
4147 AL_GAIN, &value); | |
4148 if((error = alGetError()) != AL_NO_ERROR) | |
4149 { | |
4150 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4151 alGetString(error) ); |
0 | 4152 retval = -1; |
4153 } | |
4154 else | |
4155 { | |
4156 running_total += value; | |
4157 } | |
4158 */ | |
4159 running_total += ALmixer_Channel_List[i].max_volume; | |
4160 } | |
4161 if(0 == Number_of_Channels_global) | |
4162 { | |
4163 ALmixer_SetError("No channels are allocated"); | |
4164 retval = -1.0f; | |
4165 } | |
4166 else | |
4167 { | |
4168 retval = running_total / Number_of_Channels_global; | |
4169 } | |
4170 } | |
4171 return retval; | |
4172 } | |
4173 | |
4174 static ALfloat Internal_GetMaxVolumeSource(ALuint source) | |
4175 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4176 ALint channel; |
0 | 4177 if(0 == source) |
4178 { | |
4179 return Internal_GetMaxVolumeChannel(-1); | |
4180 } | |
4181 | |
4182 channel = Internal_GetChannel(source); | |
4183 if(-1 == channel) | |
4184 { | |
4185 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
4186 return -1.0f; | |
4187 } | |
4188 | |
4189 return Internal_GetMaxVolumeChannel(channel); | |
4190 } | |
4191 | |
4192 | |
4193 /* Set a volume regardless if it's in use or not. | |
4194 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4195 static ALboolean Internal_SetMinVolumeChannel(ALint channel, ALfloat volume) |
0 | 4196 { |
4197 ALenum error; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4198 ALboolean retval = AL_TRUE; |
0 | 4199 |
4200 if(channel >= Number_of_Channels_global) | |
4201 { | |
4202 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
|
4203 return AL_FALSE; |
0 | 4204 } |
4205 | |
4206 if(channel >= 0) | |
4207 { | |
4208 if(volume < 0.0f) | |
4209 { | |
4210 volume = 0.0f; | |
4211 } | |
4212 else if(volume > 1.0f) | |
4213 { | |
4214 volume = 1.0f; | |
4215 } | |
4216 ALmixer_Channel_List[channel].min_volume = volume; | |
4217 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4218 AL_MIN_GAIN, volume); | |
4219 if((error = alGetError()) != AL_NO_ERROR) | |
4220 { | |
4221 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4222 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4223 retval = AL_FALSE; |
0 | 4224 } |
4225 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume) | |
4226 { | |
4227 ALmixer_Channel_List[channel].max_volume = volume; | |
4228 alSourcef(ALmixer_Channel_List[channel].alsource, | |
4229 AL_MAX_GAIN, volume); | |
4230 if((error = alGetError()) != AL_NO_ERROR) | |
4231 { | |
4232 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4233 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4234 retval = AL_FALSE; |
0 | 4235 } |
4236 } | |
4237 } | |
4238 else | |
4239 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4240 ALint i; |
0 | 4241 for(i=0; i<Number_of_Channels_global; i++) |
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[i].min_volume = volume; | |
4252 alSourcef(ALmixer_Channel_List[i].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[i].max_volume < ALmixer_Channel_List[i].min_volume) | |
4261 { | |
4262 ALmixer_Channel_List[i].max_volume = volume; | |
4263 alSourcef(ALmixer_Channel_List[i].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 } | |
4274 return retval; | |
4275 } | |
4276 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4277 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
|
4278 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4279 ALint channel; |
0 | 4280 if(0 == source) |
4281 { | |
4282 return Internal_SetMinVolumeChannel(-1, volume); | |
4283 } | |
4284 | |
4285 channel = Internal_GetChannel(source); | |
4286 if(-1 == channel) | |
4287 { | |
4288 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
|
4289 return AL_FALSE; |
0 | 4290 } |
4291 return Internal_SetMinVolumeChannel(channel, volume); | |
4292 } | |
4293 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4294 static ALfloat Internal_GetMinVolumeChannel(ALint channel) |
0 | 4295 { |
4296 /* | |
4297 ALfloat value; | |
4298 ALenum error; | |
4299 */ | |
4300 ALfloat running_total = 0.0f; | |
4301 ALfloat retval = 0.0f; | |
4302 | |
4303 if(channel >= Number_of_Channels_global) | |
4304 { | |
4305 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); | |
4306 return -1.0f; | |
4307 } | |
4308 | |
4309 if(channel >= 0) | |
4310 { | |
4311 /* | |
4312 alGetSourcef(ALmixer_Channel_List[channel].alsource, | |
4313 AL_GAIN, &value); | |
4314 if((error = alGetError()) != AL_NO_ERROR) | |
4315 { | |
4316 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4317 alGetString(error) ); |
0 | 4318 retval = -1.0f; |
4319 } | |
4320 else | |
4321 { | |
4322 retval = value; | |
4323 } | |
4324 */ | |
4325 retval = ALmixer_Channel_List[channel].min_volume; | |
4326 | |
4327 } | |
4328 else | |
4329 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4330 ALint i; |
0 | 4331 for(i=0; i<Number_of_Channels_global; i++) |
4332 { | |
4333 /* | |
4334 alGetSourcef(ALmixer_Channel_List[i].alsource, | |
4335 AL_GAIN, &value); | |
4336 if((error = alGetError()) != AL_NO_ERROR) | |
4337 { | |
4338 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4339 alGetString(error) ); |
0 | 4340 retval = -1; |
4341 } | |
4342 else | |
4343 { | |
4344 running_total += value; | |
4345 } | |
4346 */ | |
4347 running_total += ALmixer_Channel_List[i].min_volume; | |
4348 } | |
4349 if(0 == Number_of_Channels_global) | |
4350 { | |
4351 ALmixer_SetError("No channels are allocated"); | |
4352 retval = -1.0f; | |
4353 } | |
4354 else | |
4355 { | |
4356 retval = running_total / Number_of_Channels_global; | |
4357 } | |
4358 } | |
4359 return retval; | |
4360 } | |
4361 | |
4362 static ALfloat Internal_GetMinVolumeSource(ALuint source) | |
4363 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4364 ALint channel; |
0 | 4365 if(0 == source) |
4366 { | |
4367 return Internal_GetMinVolumeChannel(-1); | |
4368 } | |
4369 | |
4370 channel = Internal_GetChannel(source); | |
4371 if(-1 == channel) | |
4372 { | |
4373 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError()); | |
4374 return -1.0f; | |
4375 } | |
4376 | |
4377 return Internal_GetMinVolumeChannel(channel); | |
4378 } | |
4379 | |
4380 | |
4381 /* Changes the listener volume */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4382 static ALboolean Internal_SetMasterVolume(ALfloat volume) |
0 | 4383 { |
4384 ALenum error; | |
4385 alListenerf(AL_GAIN, volume); | |
4386 if((error = alGetError()) != AL_NO_ERROR) | |
4387 { | |
4388 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4389 alGetString(error) ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4390 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4391 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4392 return AL_TRUE; |
0 | 4393 } |
4394 | |
4395 static ALfloat Internal_GetMasterVolume() | |
4396 { | |
4397 ALenum error; | |
4398 ALfloat volume; | |
4399 alGetListenerf(AL_GAIN, &volume); | |
4400 if((error = alGetError()) != AL_NO_ERROR) | |
4401 { | |
4402 ALmixer_SetError("%s", | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4403 alGetString(error) ); |
0 | 4404 return -1.0f; |
4405 } | |
4406 return volume; | |
4407 } | |
4408 | |
4409 | |
4410 | |
4411 | |
4412 /* Will fade out currently playing channels. | |
4413 * 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
|
4414 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
|
4415 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4416 ALuint current_time = ALmixer_GetTicks(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4417 ALuint counter = 0; |
0 | 4418 |
4419 /* We can't accept 0 as a value because of div-by-zero. | |
4420 * If zero, just call Halt at normal | |
4421 * volume | |
4422 */ | |
4423 if(0 == ticks) | |
4424 { | |
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
|
4425 return Internal_HaltChannel(channel, AL_FALSE); |
0 | 4426 } |
4427 if(ticks < -1) | |
4428 { | |
4429 ticks = -1; | |
4430 } | |
4431 | |
4432 | |
4433 if(channel >= Number_of_Channels_global) | |
4434 { | |
4435 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); | |
4436 return -1; | |
4437 } | |
4438 | |
4439 if(channel >= 0) | |
4440 { | |
4441 if(ALmixer_Channel_List[channel].channel_in_use) | |
4442 { | |
4443 /* Set expire start time */ | |
4444 ALmixer_Channel_List[channel].start_time = current_time; | |
4445 /* Set the expire ticks */ | |
4446 ALmixer_Channel_List[channel].expire_ticks = ticks; | |
4447 | |
4448 counter++; | |
4449 } | |
4450 } | |
4451 /* Else need to fade out all channels */ | |
4452 else | |
4453 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4454 ALint i; |
0 | 4455 for(i=0; i<Number_of_Channels_global; i++) |
4456 { | |
4457 if(ALmixer_Channel_List[i].channel_in_use) | |
4458 { | |
4459 /* Set expire start time */ | |
4460 ALmixer_Channel_List[i].start_time = current_time; | |
4461 /* Set the expire ticks */ | |
4462 ALmixer_Channel_List[i].expire_ticks = ticks; | |
4463 | |
4464 counter++; | |
4465 } | |
4466 } /* End for loop */ | |
4467 } | |
4468 return counter; | |
4469 } | |
4470 | |
4471 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4472 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
|
4473 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4474 ALint channel; |
0 | 4475 if(0 == source) |
4476 { | |
4477 return Internal_ExpireChannel(-1, ticks); | |
4478 } | |
4479 | |
4480 channel = Internal_GetChannel(source); | |
4481 if(-1 == channel) | |
4482 { | |
4483 ALmixer_SetError("Cannot Expire source: %s", ALmixer_GetError()); | |
4484 return -1; | |
4485 } | |
4486 return Internal_ExpireChannel(channel, ticks); | |
4487 } | |
4488 | |
4489 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4490 static ALint Internal_QueryChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4491 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4492 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4493 ALint counter = 0; |
0 | 4494 if(channel >= Number_of_Channels_global) |
4495 { | |
4496 ALmixer_SetError("Invalid channel: %d", channel); | |
4497 return -1; | |
4498 } | |
4499 | |
4500 if(channel >= 0) | |
4501 { | |
4502 return ALmixer_Channel_List[channel].channel_in_use; | |
4503 } | |
4504 | |
4505 /* Else, return the number of channels in use */ | |
4506 for(i=0; i<Number_of_Channels_global; i++) | |
4507 { | |
4508 if(ALmixer_Channel_List[i].channel_in_use) | |
4509 { | |
4510 counter++; | |
4511 } | |
4512 } | |
4513 return counter; | |
4514 } | |
4515 | |
4516 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4517 static ALint Internal_QuerySource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4518 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4519 ALint channel; |
0 | 4520 if(0 == source) |
4521 { | |
4522 return Internal_QueryChannel(-1); | |
4523 } | |
4524 | |
4525 channel = Internal_GetChannel(source); | |
4526 if(-1 == channel) | |
4527 { | |
4528 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4529 return -1; | |
4530 } | |
4531 | |
4532 return Internal_QueryChannel(channel); | |
4533 } | |
4534 | |
4535 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4536 static ALuint Internal_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4537 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4538 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4539 ALuint counter = 0; |
0 | 4540 |
4541 | |
4542 /* Else, return the number of channels in use */ | |
4543 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4544 { | |
4545 if(ALmixer_Channel_List[i].channel_in_use) | |
4546 { | |
4547 counter++; | |
4548 } | |
4549 } | |
4550 return counter; | |
4551 } | |
4552 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4553 static ALuint Internal_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4554 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4555 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4556 ALuint counter = 0; |
0 | 4557 |
4558 | |
4559 /* Else, return the number of channels in use */ | |
4560 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++) | |
4561 { | |
4562 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4563 { | |
4564 counter++; | |
4565 } | |
4566 } | |
4567 return counter; | |
4568 } | |
4569 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4570 static ALuint Internal_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4571 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4572 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4573 ALuint counter = 0; |
0 | 4574 |
4575 | |
4576 /* Else, return the number of channels in use */ | |
4577 for(i=0; i<Number_of_Channels_global; i++) | |
4578 { | |
4579 if(ALmixer_Channel_List[i].channel_in_use) | |
4580 { | |
4581 counter++; | |
4582 } | |
4583 } | |
4584 return counter; | |
4585 } | |
4586 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4587 static ALuint Internal_CountAllFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4588 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4589 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4590 ALuint counter = 0; |
0 | 4591 |
4592 | |
4593 /* Else, return the number of channels in use */ | |
4594 for(i=0; i<Number_of_Channels_global; i++) | |
4595 { | |
4596 if( ! ALmixer_Channel_List[i].channel_in_use) | |
4597 { | |
4598 counter++; | |
4599 } | |
4600 } | |
4601 return counter; | |
4602 } | |
4603 | |
4604 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4605 static ALint Internal_PlayingChannel(ALint channel) |
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 ALint counter = 0; |
0 | 4609 ALint state; |
4610 | |
4611 if(channel >= Number_of_Channels_global) | |
4612 { | |
4613 ALmixer_SetError("Invalid channel: %d", channel); | |
4614 return -1; | |
4615 } | |
4616 | |
4617 if(channel >= 0) | |
4618 { | |
4619 if(ALmixer_Channel_List[channel].channel_in_use) | |
4620 { | |
4621 alGetSourcei( | |
4622 ALmixer_Channel_List[channel].alsource, | |
4623 AL_SOURCE_STATE, &state | |
4624 ); | |
4625 if(AL_PLAYING == state) | |
4626 { | |
4627 return 1; | |
4628 } | |
4629 } | |
4630 return 0; | |
4631 } | |
4632 | |
4633 /* Else, return the number of channels in use */ | |
4634 for(i=0; i<Number_of_Channels_global; i++) | |
4635 { | |
4636 if(ALmixer_Channel_List[i].channel_in_use) | |
4637 { | |
4638 alGetSourcei( | |
4639 ALmixer_Channel_List[i].alsource, | |
4640 AL_SOURCE_STATE, &state | |
4641 ); | |
4642 if(AL_PLAYING == state) | |
4643 { | |
4644 counter++; | |
4645 } | |
4646 } | |
4647 } | |
4648 return counter; | |
4649 } | |
4650 | |
4651 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4652 static ALint Internal_PlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4653 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4654 ALint channel; |
0 | 4655 if(0 == source) |
4656 { | |
4657 return Internal_PlayingChannel(-1); | |
4658 } | |
4659 | |
4660 channel = Internal_GetChannel(source); | |
4661 if(-1 == channel) | |
4662 { | |
4663 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4664 return -1; | |
4665 } | |
4666 | |
4667 return Internal_PlayingChannel(channel); | |
4668 } | |
4669 | |
4670 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4671 static ALint Internal_PausedChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4672 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4673 ALint i; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4674 ALint counter = 0; |
0 | 4675 ALint state; |
4676 | |
4677 if(channel >= Number_of_Channels_global) | |
4678 { | |
4679 ALmixer_SetError("Invalid channel: %d", channel); | |
4680 return -1; | |
4681 } | |
4682 | |
4683 if(channel >= 0) | |
4684 { | |
4685 if(ALmixer_Channel_List[channel].channel_in_use) | |
4686 { | |
4687 alGetSourcei( | |
4688 ALmixer_Channel_List[channel].alsource, | |
4689 AL_SOURCE_STATE, &state | |
4690 ); | |
4691 if(AL_PAUSED == state) | |
4692 { | |
4693 return 1; | |
4694 } | |
4695 } | |
4696 return 0; | |
4697 } | |
4698 | |
4699 /* Else, return the number of channels in use */ | |
4700 for(i=0; i<Number_of_Channels_global; i++) | |
4701 { | |
4702 if(ALmixer_Channel_List[i].channel_in_use) | |
4703 { | |
4704 alGetSourcei( | |
4705 ALmixer_Channel_List[i].alsource, | |
4706 AL_SOURCE_STATE, &state | |
4707 ); | |
4708 if(AL_PAUSED == state) | |
4709 { | |
4710 counter++; | |
4711 } | |
4712 } | |
4713 } | |
4714 return counter; | |
4715 } | |
4716 | |
4717 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4718 static ALint Internal_PausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4719 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4720 ALint channel; |
0 | 4721 if(0 == source) |
4722 { | |
4723 return Internal_PausedChannel(-1); | |
4724 } | |
4725 | |
4726 channel = Internal_GetChannel(source); | |
4727 if(-1 == channel) | |
4728 { | |
4729 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError()); | |
4730 return -1; | |
4731 } | |
4732 | |
4733 return Internal_PausedChannel(channel); | |
4734 } | |
4735 | |
4736 | |
4737 | |
4738 | |
4739 | |
4740 | |
4741 /* Private function for Updating ALmixer. | |
4742 * This is a very big and ugly function. | |
4743 * It should return the number of buffers that were | |
4744 * queued during the call. The value might be | |
4745 * used to guage how long you might wait to | |
4746 * call the next update loop in case you are worried | |
4747 * about preserving CPU cycles. The idea is that | |
4748 * when a buffer is queued, there was probably some | |
4749 * CPU intensive looping which took awhile. | |
4750 * 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
|
4751 * Timing the call with ALmixer_GetTicks() would produce |
0 | 4752 * more accurate information. |
4753 * Returns a negative value if there was an error, | |
4754 * the value being the number of errors. | |
4755 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4756 static ALint Update_ALmixer(void* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4757 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4758 ALint retval = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4759 ALint error_flag = 0; |
0 | 4760 ALenum error; |
4761 ALint state; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4762 ALint i=0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4763 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4764 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4765 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4766 #endif |
0 | 4767 if(0 == ALmixer_Initialized) |
4768 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4769 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4770 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4771 #endif |
0 | 4772 return 0; |
4773 } | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4774 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4775 /* Bypass if in interruption event */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4776 if(NULL == alcGetCurrentContext()) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4777 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4778 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4779 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4780 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4781 return 0; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4782 } |
0 | 4783 |
4784 /* Check the quick flag to see if anything needs updating */ | |
4785 /* If anything is playing, then we have to do work */ | |
4786 if( 0 == Is_Playing_global) | |
4787 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4788 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4789 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4790 #endif |
0 | 4791 return 0; |
4792 } | |
4793 /* Clear error */ | |
4794 if((error = alGetError()) != AL_NO_ERROR) | |
4795 { | |
4796 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
|
4797 alGetString(error)); |
0 | 4798 } |
4799 alGetError(); | |
4800 | |
4801 for(i=0; i<Number_of_Channels_global; i++) | |
4802 { | |
4803 if( ALmixer_Channel_List[i].channel_in_use ) | |
4804 { | |
4805 | |
4806 /* For simplicity, before we do anything else, | |
4807 * we can check the timeout and fading values | |
4808 * and do the appropriate things | |
4809 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4810 ALuint current_time = ALmixer_GetTicks(); |
0 | 4811 |
4812 /* Check to see if we need to halt due to Timed play */ | |
4813 if(ALmixer_Channel_List[i].expire_ticks != -1) | |
4814 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4815 ALuint target_time = (ALuint)ALmixer_Channel_List[i].expire_ticks |
0 | 4816 + ALmixer_Channel_List[i].start_time; |
4817 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4818 AL_SOURCE_STATE, &state); | |
4819 if((error = alGetError()) != AL_NO_ERROR) | |
4820 { | |
4821 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
|
4822 alGetString(error)); |
0 | 4823 } |
4824 | |
4825 /* Check the time, and also make sure that it is not | |
4826 * paused (if paused, we don't want to make the | |
4827 * evaluation because when resumed, we will adjust | |
4828 * the times to compensate for the pause). | |
4829 */ | |
4830 if( (current_time >= target_time) | |
4831 && (state != AL_PAUSED) ) | |
4832 { | |
4833 /* 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
|
4834 Internal_HaltChannel(i, AL_FALSE); |
0 | 4835 if((error = alGetError()) != AL_NO_ERROR) |
4836 { | |
4837 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
|
4838 alGetString(error)); |
0 | 4839 } |
4840 | |
4841 /* Everything should be done so go on to the next loop */ | |
4842 continue; | |
4843 } | |
4844 } /* End if time expired check */ | |
4845 | |
4846 /* Check to see if we need to adjust the volume for fading */ | |
4847 if( ALmixer_Channel_List[i].fade_enabled ) | |
4848 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4849 ALuint target_time = ALmixer_Channel_List[i].fade_expire_ticks |
0 | 4850 + ALmixer_Channel_List[i].fade_start_time; |
4851 alGetSourcei(ALmixer_Channel_List[i].alsource, | |
4852 AL_SOURCE_STATE, &state); | |
4853 if((error = alGetError()) != AL_NO_ERROR) | |
4854 { | |
4855 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
|
4856 alGetString(error)); |
0 | 4857 } |
4858 | |
4859 /* Check the time, and also make sure that it is not | |
4860 * paused (if paused, we don't want to make the | |
4861 * evaluation because when resumed, we will adjust | |
4862 * the times to compensate for the pause). | |
4863 */ | |
4864 if(state != AL_PAUSED) | |
4865 { | |
4866 ALfloat t; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
4867 ALuint delta_time; |
0 | 4868 ALfloat current_volume; |
4869 if(current_time >= target_time) | |
4870 { | |
4871 /* Need to constrain value to the end time | |
4872 * (can't go pass the value for calculations) | |
4873 */ | |
4874 current_time = target_time; | |
4875 /* We can disable the fade flag now */ | |
4876 ALmixer_Channel_List[i].fade_enabled = 0; | |
4877 } | |
4878 /* Use the linear interpolation formula: | |
4879 * X = (1-t)x0 + tx1 | |
4880 * where x0 would be the start value | |
4881 * and x1 is the final value | |
4882 * and t is delta_time*inv_time (adjusts 0 <= time <= 1) | |
4883 * delta_time = current_time-start_time | |
4884 * inv_time = 1/ (end_time-start_time) | |
4885 * so t = current_time-start_time / (end_time-start_time) | |
4886 * | |
4887 */ | |
4888 delta_time = current_time - ALmixer_Channel_List[i].fade_start_time; | |
4889 t = (ALfloat) delta_time * ALmixer_Channel_List[i].fade_inv_time; | |
4890 current_volume = (1.0f-t) * ALmixer_Channel_List[i].fade_start_volume | |
4891 + t * ALmixer_Channel_List[i].fade_end_volume; | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4892 /* |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
4893 fprintf(stderr, "start_vol=%f, end_vol:%f, current_volume: %f\n", ALmixer_Channel_List[i].fade_start_volume, ALmixer_Channel_List[i].fade_end_volume, current_volume); |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
4894 */ |
0 | 4895 /* Set the volume */ |
4896 alSourcef(ALmixer_Channel_List[i].alsource, | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
4897 AL_GAIN, current_volume); |
0 | 4898 if((error = alGetError()) != AL_NO_ERROR) |
4899 { | |
4900 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
|
4901 alGetString(error)); |
0 | 4902 } |
4903 | |
4904 /* | |
4905 fprintf(stderr, "Current time =%d\n", current_time); | |
4906 fprintf(stderr, "Current vol=%f on channel %d\n", current_volume, i); | |
4907 */ | |
4908 } /* End if not PAUSED */ | |
4909 } /* End if fade_enabled */ | |
4910 | |
4911 | |
4912 /* Okay, now that the time expired and fading stuff | |
4913 * is done, do the rest of the hard stuff | |
4914 */ | |
4915 | |
4916 | |
4917 /* For predecoded, check to see if done */ | |
4918 if( ALmixer_Channel_List[i].almixer_data->decoded_all ) | |
4919 { | |
4920 | |
4921 #if 0 | |
4922 /********* Remove this **********/ | |
4923 ALint buffers_processed; | |
4924 ALint buffers_still_queued; | |
4925 fprintf(stderr, "For Predecoded\n"); | |
4926 | |
4927 alGetSourcei( | |
4928 ALmixer_Channel_List[i].alsource, | |
4929 AL_SOURCE_STATE, &state | |
4930 ); | |
4931 switch(state) { | |
4932 case AL_PLAYING: | |
4933 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
4934 break; | |
4935 case AL_PAUSED: | |
4936 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
4937 break; | |
4938 case AL_STOPPED: | |
4939 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
4940 break; | |
4941 case AL_INITIAL: | |
4942 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
4943 break; | |
4944 default: | |
4945 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
4946 break; | |
4947 } | |
4948 | |
4949 alGetSourcei( | |
4950 ALmixer_Channel_List[i].alsource, | |
4951 AL_BUFFERS_PROCESSED, &buffers_processed | |
4952 ); | |
4953 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
4954 | |
4955 alGetSourcei( | |
4956 ALmixer_Channel_List[i].alsource, | |
4957 AL_BUFFERS_QUEUED, &buffers_still_queued | |
4958 ); | |
4959 | |
4960 /******** END REMOVE *******/ | |
4961 #endif | |
4962 /* FIXME: Ugh! Somewhere an alError is being thrown ("Invalid Enum Value"), but I can't | |
4963 * find it. It only seems to be thrown for OS X. I placed error messages after every al* | |
4964 * command I could find in the above loops, but the error doesn't seem to show | |
4965 * up until around here. I mistook it for a get queued buffers | |
4966 * error in OS X. I don't think there's an error down there. | |
4967 * For now, I'm clearing the error here. | |
4968 */ | |
4969 | |
4970 if((error = alGetError()) != AL_NO_ERROR) | |
4971 { | |
4972 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
|
4973 alGetString(error)); |
0 | 4974 } |
4975 | |
4976 | |
4977 alGetSourcei( | |
4978 ALmixer_Channel_List[i].alsource, | |
4979 AL_SOURCE_STATE, &state | |
4980 ); | |
4981 if((error = alGetError()) != AL_NO_ERROR) | |
4982 { | |
4983 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
|
4984 alGetString(error)); |
0 | 4985 } |
4986 | |
4987 | |
4988 if(AL_STOPPED == state) | |
4989 { | |
4990 /* Playback has ended. | |
4991 * Loop if necessary, or launch callback | |
4992 * and clear channel (or clear channel and | |
4993 * then launch callback?) | |
4994 */ | |
4995 | |
4996 | |
4997 /* Need to check for loops */ | |
4998 if(ALmixer_Channel_List[i].loops != 0) | |
4999 { | |
5000 /* Corner Case: If the buffer has | |
5001 * been modified using Seek, | |
5002 * the loop will start at the seek | |
5003 * position. | |
5004 */ | |
5005 if(ALmixer_Channel_List[i].loops != -1) | |
5006 { | |
5007 ALmixer_Channel_List[i].loops--; | |
5008 } | |
5009 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5010 if((error = alGetError()) != AL_NO_ERROR) | |
5011 { | |
5012 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
|
5013 alGetString(error)); |
0 | 5014 } |
5015 continue; | |
5016 } | |
5017 /* No loops. End play. */ | |
5018 else | |
5019 { | |
5020 /* Problem: It seems that when mixing | |
5021 * streamed and predecoded sources, | |
5022 * the previous instance lingers, | |
5023 * so we need to force remove | |
5024 * the data from the source. | |
5025 * The sharing problem | |
5026 * occurs when a previous predecoded buffer is played on | |
5027 * a source, and then a streamed source is played later | |
5028 * on that same source. OpenAL isn't consistently | |
5029 * removing the previous buffer so both get played. | |
5030 * (Different dists seem to have different quirks. | |
5031 * The problem might lead to crashes in the worst case.) | |
5032 */ | |
5033 /* Additional problem: There is another | |
5034 * inconsistency among OpenAL distributions. | |
5035 * Both Loki and Creative Windows seem to keep | |
5036 * the buffer queued which requires removing. | |
5037 * But the Creative Macintosh version does | |
5038 * not have any buffer queued after play | |
5039 * and it returns the error: Invalid Enum Value | |
5040 * if I try to unqueue it. | |
5041 * So I'm going to put in a check to see if I | |
5042 * can detect any buffers queued first | |
5043 * and then unqueue them if I can see them. | |
5044 * Additional note: The new CoreAudio based | |
5045 * implementation leaves it's buffer queued | |
5046 * like Loki and Creative Windows. But | |
5047 * considering all the problems I'm having | |
5048 * with the different distributions, this | |
5049 * check seems reasonable. | |
5050 */ | |
5051 ALint buffers_still_queued; | |
5052 if((error = alGetError()) != AL_NO_ERROR) | |
5053 { | |
5054 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
|
5055 alGetString(error)); |
0 | 5056 } |
5057 | |
5058 alGetSourcei( | |
5059 ALmixer_Channel_List[i].alsource, | |
5060 AL_BUFFERS_QUEUED, &buffers_still_queued | |
5061 ); | |
5062 if((error = alGetError()) != AL_NO_ERROR) | |
5063 { | |
5064 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
|
5065 alGetString(error)); |
0 | 5066 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
|
5067 alGetString(error) ); |
0 | 5068 error_flag--; |
5069 } | |
5070 if(buffers_still_queued > 0) | |
5071 { | |
1 | 5072 |
5073 #if 0 /* This triggers an error in OS X Core Audio. */ | |
5074 alSourceUnqueueBuffers( | |
5075 ALmixer_Channel_List[i].alsource, | |
5076 1, | |
5077 ALmixer_Channel_List[i].almixer_data->buffer | |
5078 ); | |
5079 #else | |
5080 /* fprintf(stderr, "In the Bob Aron section...about to clear source\n"); | |
0 | 5081 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 5082 */ |
0 | 5083 /* Rather than force unqueuing the buffer, let's see if |
5084 * setting the buffer to none works (the OpenAL 1.0 | |
5085 * Reference Annotation suggests this should work). | |
5086 */ | |
5087 alSourcei(ALmixer_Channel_List[i].alsource, | |
5088 AL_BUFFER, AL_NONE); | |
5089 /* | |
5090 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5091 */ | |
1 | 5092 #endif |
0 | 5093 if((error = alGetError()) != AL_NO_ERROR) |
5094 { | |
5095 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
|
5096 alGetString(error)); |
0 | 5097 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
|
5098 alGetString(error) ); |
0 | 5099 error_flag--; |
5100 } | |
5101 | |
5102 } | |
5103 | |
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
|
5104 /* 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
|
5105 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
|
5106 |
0 | 5107 Clean_Channel(i); |
5108 /* Subtract counter */ | |
5109 Is_Playing_global--; | |
5110 | |
5111 | |
5112 /* We're done for this loop. | |
5113 * Go to next channel | |
5114 */ | |
5115 continue; | |
5116 } | |
5117 continue; | |
5118 } | |
5119 } /* End if decoded_all */ | |
5120 /* For streamed */ | |
5121 else | |
5122 { | |
5123 ALint buffers_processed; | |
5124 ALint buffers_still_queued; | |
5125 ALint current_buffer_id; | |
5126 | |
5127 ALuint unqueued_buffer_id; | |
5128 #if 0 | |
5129 /********* Remove this **********/ | |
5130 fprintf(stderr, "For Streamed\n"); | |
5131 | |
5132 alGetSourcei( | |
5133 ALmixer_Channel_List[i].alsource, | |
5134 AL_SOURCE_STATE, &state | |
5135 ); | |
5136 switch(state) { | |
5137 case AL_PLAYING: | |
5138 fprintf(stderr, "Channel '%d' is PLAYING\n", i); | |
5139 break; | |
5140 case AL_PAUSED: | |
5141 fprintf(stderr, "Channel '%d' is PAUSED\n",i); | |
5142 break; | |
5143 case AL_STOPPED: | |
5144 fprintf(stderr, "Channel '%d' is STOPPED\n",i); | |
5145 break; | |
5146 case AL_INITIAL: | |
5147 fprintf(stderr, "Channel '%d' is INITIAL\n",i); | |
5148 break; | |
5149 default: | |
5150 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i); | |
5151 break; | |
5152 } | |
5153 /******** END REMOVE *******/ | |
5154 #endif | |
5155 /* Get the number of buffers still queued */ | |
5156 alGetSourcei( | |
5157 ALmixer_Channel_List[i].alsource, | |
5158 AL_BUFFERS_QUEUED, &buffers_still_queued | |
5159 ); | |
5160 if((error = alGetError()) != AL_NO_ERROR) | |
5161 { | |
5162 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
|
5163 alGetString(error)); |
0 | 5164 } |
5165 /* Get the number of buffers processed | |
5166 * so we know if we need to refill | |
5167 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5168 /* 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
|
5169 * 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
|
5170 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5171 // fprintf(stderr, "calling AL_BUFFERS_PROCESSED on source:%d", ALmixer_Channel_List[i].alsource); |
0 | 5172 alGetSourcei( |
5173 ALmixer_Channel_List[i].alsource, | |
5174 AL_BUFFERS_PROCESSED, &buffers_processed | |
5175 ); | |
5176 if((error = alGetError()) != AL_NO_ERROR) | |
5177 { | |
5178 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
|
5179 alGetString(error)); |
0 | 5180 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5181 // fprintf(stderr, "finished AL_BUFFERS_PROCESSED, buffers_processed=%d", buffers_processed); |
0 | 5182 |
5183 /* WTF!!! The Nvidia distribution is failing on the alGetSourcei(source, AL_BUFFER, buf_id) call. | |
5184 * I need this call to figure out which buffer OpenAL is currently playing. | |
5185 * It keeps returning an "Invalid Enum" error. | |
5186 * This is totally inane! It's a basic query. | |
5187 * By the spec, this functionality is not explicitly defined so Nvidia refuses to | |
5188 * fix this behavior, even though all other distributions work fine with this. | |
5189 * The only workaround for this is for | |
5190 * a significant rewrite of my code which requires me to | |
5191 * duplicate the OpenAL queued buffers state with my own | |
5192 * code and try to derive what the current playing buffer is by indirect observation of | |
5193 * looking at buffers_processed. But of course this has a ton of downsides since my | |
5194 * queries do not give me perfect timing of what OpenAL is actually doing and | |
5195 * the fact that some of the distributions seem to have buffer queuing problems | |
5196 * with their query results (CoreAudio). This also means a ton of extra code | |
5197 * on my side. The lack of support of a 1 line call has required me to | |
5198 * implement yet another entire state machine. <sigh> | |
5199 */ | |
5200 #if 0 /* This code will not work until possibly OpenAL 1.1 because of Nvidia */ | |
5201 /* Get the id to the current buffer playing */ | |
5202 alGetSourcei( | |
5203 ALmixer_Channel_List[i].alsource, | |
5204 AL_BUFFER, ¤t_buffer_id | |
5205 ); | |
5206 if((error = alGetError()) != AL_NO_ERROR) | |
5207 { | |
5208 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
|
5209 alGetString(error)); |
0 | 5210 } |
5211 | |
5212 /* Before the hard stuff, check to see if the | |
5213 * current queued AL buffer has changed. | |
5214 * If it has, we should launch a data callback if | |
5215 * necessary | |
5216 */ | |
5217 if( ((ALuint)current_buffer_id) != | |
5218 ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5219 { | |
5220 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5221 = (ALuint)current_buffer_id; | |
5222 | |
5223 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5224 } | |
5225 #else | |
5226 /* Only do this if "access_data" was requested (i.e. the circular_buffer!=NULL) | |
5227 * And if one of the two are true: | |
5228 * Either buffers_processed > 0 (because the current_buffer might have changed) | |
5229 * or if the current_buffer==0 (because we are in an initial state or recovering from | |
5230 * a buffer underrun) | |
5231 */ | |
5232 if((ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5233 && ( | |
5234 (buffers_processed > 0) || (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) | |
5235 ) | |
5236 ) | |
5237 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5238 ALint k; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5239 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5240 ALubyte is_out_of_sync = 0; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5241 ALuint my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
1 | 5242 /* Ugh, I have to deal with signed/unsigned mismatch here. */ |
5243 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
|
5244 ALuint unplayed_buffers; |
1 | 5245 if(buffers_unplayed_int < 0) |
5246 { | |
5247 unplayed_buffers = 0; | |
5248 } | |
5249 else | |
5250 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5251 unplayed_buffers = (ALuint)buffers_unplayed_int; |
1 | 5252 } |
0 | 5253 /* |
5254 fprintf(stderr, "Queue in processed check, before pop, buffers_processed=%d\n", buffers_processed); | |
5255 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5256 */ | |
5257 /* We can't make any determinations solely based on the number of buffers_processed | |
5258 * because currently, we only unqueue 1 buffer per loop. That means if 2 or more | |
5259 * buffers became processed in one loop, the following loop, we would have | |
5260 * at least that_many-1 buffers_processed (plus possible new processed). | |
5261 * If we tried to just remove 1 buffer from our queue, we would be incorrect | |
5262 * because we would not actually reflect the current playing buffer. | |
5263 * So the solution seems to be to make sure our queue is the same size | |
5264 * as the number of buffers_queued-buffers_processed, and return the head of our queue | |
5265 * as the current playing buffer. | |
5266 */ | |
5267 /* Also, we have a corner case. When we first start playing or if we have | |
5268 * a buffer underrun, we have not done a data callback. | |
5269 * In this case, we need to see if there is any new data in our queue | |
5270 * and if so, launch that data callback. | |
5271 */ | |
5272 /* Warning, this code risks the possibility of no data callback being fired if | |
5273 * the system is really late (or skipped buffers). | |
5274 */ | |
5275 | |
5276 /* First, let's syncronize our queue with the OpenAL queue */ | |
5277 #if 0 | |
5278 fprintf(stderr, "inside, Buffers processed=%d, Buffers queued=%d, my queue=%d\n", | |
5279 buffers_processed, buffers_still_queued, my_queue_size); | |
1 | 5280 #endif |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5281 is_out_of_sync = 1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5282 for(k=0; k<buffers_processed; k++) |
0 | 5283 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5284 queue_ret_flag = CircularQueueUnsignedInt_PopFront( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5285 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
|
5286 if(0 == queue_ret_flag) |
0 | 5287 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5288 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
|
5289 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5290 } |
0 | 5291 my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); |
5292 /* We have several possibilities we need to handle: | |
5293 * 1) We are in an initial state or underrun and need to do a data callback on the head. | |
5294 * 2) We were out of sync and need to do a new data callback on the new head. | |
5295 * 3) We were not out of sync but just had left over processed buffers which caused us to | |
5296 * fall in this block of code. (Don't do anything.) | |
5297 */ | |
5298 if( (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) || (1 == is_out_of_sync) ) | |
5299 { | |
5300 if(my_queue_size > 0) | |
5301 { | |
5302 current_buffer_id = CircularQueueUnsignedInt_Front( | |
5303 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5304 if(0 == current_buffer_id) | |
5305 { | |
5306 fprintf(stderr, "53a Internal Error, current_buffer_id=0 when it shouldn't be 0\n"); | |
5307 } | |
5308 /* | |
5309 else | |
5310 { | |
5311 fprintf(stderr, "Queue in processed check, after pop\n"); | |
5312 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5313 } | |
5314 */ | |
5315 ALmixer_Channel_List[i].almixer_data->current_buffer | |
5316 = (ALuint)current_buffer_id; | |
5317 | |
5318 #if 0 | |
5319 /* Remove me...only for checking...doesn't work on Nvidia */ | |
5320 { | |
5321 ALuint real_id; | |
5322 alGetSourcei( | |
5323 ALmixer_Channel_List[i].alsource, | |
5324 AL_BUFFER, &real_id | |
5325 ); | |
5326 alGetError(); | |
5327 fprintf(stderr, "Callback fired on data buffer=%d, real_id shoud be=%d\n", current_buffer_id, real_id); | |
5328 } | |
5329 #endif | |
5330 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id); | |
5331 } | |
5332 else | |
5333 { | |
1 | 5334 /* |
0 | 5335 fprintf(stderr, "53b, Notice/Warning:, OpenAL queue has been depleted.\n"); |
1 | 5336 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
5337 */ | |
0 | 5338 /* In this case, we might either be in an underrun or finished with playback */ |
5339 ALmixer_Channel_List[i].almixer_data->current_buffer = 0; | |
5340 } | |
5341 } | |
5342 } | |
5343 #endif | |
5344 | |
5345 | |
5346 | |
5347 /* Just a test - remove | |
5348 if( ALmixer_Channel_List[i].loops > 0) | |
5349 { | |
5350 fprintf(stderr, ">>>>>>>>>>>>>>>Loops = %d\n", | |
5351 ALmixer_Channel_List[i].loops); | |
5352 } | |
5353 */ | |
5354 #if 0 | |
5355 fprintf(stderr, "Buffers processed = %d\n", buffers_processed); | |
5356 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5357 #endif | |
5358 /* We've used up a buffer so we need to unqueue and replace */ | |
5359 /* Okay, it gets more complicated here: | |
5360 * We need to Queue more data | |
5361 * if buffers_processed > 0 or | |
5362 * if num_of_buffers_in_use < NUMBER_OF_QUEUE_BUFFERS | |
5363 * but we don't do this if at EOF, | |
5364 * except when there is looping | |
5365 */ | |
5366 /* For this to work, we must rely on EVERYTHING | |
5367 * else to unset the EOF if there is looping. | |
5368 * Remember, even Play() must do this | |
5369 */ | |
5370 | |
5371 /* If not EOF, then we are still playing. | |
5372 * Inside, we might find num_of_buffers < NUM...QUEUE_BUF.. | |
5373 * or buffers_process > 0 | |
5374 * in which case we queue up. | |
5375 * We also might find no buffers we need to fill, | |
5376 * in which case we just keep going | |
5377 */ | |
5378 if( ! ALmixer_Channel_List[i].almixer_data->eof) | |
5379 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5380 ALuint bytes_returned; |
0 | 5381 /* We have a priority. We first must assign |
5382 * unused buffers in reserve. If there is nothing | |
5383 * left, then we may unqueue buffers. We can't | |
5384 * do it the other way around because we will | |
5385 * lose the pointer to the unqueued buffer | |
5386 */ | |
5387 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5388 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5389 { | |
1 | 5390 #if 0 |
0 | 5391 fprintf(stderr, "Getting more data in NOT_EOF and num_buffers_in_use (%d) < max_queue (%d)\n", |
5392 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5393 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5394 #endif |
0 | 5395 /* Going to add an unused packet. |
5396 * Grab next packet */ | |
5397 bytes_returned = GetMoreData( | |
5398 ALmixer_Channel_List[i].almixer_data, | |
5399 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5400 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5401 ); | |
5402 } | |
5403 /* For processed > 0 */ | |
5404 else if(buffers_processed > 0) | |
5405 { | |
5406 /* Unqueue only 1 buffer for now. | |
5407 * If there are more than one, | |
5408 * let the next Update pass deal with it | |
5409 * so we don't stall the program for too long. | |
5410 */ | |
5411 #if 0 | |
5412 fprintf(stderr, "About to Unqueue, Buffers processed = %d\n", buffers_processed); | |
5413 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued); | |
5414 fprintf(stderr, "Unqueuing a buffer\n"); | |
5415 #endif | |
5416 alSourceUnqueueBuffers( | |
5417 ALmixer_Channel_List[i].alsource, | |
5418 1, &unqueued_buffer_id | |
5419 ); | |
5420 if((error = alGetError()) != AL_NO_ERROR) | |
5421 { | |
5422 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
|
5423 alGetString(error)); |
0 | 5424 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
|
5425 alGetString(error) ); |
0 | 5426 error_flag--; |
5427 } | |
5428 /* | |
5429 fprintf(stderr, "Right after unqueue..."); | |
5430 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5431 fprintf(stderr, "Getting more data for NOT_EOF, max_buffers filled\n"); | |
5432 */ | |
5433 /* Grab unqueued packet */ | |
5434 bytes_returned = GetMoreData( | |
5435 ALmixer_Channel_List[i].almixer_data, | |
5436 unqueued_buffer_id); | |
5437 } | |
5438 /* We are still streaming, but currently | |
5439 * don't need to fill any buffers */ | |
5440 else | |
5441 { | |
5442 /* Might want to check state */ | |
5443 /* In case the playback stopped, | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5444 * we need to resume |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5445 * a.k.a. buffer underrun |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5446 */ |
1 | 5447 #if 1 |
5448 /* Try not refetching the state here because I'm getting a duplicate | |
5449 buffer playback (hiccup) */ | |
0 | 5450 alGetSourcei( |
5451 ALmixer_Channel_List[i].alsource, | |
5452 AL_SOURCE_STATE, &state | |
5453 ); | |
1 | 5454 if((error = alGetError()) != AL_NO_ERROR) |
5455 { | |
5456 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
|
5457 alGetString(error)); |
1 | 5458 } |
5459 /* Get the number of buffers processed | |
5460 */ | |
5461 alGetSourcei( | |
5462 ALmixer_Channel_List[i].alsource, | |
5463 AL_BUFFERS_PROCESSED, | |
5464 &buffers_processed | |
5465 ); | |
5466 if((error = alGetError()) != AL_NO_ERROR) | |
5467 { | |
5468 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
|
5469 alGetString(error)); |
1 | 5470 } |
5471 #endif | |
0 | 5472 if(AL_STOPPED == state) |
5473 { | |
5474 /* Resuming in not eof, but nothing to buffer */ | |
1 | 5475 |
5476 /* Okay, here's another lately discovered problem: | |
5477 * I can't find it in the spec, but for at least some of the | |
5478 * implementations, if I call play on a stopped source that | |
5479 * has processed buffers, all those buffers get marked as unprocessed | |
5480 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5481 * processed, on resume, the earlier 24 buffers will get replayed, | |
5482 * causing a "hiccup" like sound in the playback. | |
5483 * To avoid this, I must unqueue all processed buffers before | |
5484 * calling play. But to complicate things, I need to worry about resyncing | |
5485 * the circular queue with this since I designed this thing | |
5486 * with some correlation between the two. However, I might | |
5487 * have already handled this, so I will try writing this code without | |
5488 * syncing for now. | |
5489 * There is currently an assumption that a buffer | |
5490 * was queued above so I actually have something | |
5491 * to play. | |
5492 */ | |
5493 ALint temp_count; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5494 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5495 fprintf(stderr, "STOPPED1, need to clear processed=%d, status is:\n", buffers_processed); |
1 | 5496 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
|
5497 #endif |
1 | 5498 for(temp_count=0; temp_count<buffers_processed; temp_count++) |
5499 { | |
5500 alSourceUnqueueBuffers( | |
5501 ALmixer_Channel_List[i].alsource, | |
5502 1, &unqueued_buffer_id | |
5503 ); | |
5504 if((error = alGetError()) != AL_NO_ERROR) | |
5505 { | |
5506 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
|
5507 alGetString(error)); |
1 | 5508 error_flag--; |
5509 } | |
5510 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5511 #if 0 |
1 | 5512 fprintf(stderr, "After unqueue clear...:\n"); |
5513 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
|
5514 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5515 /* 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
|
5516 * 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
|
5517 * 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
|
5518 * 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
|
5519 * no buffers in queue. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5520 * 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
|
5521 * Then we need to resume playing. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5522 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5523 #if 0 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5524 int buffers_queued; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5525 alGetSourcei( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5526 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5527 AL_BUFFERS_QUEUED, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5528 &buffers_queued |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5529 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5530 |
1 | 5531 if((error = alGetError()) != AL_NO_ERROR) |
5532 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5533 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
|
5534 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5535 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5536 assert(buffers_queued == 0); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5537 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
|
5538 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5539 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5540 /* 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
|
5541 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
|
5542 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5543 /* 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
|
5544 bytes_returned = GetMoreData( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5545 ALmixer_Channel_List[i].almixer_data, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5546 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
|
5547 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5548 /* 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
|
5549 * 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
|
5550 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5551 if(bytes_returned > 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5552 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5553 /* Queue up the new data */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5554 alSourceQueueBuffers( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5555 ALmixer_Channel_List[i].alsource, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5556 1, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5557 &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
|
5558 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5559 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5560 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5561 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
|
5562 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5563 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5564 /* 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
|
5565 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
|
5566 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5567 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5568 /* 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
|
5569 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
|
5570 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5571 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5572 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
|
5573 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5574 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5575 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
|
5576 ); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5577 if(0 == queue_ret_flag) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5578 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5579 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
|
5580 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
|
5581 } |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5584 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5585 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5586 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5587 /* Resume playback from underrun */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5588 alSourcePlay(ALmixer_Channel_List[i].alsource); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5589 if((error = alGetError()) != AL_NO_ERROR) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5590 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5591 fprintf(stderr, "55Tbesting error: %s\n", |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5592 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5593 } |
1 | 5594 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5595 |
0 | 5596 } |
5597 /* Let's escape to the next loop. | |
5598 * All code below this point is for queuing up | |
5599 */ | |
5600 /* | |
1 | 5601 fprintf(stderr, "Entry: Nothing to do...continue\n\n"); |
5602 */ | |
0 | 5603 continue; |
5604 } | |
5605 /* We now know we have to fill an available | |
5606 * buffer. | |
5607 */ | |
5608 | |
5609 /* In the previous branch, we just grabbed more data. | |
5610 * Let's check it to make sure it's okay, | |
5611 * and then queue it up | |
5612 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5613 /* This check doesn't work anymore because it is now ALuint */ |
0 | 5614 #if 0 |
5615 if(-1 == bytes_returned) | |
5616 { | |
5617 /* Problem occurred...not sure what to do */ | |
5618 /* Go to next loop? */ | |
5619 error_flag--; | |
5620 /* Set the eof flag to force a quit so | |
5621 * we don't get stuck in an infinite loop | |
5622 */ | |
5623 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5624 continue; | |
5625 } | |
5626 #endif | |
5627 /* This is a special case where we've run | |
5628 * out of data. We should check for loops | |
5629 * and get more data. If there is no loop, | |
5630 * then do nothing and wait for future | |
5631 * update passes to handle the EOF. | |
5632 * The advantage of handling the loop here | |
5633 * instead of waiting for play to stop is | |
5634 * that we should be able to keep the buffer | |
5635 * filled. | |
5636 */ | |
5637 #if 0 | |
5638 else if(0 == bytes_returned) | |
5639 #endif | |
5640 if(0 == bytes_returned) | |
5641 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5642 /* |
0 | 5643 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
|
5644 */ |
0 | 5645 /* Check for loops */ |
5646 if( ALmixer_Channel_List[i].loops != 0 ) | |
5647 { | |
5648 /* We have to loop, so rewind | |
5649 * and fetch more data | |
5650 */ | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5651 /* |
0 | 5652 fprintf(stderr, "Rewinding data\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5653 */ |
0 | 5654 if(0 == Sound_Rewind( |
5655 ALmixer_Channel_List[i].almixer_data->sample)) | |
5656 { | |
5657 fprintf(stderr, "Rewinding failed\n"); | |
5658 ALmixer_SetError( Sound_GetError() ); | |
5659 ALmixer_Channel_List[i].loops = 0; | |
5660 error_flag--; | |
5661 /* We'll continue on because we do have some valid data */ | |
5662 continue; | |
5663 } | |
5664 /* Remember to reset the data->eof flag */ | |
5665 ALmixer_Channel_List[i].almixer_data->eof = 0; | |
5666 if(ALmixer_Channel_List[i].loops > 0) | |
5667 { | |
5668 ALmixer_Channel_List[i].loops--; | |
5669 } | |
5670 /* Try grabbing another packet now. | |
5671 * Since we may have already unqueued a | |
5672 * buffer, we don't want to lose it. | |
5673 */ | |
5674 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5675 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
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 %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
|
5679 */ |
0 | 5680 /* Grab next packet */ |
5681 bytes_returned = GetMoreData( | |
5682 ALmixer_Channel_List[i].almixer_data, | |
5683 ALmixer_Channel_List[i].almixer_data->buffer[ | |
5684 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
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, "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
|
5688 */ |
0 | 5689 } |
5690 /* Refilling unqueued packet */ | |
5691 else | |
5692 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5693 /* |
0 | 5694 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
|
5695 */ |
0 | 5696 /* Grab next packet */ |
5697 bytes_returned = GetMoreData( | |
5698 ALmixer_Channel_List[i].almixer_data, | |
5699 unqueued_buffer_id); | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5700 /* |
0 | 5701 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
|
5702 */ |
0 | 5703 } |
5704 /* Another error check */ | |
5705 /* | |
5706 if(bytes_returned <= 0) | |
5707 */ | |
5708 if(0 == bytes_returned) | |
5709 { | |
5710 fprintf(stderr, "??????????ERROR\n"); | |
5711 ALmixer_SetError("Could not loop because after rewind, no data could be retrieved"); | |
5712 /* Problem occurred...not sure what to do */ | |
5713 /* Go to next loop? */ | |
5714 error_flag--; | |
5715 /* Set the eof flag to force a quit so | |
5716 * we don't get stuck in an infinite loop | |
5717 */ | |
5718 ALmixer_Channel_List[i].almixer_data->eof = 1; | |
5719 continue; | |
5720 } | |
5721 /* We made it to the end. We still need | |
5722 * to BufferData, so let this branch | |
5723 * fall into the next piece of | |
5724 * code below which will handle that | |
5725 */ | |
5726 | |
5727 | |
5728 } /* END loop check */ | |
5729 else | |
5730 { | |
5731 /* No more loops to do. | |
5732 * EOF flag should be set. | |
5733 * Just go to next loop and | |
5734 * let things be handled correctly | |
5735 * in future update calls | |
5736 */ | |
1 | 5737 /* |
0 | 5738 fprintf(stderr, "SHOULD BE EOF\n"); |
5739 | |
5740 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
1 | 5741 */ |
0 | 5742 continue; |
5743 } | |
5744 } /* END if bytes_returned == 0 */ | |
5745 /********* Possible trouble point. I might be queueing empty buffers on the mac. | |
5746 * This check doesn't say if the buffer is valid. Only the EOF assumption is a clue at this point | |
5747 */ | |
5748 /* Fall here */ | |
5749 /* Everything is normal. We aren't | |
5750 * at an EOF, but need to simply | |
5751 * queue more data. The data is already checked for good, | |
5752 * so queue it up */ | |
5753 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5754 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5755 { | |
5756 /* Keep count of how many buffers we have | |
5757 * to queue so we can return the value | |
5758 */ | |
5759 retval++; | |
1 | 5760 /* |
0 | 5761 fprintf(stderr, "NOT_EOF???, about to Queue more data for num_buffers (%d) < max_queue (%d)\n", |
5762 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use, | |
5763 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
1 | 5764 */ |
0 | 5765 alSourceQueueBuffers( |
5766 ALmixer_Channel_List[i].alsource, | |
5767 1, | |
5768 &ALmixer_Channel_List[i].almixer_data->buffer[ | |
5769 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5770 ); | |
5771 if((error = alGetError()) != AL_NO_ERROR) | |
5772 { | |
5773 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
|
5774 alGetString(error)); |
0 | 5775 } |
5776 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5777 * which buffer to show during callbacks (for things like | |
5778 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5779 * data structure. This code will be called only if | |
5780 * "access_data" was set, indicated by whether the queue is NULL. | |
5781 */ | |
5782 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5783 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5784 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5785 // fprintf(stderr, "56d: CircularQueue_PushBack.\n"); |
0 | 5786 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5787 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5788 ALmixer_Channel_List[i].almixer_data->buffer[ALmixer_Channel_List[i].almixer_data->num_buffers_in_use] | |
5789 ); | |
5790 if(0 == queue_ret_flag) | |
5791 { | |
5792 fprintf(stderr, "56aSerious internal error: CircularQueue could not push into queue.\n"); | |
5793 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5794 } | |
5795 /* | |
5796 else | |
5797 { | |
5798 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5799 } | |
5800 */ | |
5801 } | |
5802 } | |
5803 /* for processed > 0 */ | |
5804 else | |
5805 { | |
5806 /* Keep count of how many buffers we have | |
5807 * to queue so we can return the value | |
5808 */ | |
5809 retval++; | |
5810 /* | |
5811 fprintf(stderr, "NOT_EOF, about to Queue more data for filled max_queue (%d)\n", | |
5812 ALmixer_Channel_List[i].almixer_data->max_queue_buffers); | |
5813 */ | |
5814 alSourceQueueBuffers( | |
5815 ALmixer_Channel_List[i].alsource, | |
5816 1, &unqueued_buffer_id); | |
5817 if((error = alGetError()) != AL_NO_ERROR) | |
5818 { | |
5819 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
|
5820 alGetString(error) ); |
0 | 5821 error_flag--; |
5822 continue; | |
5823 } | |
5824 /* This is part of the hideous Nvidia workaround. In order to figure out | |
5825 * which buffer to show during callbacks (for things like | |
5826 * o-scopes), I must keep a copy of the buffers that are queued in my own | |
5827 * data structure. This code will be called only if | |
5828 * "access_data" was set, indicated by whether the queue is NULL. | |
5829 */ | |
5830 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL) | |
5831 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5832 ALuint queue_ret_flag; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5833 // fprintf(stderr, "56e: CircularQueue_PushBack.\n"); |
0 | 5834 queue_ret_flag = CircularQueueUnsignedInt_PushBack( |
5835 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue, | |
5836 unqueued_buffer_id | |
5837 ); | |
5838 if(0 == queue_ret_flag) | |
5839 { | |
5840 fprintf(stderr, "56bSerious internal error: CircularQueue could not push into queue.\n"); | |
5841 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue"); | |
5842 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5843 #if 0 |
0 | 5844 else |
5845 { | |
5846 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue); | |
5847 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5848 #endif |
0 | 5849 } |
5850 } | |
5851 /* If we used an available buffer queue, | |
5852 * then we need to update the number of them in use | |
5853 */ | |
5854 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use | |
5855 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers) | |
5856 { | |
5857 /* Increment the number of buffers in use */ | |
5858 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use++; | |
5859 } | |
5860 /* Might want to check state */ | |
5861 /* In case the playback stopped, | |
5862 * we need to resume */ | |
1 | 5863 #if 1 |
5864 /* Try not refetching the state here because I'm getting a duplicate | |
5865 buffer playback (hiccup) */ | |
0 | 5866 alGetSourcei( |
5867 ALmixer_Channel_List[i].alsource, | |
5868 AL_SOURCE_STATE, &state | |
5869 ); | |
1 | 5870 if((error = alGetError()) != AL_NO_ERROR) |
5871 { | |
5872 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
|
5873 alGetString(error)); |
1 | 5874 } |
5875 /* Get the number of buffers processed | |
5876 */ | |
5877 alGetSourcei( | |
5878 ALmixer_Channel_List[i].alsource, | |
5879 AL_BUFFERS_PROCESSED, | |
5880 &buffers_processed | |
5881 ); | |
5882 if((error = alGetError()) != AL_NO_ERROR) | |
5883 { | |
5884 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
|
5885 alGetString(error)); |
1 | 5886 } |
5887 #endif | |
0 | 5888 if(AL_STOPPED == state) |
5889 { | |
1 | 5890 /* |
0 | 5891 fprintf(stderr, "Resuming in not eof\n"); |
1 | 5892 */ |
5893 /* Okay, here's another lately discovered problem: | |
5894 * I can't find it in the spec, but for at least some of the | |
5895 * implementations, if I call play on a stopped source that | |
5896 * has processed buffers, all those buffers get marked as unprocessed | |
5897 * on alSourcePlay. So if I had a queue of 25 with 24 of the buffers | |
5898 * processed, on resume, the earlier 24 buffers will get replayed, | |
5899 * causing a "hiccup" like sound in the playback. | |
5900 * To avoid this, I must unqueue all processed buffers before | |
5901 * calling play. But to complicate things, I need to worry about resyncing | |
5902 * the circular queue with this since I designed this thing | |
5903 * with some correlation between the two. However, I might | |
5904 * have already handled this, so I will try writing this code without | |
5905 * syncing for now. | |
5906 * There is currently an assumption that a buffer | |
5907 * was queued above so I actually have something | |
5908 * to play. | |
5909 */ | |
5910 ALint temp_count; | |
5911 /* | |
5912 fprintf(stderr, "STOPPED2, need to clear processed, status is:\n"); | |
5913 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5914 */ | |
5915 | |
5916 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5917 { | |
5918 alSourceUnqueueBuffers( | |
5919 ALmixer_Channel_List[i].alsource, | |
5920 1, &unqueued_buffer_id | |
5921 ); | |
5922 if((error = alGetError()) != AL_NO_ERROR) | |
5923 { | |
5924 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
|
5925 alGetString(error)); |
1 | 5926 error_flag--; |
5927 } | |
5928 } | |
5929 /* | |
5930 fprintf(stderr, "After unqueue clear...:\n"); | |
5931 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
5932 */ | |
5933 | |
5934 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
5935 if((error = alGetError()) != AL_NO_ERROR) | |
5936 { | |
5937 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
|
5938 alGetString(error)); |
1 | 5939 } |
0 | 5940 } |
5941 continue; | |
5942 } /* END if( ! eof) */ | |
5943 /* We have hit EOF in the SDL_Sound sample and there | |
5944 * are no more loops. However, there may still be | |
5945 * buffers in the OpenAL queue which still need to | |
5946 * be played out. The following body of code will | |
5947 * determine if play is still happening or | |
5948 * initiate the stop/cleanup sequenece. | |
5949 */ | |
5950 else | |
5951 { | |
5952 /* Let's continue to remove the used up | |
5953 * buffers as they come in. */ | |
5954 if(buffers_processed > 0) | |
5955 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
5956 ALint temp_count; |
0 | 5957 /* Do as a for-loop because I don't want |
5958 * to have to create an array for the | |
5959 * unqueued_buffer_id's | |
5960 */ | |
5961 for(temp_count=0; temp_count<buffers_processed; temp_count++) | |
5962 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5963 /* |
0 | 5964 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
|
5965 */ |
0 | 5966 alSourceUnqueueBuffers( |
5967 ALmixer_Channel_List[i].alsource, | |
5968 1, &unqueued_buffer_id | |
5969 ); | |
5970 if((error = alGetError()) != AL_NO_ERROR) | |
5971 { | |
5972 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
|
5973 alGetString(error)); |
0 | 5974 } |
5975 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5976 /* |
0 | 5977 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
|
5978 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
5979 |
0 | 5980 /* Need to update counts since we removed everything. |
5981 * If we don't update the counts here, we end up in the | |
5982 * "Shouldn't be here section, but maybe it's okay due to race conditions" | |
5983 */ | |
5984 alGetSourcei( | |
5985 ALmixer_Channel_List[i].alsource, | |
5986 AL_BUFFERS_QUEUED, &buffers_still_queued | |
5987 ); | |
5988 if((error = alGetError()) != AL_NO_ERROR) | |
5989 { | |
5990 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
|
5991 alGetString(error)); |
0 | 5992 } |
5993 /* Get the number of buffers processed | |
5994 * so we know if we need to refill | |
5995 */ | |
5996 alGetSourcei( | |
5997 ALmixer_Channel_List[i].alsource, | |
5998 AL_BUFFERS_PROCESSED, &buffers_processed | |
5999 ); | |
6000 if((error = alGetError()) != AL_NO_ERROR) | |
6001 { | |
6002 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
|
6003 alGetString(error)); |
0 | 6004 } |
6005 } | |
6006 | |
6007 | |
6008 /* Else if buffers_processed == 0 | |
6009 * and buffers_still_queued == 0. | |
6010 * then we check to see if the source | |
6011 * is still playing. Quit if stopped | |
6012 * We shouldn't need to worry about | |
6013 * looping because that should have | |
6014 * been handled above. | |
6015 */ | |
6016 if(0 == buffers_still_queued) | |
6017 { | |
6018 /* Make sure playback has stopped before | |
6019 * we shutdown. | |
6020 */ | |
6021 alGetSourcei( | |
6022 ALmixer_Channel_List[i].alsource, | |
6023 AL_SOURCE_STATE, &state | |
6024 ); | |
6025 if((error = alGetError()) != AL_NO_ERROR) | |
6026 { | |
6027 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
|
6028 alGetString(error)); |
0 | 6029 } |
6030 if(AL_STOPPED == state) | |
6031 { | |
6032 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use = 0; | |
6033 /* Playback has ended. | |
6034 * Loop if necessary, or launch callback | |
6035 * and clear channel (or clear channel and | |
6036 * 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
|
6037 * Update: Need to do callback first because I reference the mixer_data and source |
0 | 6038 */ |
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
|
6039 |
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
|
6040 /* 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
|
6041 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
|
6042 |
0 | 6043 Clean_Channel(i); |
6044 /* Subtract counter */ | |
6045 Is_Playing_global--; | |
6046 | |
6047 | |
6048 /* We're done for this loop. | |
6049 * Go to next channel | |
6050 */ | |
6051 continue; | |
6052 } | |
6053 } /* End end-playback */ | |
6054 else | |
6055 { | |
6056 /* Need to run out buffer */ | |
6057 #if 1 | |
6058 /* Might want to check state */ | |
6059 /* In case the playback stopped, | |
6060 * we need to resume */ | |
6061 alGetSourcei( | |
6062 ALmixer_Channel_List[i].alsource, | |
6063 AL_SOURCE_STATE, &state | |
6064 ); | |
6065 if((error = alGetError()) != AL_NO_ERROR) | |
6066 { | |
6067 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
|
6068 alGetString(error)); |
0 | 6069 } |
6070 if(AL_STOPPED == state) | |
6071 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6072 /* |
0 | 6073 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
|
6074 */ |
1 | 6075 /* |
0 | 6076 PrintQueueStatus(ALmixer_Channel_List[i].alsource); |
1 | 6077 */ |
0 | 6078 /* Rather than force unqueuing the buffer, let's see if |
6079 * setting the buffer to none works (the OpenAL 1.0 | |
6080 * Reference Annotation suggests this should work). | |
6081 */ | |
6082 alSourcei(ALmixer_Channel_List[i].alsource, | |
6083 AL_BUFFER, AL_NONE); | |
6084 /* | |
6085 PrintQueueStatus(ALmixer_Channel_List[i].alsource); | |
6086 */ | |
6087 /* This doesn't work because in some cases, I think | |
6088 * it causes the sound to be replayed | |
6089 */ | |
6090 /* | |
6091 fprintf(stderr, "Resuming in eof (trying to run out buffers\n"); | |
6092 alSourcePlay(ALmixer_Channel_List[i].alsource); | |
6093 */ | |
6094 } | |
6095 #endif | |
6096 } /* End trap section */ | |
6097 } /* End POST-EOF use-up buffer section */ | |
6098 } /* END Streamed section */ | |
6099 } /* END channel in use */ | |
6100 } /* END for-loop for each channel */ | |
6101 | |
6102 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6103 alcProcessContext(alcGetCurrentContext()); | |
6104 if((error = alGetError()) != AL_NO_ERROR) | |
6105 { | |
6106 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
|
6107 alGetString(error)); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6108 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6109 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6110 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6111 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6112 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6113 #endif |
0 | 6114 /* Return the number of errors */ |
6115 if(error_flag < 0) | |
6116 { | |
6117 return error_flag; | |
6118 } | |
6119 /* Return the number of buffers that were queued */ | |
6120 return retval; | |
6121 } | |
6122 | |
6123 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6124 /* 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
|
6125 static void my_dummy_audio_callback(void* userdata, ALbyte* stream, int len) |
0 | 6126 { |
6127 } | |
6128 #endif | |
6129 | |
6130 | |
6131 | |
6132 | |
6133 #ifdef ENABLE_ALMIXER_THREADS | |
6134 /* We might need threads. We | |
6135 * must constantly poll OpenAL to find out | |
6136 * if sound is being streamed, if play has | |
6137 * ended, etc. Without threads, this must | |
6138 * be explicitly done by the user. | |
6139 * We could try to do it for them if we | |
6140 * finish the threads. | |
6141 */ | |
6142 | |
6143 static int Stream_Data_Thread_Callback(void* data) | |
6144 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6145 ALint retval; |
0 | 6146 |
6147 while(ALmixer_Initialized) | |
6148 { | |
6149 retval = Update_ALmixer(data); | |
6150 /* 0 means that nothing needed updating and | |
6151 * the function returned quickly | |
6152 */ | |
6153 if(0 == retval) | |
6154 { | |
6155 /* Let's be nice and make the thread sleep since | |
6156 * little work was done in update | |
6157 */ | |
6158 /* Make sure times are multiples of 10 | |
6159 * for optimal performance and accuracy in Linux | |
6160 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6161 ALmixer_Delay(10); |
0 | 6162 } |
6163 else | |
6164 { | |
6165 /* 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
|
6166 ALmixer_Delay(0); |
0 | 6167 } |
6168 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6169 /* |
0 | 6170 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
|
6171 */ |
0 | 6172 return 0; |
6173 } | |
6174 #endif /* End of ENABLE_ALMIXER_THREADS */ | |
6175 | |
6176 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6177 /* 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
|
6178 * 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
|
6179 * so SDL_mixer porting people beware. |
0 | 6180 * Warning: SDL_QuitSubSystem(SDL_INIT_AUDIO) is called which |
6181 * means the SDL audio system will be disabled. It will not | |
6182 * be restored (in case SDL is not actually being used) so | |
6183 * the user will need to restart it if they need it after | |
6184 * OpenAL shuts down. | |
6185 */ | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6186 ALboolean ALmixer_Init(ALuint frequency, ALuint num_sources, ALuint refresh) |
0 | 6187 { |
6188 ALCdevice* dev; | |
6189 ALCcontext* context; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6190 ALint i; |
0 | 6191 ALenum error; |
6192 ALuint* source; | |
6193 | |
6194 #ifdef USING_LOKI_AL_DIST | |
6195 /* The Loki dist requires that I set both the | |
6196 * device and context frequency values separately | |
6197 */ | |
6198 /* Hope this won't overflow */ | |
6199 char device_string[256]; | |
6200 #endif | |
6201 | |
6202 /* (Venting frustration) Damn it! Nobody bothered | |
6203 * documenting how you're supposed to use an attribute | |
6204 * list. In fact, the not even the Loki test program | |
6205 * writers seem to know because they use it inconsistently. | |
6206 * For example, how do you terminate that attribute list? | |
6207 * The Loki test code does it 3 different ways. They | |
6208 * set the last value to 0, or they set it to ALC_INVALID, | |
6209 * or they set two final values: ALC_INVALID, 0 | |
6210 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6211 * but with Creative Labs ALC_INVALID is -1. | |
6212 * So something's going to break. Loki's source | |
6213 * code says to terminate with ALC_INVALID. But I | |
6214 * don't know if that's really true, or it happens | |
6215 * to be a coinicidence because it's defined to 0. | |
6216 * Creative provides no source code, so I can't look at how | |
6217 * they terminate it. | |
6218 * So this is really, really ticking me off... | |
6219 * For now, I'm going to use ALC_INVALID. | |
6220 * (Update...after further review of the API spec, | |
6221 * it seems that a NULL terminated string is the correct | |
6222 * termination value to use, so 0 it is.) | |
6223 */ | |
6224 #if 0 | |
6225 ALint attrlist[] = { | |
6226 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6227 /* Don't know anything about these values. | |
6228 * Trust defaults? */ | |
6229 /* Supposed to be the refresh rate in Hz. | |
6230 * I think 15-120 are supposed to be good | |
6231 * values. Though I haven't gotten any effect except | |
6232 * for one strange instance on a Mac. But it was | |
6233 * unrepeatable. | |
6234 */ | |
6235 #if 0 | |
6236 ALC_REFRESH, 15, | |
6237 #endif | |
6238 /* Sync requires a alcProcessContext() call | |
6239 * for every cycle. By default, this is | |
6240 * not used and the value is AL_FALSE | |
6241 * because it will probably perform | |
6242 * pretty badly for me. | |
6243 */ | |
6244 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6245 ALC_SYNC, AL_TRUE, | |
6246 #else | |
6247 ALC_SYNC, AL_FALSE, | |
6248 #endif | |
6249 /* Looking at the API spec, it implies | |
6250 * that the list be a NULL terminated string | |
6251 * so it's probably not safe to use ALC_INVALID | |
6252 */ | |
6253 /* | |
6254 ALC_INVALID }; | |
6255 */ | |
6256 '\0'}; | |
6257 #endif | |
6258 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6259 * However, if no value is specified, I don't | |
6260 * want it in the list so I can get the OpenAL defaults | |
6261 */ | |
6262 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6263 ALsizei current_attrlist_index = 0; |
0 | 6264 |
6265 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6266 /* More problems: I'm getting bit by endian/signedness issues on | |
6267 * different platforms. I can find the endianess easily enough, | |
6268 * but I don't know how to determine what the correct signedness | |
6269 * is (if such a thing exists). I do know that if I try using | |
6270 * unsigned on OSX with an originally signed sample, I get | |
6271 * distortion. However, I don't have any native unsigned samples | |
6272 * to test. But I'm assuming that the platform must be in the | |
6273 * correct signedness no matter what. | |
6274 * I can either assume everybody is signed, or I can try to | |
6275 * determine the value. If I try to determine the values, | |
6276 * I think my only ability to figure it out will be to open | |
6277 * SDL_Audio, and read what the obtained settings were. | |
6278 * Then shutdown everything. However, I don't even know how | |
6279 * reliable this is. | |
6280 * Update: I think I resolved the issues...forgot to update | |
6281 * these comments when it happened. I should check the revision control | |
6282 * log... Anyway, I think the issue was partly related to me not | |
6283 * doing something correctly with the AudioInfo or some kind | |
6284 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6285 * revision control, I think I might have assumed that SDL_Sound would | |
6286 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6287 * and had to fill one out myself. | |
6288 */ | |
6289 SDL_AudioSpec desired; | |
6290 SDL_AudioSpec obtained; | |
6291 #endif | |
6292 | |
6293 | |
6294 /* Make sure ALmixer isn't already initialized */ | |
6295 if(ALmixer_Initialized) | |
6296 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6297 return AL_FALSE; |
0 | 6298 } |
6299 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6300 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6301 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6302 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6303 /* 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
|
6304 /* 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
|
6305 * 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
|
6306 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6307 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6308 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6309 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6310 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6311 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6312 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6313 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6314 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6315 } |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6316 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6317 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6318 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6319 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
|
6320 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
|
6321 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6322 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6323 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6324 |
0 | 6325 /* Set the defaults */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6326 /* |
0 | 6327 attrlist[0] = ALC_FREQUENCY; |
6328 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6329 attrlist[2] = ALC_SYNC; | |
6330 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6331 attrlist[3] = ALC_TRUE; | |
6332 #else | |
6333 attrlist[3] = ALC_FALSE; | |
6334 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6335 */ |
0 | 6336 /* Set frequency value if it is not 0 */ |
6337 if(0 != frequency) | |
6338 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6339 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6340 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6341 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6342 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6343 } |
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 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6346 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6347 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6348 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6349 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6350 #endif |
0 | 6351 |
6352 /* If the user specifies a refresh value, | |
6353 * make room for it | |
6354 */ | |
6355 if(0 != refresh) | |
6356 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6357 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
|
6358 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6359 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6360 current_attrlist_index++; |
0 | 6361 } |
6362 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6363 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6364 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6365 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6366 |
0 | 6367 /* Initialize SDL_Sound */ |
6368 if(! Sound_Init() ) | |
6369 { | |
6370 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6371 return AL_FALSE; |
0 | 6372 } |
6373 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6374 /* Here is the paranoid check that opens | |
6375 * SDL audio in an attempt to find the correct | |
6376 * system values. | |
6377 */ | |
6378 /* Doesn't have to be the actual value I think | |
6379 * (as long as it doesn't influence format, in | |
6380 * which case I'm probably screwed anyway because OpenAL | |
6381 * may easily choose to do something else). | |
6382 */ | |
6383 desired.freq = 44100; | |
6384 desired.channels = 2; | |
6385 desired.format = AUDIO_S16SYS; | |
6386 desired.callback = my_dummy_audio_callback; | |
6387 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6388 { | |
6389 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6390 /* Now to get really paranoid, we should probably | |
6391 * also assume that the 8bit format is also the | |
6392 * same sign type and set that value | |
6393 */ | |
6394 if(AUDIO_S16SYS == obtained.format) | |
6395 { | |
6396 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6397 } | |
6398 /* Should be AUDIO_U16SYS */ | |
6399 else | |
6400 { | |
6401 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6402 } | |
6403 SDL_CloseAudio(); | |
6404 } | |
6405 else | |
6406 { | |
6407 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6408 */ | |
6409 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6410 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6411 } | |
6412 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6413 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6414 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6415 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
6416 * causes OpenAL and SMPEG to conflict. For some reason | |
6417 * if SDL_Init on audio is active, then all the SMPEG | |
6418 * decoded sound comes out silent. Unfortunately, | |
6419 * Sound_Init() invokes SDL_Init on audio. I'm | |
6420 * not sure why it actually needs it... | |
6421 * But we'll attempt to disable it here after the | |
6422 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
6423 */ | |
6424 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6425 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6426 |
0 | 6427 /* I'm told NULL will call the default string |
6428 * and hopefully do the right thing for each platform | |
6429 */ | |
6430 /* | |
6431 dev = alcOpenDevice( NULL ); | |
6432 */ | |
6433 /* Now I'm told I need to set both the device and context | |
6434 * to have the same sampling rate, so I must pass a string | |
6435 * to OpenDevice(). I don't know how portable these strings are. | |
6436 * I don't even know if the format for strings is | |
6437 * compatible | |
6438 * From the testattrib.c in the Loki test section | |
6439 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
6440 */ | |
6441 | |
6442 #ifdef USING_LOKI_AL_DIST | |
6443 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
6444 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
6445 #else | |
6446 dev = alcOpenDevice( NULL ); | |
6447 #endif | |
6448 if(NULL == dev) | |
6449 { | |
6450 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
|
6451 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6452 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6453 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6454 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6455 /* 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
|
6456 /* 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
|
6457 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6458 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6459 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6460 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6461 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
|
6462 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6463 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
|
6464 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6465 #endif |
0 | 6466 |
6467 context = alcCreateContext(dev, attrlist); | |
6468 if(NULL == context) | |
6469 { | |
6470 ALmixer_SetError("Cannot create a context OpenAL"); | |
6471 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6472 return AL_FALSE; |
0 | 6473 } |
6474 | |
6475 | |
6476 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6477 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6478 * According to Garin Hiebert, this is actually an inconsistency | |
6479 * in the Loki version. The function should return a boolean. | |
6480 * instead of ALC_NO_ERROR. Garin suggested I check via | |
6481 * alcGetError(). | |
6482 */ | |
6483 /* clear the error */ | |
6484 alcGetError(dev); | |
6485 alcMakeContextCurrent(context); | |
6486 | |
6487 error = alcGetError(dev); | |
6488 if( (ALC_NO_ERROR != error) ) | |
6489 { | |
6490 ALmixer_SetError("Could not MakeContextCurrent"); | |
6491 alcDestroyContext(context); | |
6492 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6493 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6494 } |
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 /* 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
|
6497 * 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
|
6498 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6499 * 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
|
6500 * 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
|
6501 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6502 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6503 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6504 ALmixer_Frequency_global = frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6505 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6506 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6507 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
|
6508 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6509 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
|
6510 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6511 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6512 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6513 |
0 | 6514 #if 0 |
6515 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
6516 if(alcGetCurrentContext() != context) | |
6517 { | |
6518 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
6519 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
6520 * I think this is a bug in the OpenAL implementation. | |
6521 */ | |
6522 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
6523 | |
6524 fprintf(stderr, "Making context current\n"); | |
6525 #ifndef __APPLE__ | |
6526 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
6527 #else | |
6528 if(!alcMakeContextCurrent(context)) | |
6529 #endif | |
6530 { | |
6531 ALmixer_SetError("Could not MakeContextCurrent"); | |
6532 alcDestroyContext(context); | |
6533 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6534 return AL_FALSE; |
0 | 6535 } |
6536 } | |
6537 #endif | |
6538 | |
6539 | |
6540 /* #endif */ | |
6541 /* Saw this in the README with the OS X OpenAL distribution. | |
6542 * It looked interesting and simple, so I thought I might | |
6543 * try it out. | |
6544 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
6545 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
6546 * Audio format, the audio data passed to the | |
6547 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
6548 * usage by removing an audio data conversion | |
6549 * (per source) at render timem at the expense of a larger memory footprint. | |
6550 * | |
6551 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
6552 * setting will be applied to all subsequent | |
6553 * calls to alBufferData(). | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6554 * |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6555 * 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
|
6556 * Rather than deal with it right now, I think I am going to make it an opt-in thing. |
0 | 6557 */ |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6558 #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
|
6559 /* |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6560 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
|
6561 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6562 #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
|
6563 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6564 #else |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6565 /* 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
|
6566 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
|
6567 /* |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6568 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
|
6569 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6570 if(0 != convert_data_enum) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6571 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6572 alEnable(convert_data_enum); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6573 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6574 if( (AL_NO_ERROR != alGetError()) ) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6575 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6576 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
|
6577 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
|
6578 } |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6579 #endif |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6580 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6581 #endif /* __APPLE__ */ |
0 | 6582 |
6583 | |
6584 | |
6585 | |
6586 ALmixer_Initialized = 1; | |
6587 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6588 if(num_sources == 0) |
0 | 6589 { |
6590 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
6591 } | |
6592 else | |
6593 { | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
6594 /* 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
|
6595 Number_of_Channels_global = (ALint)num_sources; |
0 | 6596 } |
6597 Number_of_Reserve_Channels_global = 0; | |
6598 Is_Playing_global = 0; | |
6599 /* Set to Null in case system quit and was reinitialized */ | |
6600 Channel_Done_Callback = NULL; | |
6601 Channel_Done_Callback_Userdata = NULL; | |
6602 Channel_Data_Callback = NULL; | |
1 | 6603 Channel_Data_Callback_Userdata = NULL; |
0 | 6604 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6605 /* Allocate memory for linked list of ALmixerData. */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6606 s_listOfALmixerData = LinkedList_Create(); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6607 if(NULL == s_listOfALmixerData) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6608 { |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6609 ALmixer_SetError("Couldn't create linked list"); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6610 alcDestroyContext(context); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6611 alcCloseDevice(dev); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6612 ALmixer_Initialized = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6613 Number_of_Channels_global = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6614 return AL_FALSE; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6615 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6616 |
0 | 6617 /* Allocate memory for the list of channels */ |
6618 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
6619 if(NULL == ALmixer_Channel_List) | |
6620 { | |
6621 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
|
6622 LinkedList_Free(s_listOfALmixerData); |
0 | 6623 alcDestroyContext(context); |
6624 alcCloseDevice(dev); | |
6625 ALmixer_Initialized = 0; | |
6626 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6627 return AL_FALSE; |
0 | 6628 } |
6629 | |
6630 /* Allocate memory for the list of sources that map to the channels */ | |
6631 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
6632 if(NULL == Source_Map_List) | |
6633 { | |
6634 ALmixer_SetError("Out of Memory for Source Map List"); | |
6635 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6636 LinkedList_Free(s_listOfALmixerData); |
0 | 6637 alcDestroyContext(context); |
6638 alcCloseDevice(dev); | |
6639 ALmixer_Initialized = 0; | |
6640 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6641 return AL_FALSE; |
0 | 6642 } |
6643 | |
6644 /* Create array that will hold the sources */ | |
6645 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
6646 if(NULL == source) | |
6647 { | |
6648 ALmixer_SetError("Out of Memory for sources"); | |
6649 free(Source_Map_List); | |
6650 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6651 LinkedList_Free(s_listOfALmixerData); |
0 | 6652 alcDestroyContext(context); |
6653 alcCloseDevice(dev); | |
6654 ALmixer_Initialized = 0; | |
6655 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6656 return AL_FALSE; |
0 | 6657 } |
6658 | |
6659 /* Clear the error state */ | |
6660 alGetError(); | |
6661 /* Generate the OpenAL sources */ | |
6662 alGenSources(Number_of_Channels_global, source); | |
6663 if( (error=alGetError()) != AL_NO_ERROR) | |
6664 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6665 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 6666 free(ALmixer_Channel_List); |
6667 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6668 LinkedList_Free(s_listOfALmixerData); |
0 | 6669 alcDestroyContext(context); |
6670 alcCloseDevice(dev); | |
6671 ALmixer_Initialized = 0; | |
6672 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6673 return AL_FALSE; |
0 | 6674 } |
6675 | |
6676 /* Initialize each channel and associate one source to one channel */ | |
6677 for(i=0; i<Number_of_Channels_global; i++) | |
6678 { | |
6679 if(0 == source[i]) | |
6680 { | |
6681 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"); | |
6682 } | |
6683 | |
6684 Init_Channel(i); | |
6685 /* Keeping the source allocation out of the Init function | |
6686 * in case I want to reuse the Init | |
6687 * function for resetting data | |
6688 */ | |
6689 ALmixer_Channel_List[i].alsource = source[i]; | |
6690 /* Now also keep a copy of the source to channel mapping | |
6691 * in case we need to look up a channel from the source | |
6692 * instead of a source from a channel | |
6693 */ | |
6694 Source_Map_List[i].source = source[i]; | |
6695 Source_Map_List[i].channel = i; | |
6696 /* Clean the channel because there are some things that need to | |
6697 * be done that can't happen until the source is set | |
6698 */ | |
6699 Clean_Channel(i); | |
6700 } | |
6701 | |
6702 /* The Source_Map_List must be sorted by source for binary searches | |
6703 */ | |
6704 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
6705 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6706 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6707 ALmixer_OutputDecoders(); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6708 */ |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6709 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6710 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6711 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6712 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6713 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6714 if(NULL == s_simpleLock) |
0 | 6715 { |
6716 /* SDL sets the error message already? */ | |
6717 free(source); | |
6718 free(ALmixer_Channel_List); | |
6719 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6720 LinkedList_Free(s_listOfALmixerData); |
0 | 6721 alcDestroyContext(context); |
6722 alcCloseDevice(dev); | |
6723 ALmixer_Initialized = 0; | |
6724 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6725 return AL_FALSE; |
0 | 6726 } |
6727 | |
6728 | |
6729 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
6730 if(NULL == Stream_Thread_global) | |
6731 { | |
6732 /* 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
|
6733 SDL_DestroyMutex(s_simpleLock); |
0 | 6734 free(source); |
6735 free(ALmixer_Channel_List); | |
6736 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
6737 LinkedList_Free(s_listOfALmixerData); |
0 | 6738 alcDestroyContext(context); |
6739 alcCloseDevice(dev); | |
6740 ALmixer_Initialized = 0; | |
6741 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6742 return AL_FALSE; |
0 | 6743 } |
6744 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6745 /* |
0 | 6746 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
6747 */ |
0 | 6748 #endif /* End of ENABLE_ALMIXER_THREADS */ |
6749 | |
6750 /* We don't need this array any more because all the sources | |
6751 * are connected to channels | |
6752 */ | |
6753 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6754 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6755 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6756 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6757 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6758 ALboolean ALmixer_InitContext(ALuint frequency, ALuint refresh) |
0 | 6759 { |
6760 ALCdevice* dev; | |
6761 ALCcontext* context; | |
6762 ALCenum error; | |
6763 | |
6764 #ifdef USING_LOKI_AL_DIST | |
6765 /* The Loki dist requires that I set both the | |
6766 * device and context frequency values separately | |
6767 */ | |
6768 /* Hope this won't overflow */ | |
6769 char device_string[256]; | |
6770 #endif | |
6771 | |
6772 /* (Venting frustration) Damn it! Nobody bothered | |
6773 * documenting how you're supposed to use an attribute | |
6774 * list. In fact, the not even the Loki test program | |
6775 * writers seem to know because they use it inconsistently. | |
6776 * For example, how do you terminate that attribute list? | |
6777 * The Loki test code does it 3 different ways. They | |
6778 * set the last value to 0, or they set it to ALC_INVALID, | |
6779 * or they set two final values: ALC_INVALID, 0 | |
6780 * In Loki, 0 and ALC_INVALID happen to be the same, | |
6781 * but with Creative Labs ALC_INVALID is -1. | |
6782 * So something's going to break. Loki's source | |
6783 * code says to terminate with ALC_INVALID. But I | |
6784 * don't know if that's really true, or it happens | |
6785 * to be a coinicidence because it's defined to 0. | |
6786 * Creative provides no source code, so I can't look at how | |
6787 * they terminate it. | |
6788 * So this is really, really ticking me off... | |
6789 * For now, I'm going to use ALC_INVALID. | |
6790 * (Update...after further review of the API spec, | |
6791 * it seems that a NULL terminated string is the correct | |
6792 * termination value to use, so 0 it is.) | |
6793 */ | |
6794 #if 0 | |
6795 ALint attrlist[] = { | |
6796 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY, | |
6797 /* Don't know anything about these values. | |
6798 * Trust defaults? */ | |
6799 /* Supposed to be the refresh rate in Hz. | |
6800 * I think 15-120 are supposed to be good | |
6801 * values. Though I haven't gotten any effect except | |
6802 * for one strange instance on a Mac. But it was | |
6803 * unrepeatable. | |
6804 */ | |
6805 #if 0 | |
6806 ALC_REFRESH, 15, | |
6807 #endif | |
6808 /* Sync requires a alcProcessContext() call | |
6809 * for every cycle. By default, this is | |
6810 * not used and the value is AL_FALSE | |
6811 * because it will probably perform | |
6812 * pretty badly for me. | |
6813 */ | |
6814 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6815 ALC_SYNC, AL_TRUE, | |
6816 #else | |
6817 ALC_SYNC, AL_FALSE, | |
6818 #endif | |
6819 /* Looking at the API spec, it implies | |
6820 * that the list be a NULL terminated string | |
6821 * so it's probably not safe to use ALC_INVALID | |
6822 */ | |
6823 /* | |
6824 ALC_INVALID }; | |
6825 */ | |
6826 '\0'}; | |
6827 #endif | |
6828 /* Redo: I'm going to allow ALC_REFRESH to be set. | |
6829 * However, if no value is specified, I don't | |
6830 * want it in the list so I can get the OpenAL defaults | |
6831 */ | |
6832 ALint attrlist[7]; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6833 ALsizei current_attrlist_index = 0; |
0 | 6834 |
6835 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6836 /* More problems: I'm getting bit by endian/signedness issues on | |
6837 * different platforms. I can find the endianess easily enough, | |
6838 * but I don't know how to determine what the correct signedness | |
6839 * is (if such a thing exists). I do know that if I try using | |
6840 * unsigned on OSX with an originally signed sample, I get | |
6841 * distortion. However, I don't have any native unsigned samples | |
6842 * to test. But I'm assuming that the platform must be in the | |
6843 * correct signedness no matter what. | |
6844 * I can either assume everybody is signed, or I can try to | |
6845 * determine the value. If I try to determine the values, | |
6846 * I think my only ability to figure it out will be to open | |
6847 * SDL_Audio, and read what the obtained settings were. | |
6848 * Then shutdown everything. However, I don't even know how | |
6849 * reliable this is. | |
6850 * Update: I think I resolved the issues...forgot to update | |
6851 * these comments when it happened. I should check the revision control | |
6852 * log... Anyway, I think the issue was partly related to me not | |
6853 * doing something correctly with the AudioInfo or some kind | |
6854 * of stupid endian bug in my code, and weirdness ensued. Looking at the | |
6855 * revision control, I think I might have assumed that SDL_Sound would | |
6856 * do the right thing with a NULL AudioInfo, but I was incorrect, | |
6857 * and had to fill one out myself. | |
6858 */ | |
6859 SDL_AudioSpec desired; | |
6860 SDL_AudioSpec obtained; | |
6861 #endif | |
6862 | |
6863 | |
6864 | |
6865 | |
6866 /* Make sure ALmixer isn't already initialized */ | |
6867 if(ALmixer_Initialized) | |
6868 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6869 return AL_FALSE; |
0 | 6870 } |
6871 | |
6872 /* Set the defaults */ | |
6873 attrlist[0] = ALC_FREQUENCY; | |
6874 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY; | |
6875 attrlist[2] = ALC_SYNC; | |
6876 #ifdef ENABLE_ALMIXER_ALC_SYNC | |
6877 attrlist[3] = ALC_TRUE; | |
6878 #else | |
6879 attrlist[3] = ALC_FALSE; | |
6880 #endif | |
6881 /* Set frequency value if it is not 0 */ | |
6882 if(0 != frequency) | |
6883 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6884 attrlist[current_attrlist_index] = ALC_FREQUENCY; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6885 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6886 attrlist[current_attrlist_index] = (ALint)frequency; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6887 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6888 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6889 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6890 #ifdef ENABLE_ALMIXER_ALC_SYNC |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6891 attrlist[current_attrlist_index] = ALC_SYNC; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6892 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6893 attrlist[current_attrlist_index] = ALC_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6894 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6895 #endif |
0 | 6896 |
6897 /* If the user specifies a refresh value, | |
6898 * make room for it | |
6899 */ | |
6900 if(0 != refresh) | |
6901 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6902 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
|
6903 current_attrlist_index++; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6904 attrlist[current_attrlist_index] = refresh; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6905 current_attrlist_index++; |
0 | 6906 } |
6907 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6908 /* End attribute list */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6909 attrlist[current_attrlist_index] = '\0'; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6910 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6911 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6912 |
0 | 6913 /* Initialize SDL_Sound */ |
6914 if(! Sound_Init() ) | |
6915 { | |
6916 ALmixer_SetError(Sound_GetError()); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6917 return AL_FALSE; |
0 | 6918 } |
6919 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK | |
6920 /* Here is the paranoid check that opens | |
6921 * SDL audio in an attempt to find the correct | |
6922 * system values. | |
6923 */ | |
6924 /* Doesn't have to be the actual value I think | |
6925 * (as long as it doesn't influence format, in | |
6926 * which case I'm probably screwed anyway because OpenAL | |
6927 * may easily choose to do something else). | |
6928 */ | |
6929 desired.freq = 44100; | |
6930 desired.channels = 2; | |
6931 desired.format = AUDIO_S16SYS; | |
6932 desired.callback = my_dummy_audio_callback; | |
6933 if(SDL_OpenAudio(&desired, &obtained) >= 0) | |
6934 { | |
6935 SIGN_TYPE_16BIT_FORMAT = obtained.format; | |
6936 /* Now to get really paranoid, we should probably | |
6937 * also assume that the 8bit format is also the | |
6938 * same sign type and set that value | |
6939 */ | |
6940 if(AUDIO_S16SYS == obtained.format) | |
6941 { | |
6942 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8; | |
6943 } | |
6944 /* Should be AUDIO_U16SYS */ | |
6945 else | |
6946 { | |
6947 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8; | |
6948 } | |
6949 SDL_CloseAudio(); | |
6950 } | |
6951 else | |
6952 { | |
6953 /* Well, I guess I'm in trouble. I guess it's my best guess | |
6954 */ | |
6955 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS; | |
6956 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8; | |
6957 } | |
6958 #endif | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6959 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6960 #ifndef ALMIXER_COMPILE_WITHOUT_SDL |
0 | 6961 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO) |
6962 * causes OpenAL and SMPEG to conflict. For some reason | |
6963 * if SDL_Init on audio is active, then all the SMPEG | |
6964 * decoded sound comes out silent. Unfortunately, | |
6965 * Sound_Init() invokes SDL_Init on audio. I'm | |
6966 * not sure why it actually needs it... | |
6967 * But we'll attempt to disable it here after the | |
6968 * SDL_Sound::Init call and hope it doesn't break SDL_Sound. | |
6969 */ | |
6970 SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6971 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6972 |
0 | 6973 /* I'm told NULL will call the default string |
6974 * and hopefully do the right thing for each platform | |
6975 */ | |
6976 /* | |
6977 dev = alcOpenDevice( NULL ); | |
6978 */ | |
6979 /* Now I'm told I need to set both the device and context | |
6980 * to have the same sampling rate, so I must pass a string | |
6981 * to OpenDevice(). I don't know how portable these strings are. | |
6982 * I don't even know if the format for strings is | |
6983 * compatible | |
6984 * From the testattrib.c in the Loki test section | |
6985 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" ); | |
6986 */ | |
6987 | |
6988 #ifdef USING_LOKI_AL_DIST | |
6989 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]); | |
6990 dev = alcOpenDevice( (const ALubyte *) device_string ); | |
6991 #else | |
6992 dev = alcOpenDevice( NULL ); | |
6993 #endif | |
6994 if(NULL == dev) | |
6995 { | |
6996 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
|
6997 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6998 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
6999 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7000 #ifdef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7001 /* 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
|
7002 /* 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
|
7003 if(0 != frequency) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7004 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7005 Internal_alcMacOSXMixerOutputRate((ALdouble)frequency); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7006 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7007 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
|
7008 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7009 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
|
7010 */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7011 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7012 |
0 | 7013 |
7014 context = alcCreateContext(dev, attrlist); | |
7015 if(NULL == context) | |
7016 { | |
7017 ALmixer_SetError("Cannot create a context OpenAL"); | |
7018 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7019 return AL_FALSE; |
0 | 7020 } |
7021 | |
7022 | |
7023 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
7024 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
7025 * According to Garin Hiebert, this is actually an inconsistency | |
7026 * in the Loki version. The function should return a boolean. | |
7027 * instead of ALC_NO_ERROR. Garin suggested I check via | |
7028 * alcGetError(). | |
7029 */ | |
7030 /* clear the error */ | |
7031 alcGetError(dev); | |
7032 alcMakeContextCurrent(context); | |
7033 | |
7034 error = alcGetError(dev); | |
7035 if( (ALC_NO_ERROR != error) ) | |
7036 { | |
7037 ALmixer_SetError("Could not MakeContextCurrent"); | |
7038 alcDestroyContext(context); | |
7039 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7040 return AL_FALSE; |
0 | 7041 } |
7042 | |
7043 | |
7044 #if 0 | |
7045 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */ | |
7046 if(alcGetCurrentContext() != context) | |
7047 { | |
7048 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent, | |
7049 * but ALC_NO_ERROR is defined to ALC_FALSE. | |
7050 * I think this is a bug in the OpenAL implementation. | |
7051 */ | |
7052 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context)); | |
7053 | |
7054 fprintf(stderr, "Making context current\n"); | |
7055 #ifndef __APPLE__ | |
7056 if(alcMakeContextCurrent(context) != ALC_NO_ERROR) | |
7057 #else | |
7058 if(!alcMakeContextCurrent(context)) | |
7059 #endif | |
7060 { | |
7061 ALmixer_SetError("Could not MakeContextCurrent"); | |
7062 alcDestroyContext(context); | |
7063 alcCloseDevice(dev); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7064 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7065 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7066 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7067 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7068 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7069 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7070 /* 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
|
7071 * 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
|
7072 * own copy. Yuck. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7073 * 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
|
7074 * 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
|
7075 * The demo is in testattrib.c. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7076 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7077 #ifndef __APPLE__ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7078 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
|
7079 /* |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7080 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
|
7081 */ |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7082 #endif |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7083 |
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7084 |
0 | 7085 |
7086 /* Saw this in the README with the OS X OpenAL distribution. | |
7087 * It looked interesting and simple, so I thought I might | |
7088 * try it out. | |
7089 * ***** ALC_CONVERT_DATA_UPON_LOADING | |
7090 * This extension allows the caller to tell OpenAL to preconvert to the native Core | |
7091 * Audio format, the audio data passed to the | |
7092 * library with the alBufferData() call. Preconverting the audio data, reduces CPU | |
7093 * usage by removing an audio data conversion | |
7094 * (per source) at render timem at the expense of a larger memory footprint. | |
7095 * | |
7096 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This | |
7097 * setting will be applied to all subsequent | |
7098 * calls to alBufferData(). | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7099 * 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
|
7100 * Rather than deal with it right now, I think I am going to make it an opt-in thing. |
0 | 7101 */ |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7102 #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
|
7103 /* |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7104 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
|
7105 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7106 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7107 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7108 #else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7109 /* 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
|
7110 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
|
7111 /* |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7112 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
|
7113 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7114 if(0 != convert_data_enum) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7115 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7116 alEnable(convert_data_enum); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7117 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7118 if( (AL_NO_ERROR != alGetError()) ) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7119 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7120 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
|
7121 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
|
7122 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7123 #endif |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7124 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7125 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7126 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7127 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7128 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7129 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7130 ALboolean ALmixer_InitMixer(ALuint num_sources) |
0 | 7131 { |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7132 ALint i; |
0 | 7133 ALenum error; |
7134 ALuint* source; | |
7135 | |
7136 | |
7137 ALmixer_Initialized = 1; | |
7138 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7139 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7140 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7141 ALmixer_InitTime(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7142 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7143 /* 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
|
7144 /* 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
|
7145 * 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
|
7146 * This is not actually a leak. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7147 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7148 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7149 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7150 s_ALmixerErrorPool = TError_CreateErrorPool(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7151 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7152 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7153 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7154 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7155 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7156 /* |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7157 fprintf(stderr, "tError Test0\n"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7158 ALmixer_SetError("Initing (and testing SetError)"); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7159 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
|
7160 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
|
7161 */ |
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 |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7164 if(num_sources == 0) |
0 | 7165 { |
7166 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS; | |
7167 } | |
7168 else | |
7169 { | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7170 Number_of_Channels_global = (ALint)num_sources; |
0 | 7171 } |
7172 Number_of_Reserve_Channels_global = 0; | |
7173 Is_Playing_global = 0; | |
7174 /* Set to Null in case system quit and was reinitialized */ | |
7175 Channel_Done_Callback = NULL; | |
7176 Channel_Done_Callback_Userdata = NULL; | |
7177 Channel_Data_Callback = NULL; | |
1 | 7178 Channel_Data_Callback_Userdata = NULL; |
0 | 7179 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7180 /* Allocate memory for linked list of ALmixerData. */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7181 s_listOfALmixerData = LinkedList_Create(); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7182 if(NULL == s_listOfALmixerData) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7183 { |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7184 ALmixer_SetError("Couldn't create linked list"); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7185 ALmixer_Initialized = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7186 Number_of_Channels_global = 0; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7187 return AL_FALSE; |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7188 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7189 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7190 |
0 | 7191 /* Allocate memory for the list of channels */ |
7192 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel)); | |
7193 if(NULL == ALmixer_Channel_List) | |
7194 { | |
7195 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
|
7196 LinkedList_Free(s_listOfALmixerData); |
0 | 7197 ALmixer_Initialized = 0; |
7198 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7199 return AL_FALSE; |
0 | 7200 } |
7201 | |
7202 /* Allocate memory for the list of sources that map to the channels */ | |
7203 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map)); | |
7204 if(NULL == Source_Map_List) | |
7205 { | |
7206 ALmixer_SetError("Out of Memory for Source Map List"); | |
7207 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7208 LinkedList_Free(s_listOfALmixerData); |
0 | 7209 ALmixer_Initialized = 0; |
7210 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7211 return AL_FALSE; |
0 | 7212 } |
7213 | |
7214 /* Create array that will hold the sources */ | |
7215 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint)); | |
7216 if(NULL == source) | |
7217 { | |
7218 ALmixer_SetError("Out of Memory for sources"); | |
7219 free(Source_Map_List); | |
7220 free(ALmixer_Channel_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7221 LinkedList_Free(s_listOfALmixerData); |
0 | 7222 ALmixer_Initialized = 0; |
7223 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7224 return AL_FALSE; |
0 | 7225 } |
7226 | |
7227 /* Clear the error state */ | |
7228 alGetError(); | |
7229 /* Generate the OpenAL sources */ | |
7230 alGenSources(Number_of_Channels_global, source); | |
7231 if( (error=alGetError()) != AL_NO_ERROR) | |
7232 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7233 ALmixer_SetError("Couldn't generate sources: %s\n", alGetString(error)); |
0 | 7234 free(ALmixer_Channel_List); |
7235 free(Source_Map_List); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7236 LinkedList_Free(s_listOfALmixerData); |
0 | 7237 ALmixer_Initialized = 0; |
7238 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7239 return AL_FALSE; |
0 | 7240 } |
7241 | |
7242 /* Initialize each channel and associate one source to one channel */ | |
7243 for(i=0; i<Number_of_Channels_global; i++) | |
7244 { | |
7245 Init_Channel(i); | |
7246 /* Keeping the source allocation out of the Init function | |
7247 * in case I want to reuse the Init | |
7248 * function for resetting data | |
7249 */ | |
7250 ALmixer_Channel_List[i].alsource = source[i]; | |
7251 /* Now also keep a copy of the source to channel mapping | |
7252 * in case we need to look up a channel from the source | |
7253 * instead of a source from a channel | |
7254 */ | |
7255 Source_Map_List[i].source = source[i]; | |
7256 Source_Map_List[i].channel = i; | |
7257 /* Clean the channel because there are some things that need to | |
7258 * be done that can't happen until the source is set | |
7259 */ | |
7260 Clean_Channel(i); | |
7261 } | |
7262 | |
7263 /* The Source_Map_List must be sorted by source for binary searches | |
7264 */ | |
7265 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map); | |
7266 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7267 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7268 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7269 s_simpleLock = SDL_CreateMutex(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7270 if(NULL == s_simpleLock) |
0 | 7271 { |
7272 /* SDL sets the error message already? */ | |
7273 free(source); | |
7274 free(ALmixer_Channel_List); | |
7275 free(Source_Map_List); | |
7276 ALmixer_Initialized = 0; | |
7277 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7278 return AL_FALSE; |
0 | 7279 } |
7280 | |
7281 | |
7282 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL); | |
7283 if(NULL == Stream_Thread_global) | |
7284 { | |
7285 /* 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
|
7286 SDL_DestroyMutex(s_simpleLock); |
0 | 7287 free(source); |
7288 free(ALmixer_Channel_List); | |
7289 free(Source_Map_List); | |
7290 ALmixer_Initialized = 0; | |
7291 Number_of_Channels_global = 0; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7292 return AL_FALSE; |
0 | 7293 } |
7294 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7295 /* |
0 | 7296 fprintf(stderr, "Using threads\n"); |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7297 */ |
0 | 7298 #endif /* End of ENABLE_ALMIXER_THREADS */ |
7299 | |
7300 /* We don't need this array any more because all the sources | |
7301 * are connected to channels | |
7302 */ | |
7303 free(source); | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7304 return AL_TRUE; |
0 | 7305 } |
7306 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7307 void ALmixer_BeginInterruption() |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7308 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7309 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7310 SDL_LockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7311 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7312 s_interruptionContext = alcGetCurrentContext(); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7313 if(NULL != s_interruptionContext) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7314 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7315 /* iOS alcSuspendContext is a no-op */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7316 alcSuspendContext(s_interruptionContext); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7317 alcMakeContextCurrent(NULL); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7318 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7319 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7320 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7321 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7322 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7323 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7324 void ALmixer_EndInterruption() |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7325 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7326 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7327 SDL_LockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7328 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7329 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7330 /* Note: iOS, you need to set the AudioSession active. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7331 * But if the AudioSession is not initialized, this SetActive |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7332 * call fails. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7333 * 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
|
7334 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7335 /* |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7336 #if (TARGET_OS_IPHONE == 1) || (TARGET_IPHONE_SIMULATOR == 1) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7337 OSStatus the_error = AudioSessionSetActive(true); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7338 if(noErr != the_error) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7339 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7340 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
|
7341 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7342 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7343 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7344 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7345 if(NULL != s_interruptionContext) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7346 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7347 alcMakeContextCurrent(s_interruptionContext); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7348 alcProcessContext(s_interruptionContext); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7349 s_interruptionContext = NULL; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7350 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7351 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7352 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7353 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7354 } |
0 | 7355 |
7356 /* Keep the return value void to allow easy use with | |
7357 * atexit() | |
7358 */ | |
7359 void ALmixer_Quit() | |
7360 { | |
7361 ALCcontext* context; | |
7362 ALCdevice* dev; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7363 ALint i; |
0 | 7364 |
7365 if( ! ALmixer_Initialized) | |
7366 { | |
7367 return; | |
7368 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7369 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7370 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7371 #endif |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7372 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7373 /* Several things we need to do: |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7374 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
|
7375 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
|
7376 Next, we should delete the OpenAL sources. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7377 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
|
7378 Finally, we can delete the OpenAL context. |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7379 */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7380 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7381 context = alcGetCurrentContext(); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7382 if(NULL == context) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7383 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7384 /* 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
|
7385 if(NULL == s_interruptionContext) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7386 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7387 /* Nothing left to try. I think we're done. */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7388 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
|
7389 return; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7390 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7391 else |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7392 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7393 context = s_interruptionContext; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7394 /* reactivate the context so we can call OpenAL functions */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7395 alcMakeContextCurrent(context); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7396 s_interruptionContext = NULL; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7397 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7398 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7399 |
0 | 7400 /* Shutdown everything before closing context */ |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7401 Internal_HaltChannel(-1, AL_FALSE); |
0 | 7402 |
7403 /* This flag will cause the thread to terminate */ | |
7404 ALmixer_Initialized = 0; | |
7405 #ifdef ENABLE_ALMIXER_THREADS | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7406 SDL_UnlockMutex(s_simpleLock); |
0 | 7407 SDL_WaitThread(Stream_Thread_global, NULL); |
7408 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7409 SDL_DestroyMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7410 #endif |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7411 |
0 | 7412 /* Delete all the OpenAL sources */ |
7413 for(i=0; i<Number_of_Channels_global; i++) | |
7414 { | |
7415 alDeleteSources(1, &ALmixer_Channel_List[i].alsource); | |
7416 } | |
7417 /* Delete all the channels */ | |
7418 free(ALmixer_Channel_List); | |
7419 free(Source_Map_List); | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7420 |
0 | 7421 /* Reset the Number_of_Channels just in case somebody |
7422 * tries using a ALmixer function. | |
7423 * I probably should put "Initialized" checks everywhere, | |
7424 * but I'm too lazy at the moment. | |
7425 */ | |
7426 Number_of_Channels_global = 0; | |
7427 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7428 |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7429 /* 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
|
7430 * 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
|
7431 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7432 while(LinkedList_Size(s_listOfALmixerData) > 0) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7433 { |
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
|
7434 /* 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
|
7435 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
|
7436 ALmixer_FreeData(almixer_data); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7437 } |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7438 LinkedList_Free(s_listOfALmixerData); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
7439 s_listOfALmixerData = NULL; |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7440 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7441 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7442 /* 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
|
7443 dev = alcGetContextsDevice(context); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7444 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7445 alcMakeContextCurrent(NULL); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7446 alcDestroyContext(context); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7447 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7448 if(NULL == dev) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7449 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7450 return; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7451 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7452 alcCloseDevice(dev); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7453 |
0 | 7454 Sound_Quit(); |
7455 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7456 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7457 /* 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
|
7458 TError_FreeErrorPool(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7459 s_ALmixerErrorPool = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7460 #endif |
0 | 7461 return; |
7462 } | |
7463 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7464 ALboolean ALmixer_IsInitialized() |
0 | 7465 { |
7466 return ALmixer_Initialized; | |
7467 } | |
7468 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7469 ALuint ALmixer_GetFrequency() |
0 | 7470 { |
7471 return ALmixer_Frequency_global; | |
7472 } | |
7473 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7474 const ALmixer_version* ALmixer_GetLinkedVersion() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7475 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7476 static ALmixer_version linked_mixver; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7477 ALMIXER_GET_COMPILED_VERSION(&linked_mixver); |
0 | 7478 return(&linked_mixver); |
7479 } | |
7480 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7481 #ifdef ALMIXER_COMPILE_WITHOUT_SDL |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7482 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7483 const char* ALmixer_GetError() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7484 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7485 const char* error_string = NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7486 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7487 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7488 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
|
7489 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7490 error_string = TError_GetLastErrorStr(s_ALmixerErrorPool); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7491 /* 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
|
7492 if(NULL == error_string) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7493 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7494 return ""; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7495 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7496 else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7497 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7498 return error_string; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7499 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7500 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7501 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7502 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
|
7503 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7504 if(NULL == s_ALmixerErrorPool) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7505 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7506 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
|
7507 return; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7508 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7509 va_list argp; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7510 va_start(argp, err_str); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7511 // 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
|
7512 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
|
7513 va_end(argp); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7514 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7515 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7516 #endif |
0 | 7517 |
7518 | |
7519 | |
7520 | |
7521 #if 0 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7522 void ALmixer_OutputAttributes() |
0 | 7523 { |
7524 ALint num_flags = 0; | |
7525 ALint* flags = 0; | |
7526 int i; | |
7527 ALCdevice* dev = alcGetContextsDevice( alcGetCurrentContext() ); | |
7528 | |
7529 | |
7530 printf("custom context\n"); | |
7531 | |
7532 alcGetIntegerv(dev, ALC_ATTRIBUTES_SIZE, | |
7533 sizeof num_flags, &num_flags ); | |
7534 | |
7535 printf("Number of Flags: %d\n", num_flags); | |
7536 | |
7537 if(num_flags) | |
7538 { | |
7539 flags = malloc(sizeof(num_flags) * sizeof(ALint)); | |
7540 | |
7541 alcGetIntegerv(dev, ALC_ALL_ATTRIBUTES, | |
7542 sizeof num_flags * sizeof(ALint), | |
7543 flags ); | |
7544 } | |
7545 for(i = 0; i < num_flags-1; i += 2) | |
7546 { | |
7547 printf("key 0x%x : value %d\n", | |
7548 flags[i], flags[i+1]); | |
7549 } | |
7550 free(flags); | |
7551 } | |
7552 #endif | |
7553 | |
7554 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7555 void ALmixer_OutputDecoders() |
0 | 7556 { |
7557 Sound_Version sound_compile_version; | |
7558 Sound_Version sound_link_version; | |
7559 | |
7560 const Sound_DecoderInfo **rc = Sound_AvailableDecoders(); | |
7561 const Sound_DecoderInfo **i; | |
7562 const char **ext; | |
7563 FILE* stream = stdout; | |
7564 | |
7565 | |
7566 fprintf(stream, "SDL_sound Information:\n"); | |
7567 | |
7568 SOUND_VERSION(&sound_compile_version); | |
7569 fprintf(stream, "\tCompiled with SDL_sound version: %d.%d.%d\n", | |
7570 sound_compile_version.major, | |
7571 sound_compile_version.minor, | |
7572 sound_compile_version.patch); | |
7573 | |
7574 Sound_GetLinkedVersion(&sound_link_version); | |
7575 fprintf(stream, "\tRunning (linked) with SDL_sound version: %d.%d.%d\n", | |
7576 sound_link_version.major, | |
7577 sound_link_version.minor, | |
7578 sound_link_version.patch); | |
7579 | |
7580 fprintf(stream, "Supported sound formats:\n"); | |
7581 if (rc == NULL) | |
7582 fprintf(stream, " * Apparently, NONE!\n"); | |
7583 else | |
7584 { | |
7585 for (i = rc; *i != NULL; i++) | |
7586 { | |
7587 fprintf(stream, " * %s\n", (*i)->description); | |
7588 | |
7589 for (ext = (*i)->extensions; *ext != NULL; ext++) | |
7590 fprintf(stream, " File extension \"%s\"\n", *ext); | |
7591 | |
7592 fprintf(stream, " Written by %s.\n %s\n\n", | |
7593 (*i)->author, (*i)->url); | |
7594 } /* for */ | |
7595 } /* else */ | |
7596 | |
7597 fprintf(stream, "\n"); | |
7598 } | |
7599 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7600 void ALmixer_OutputOpenALInfo() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7601 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7602 ALmixer_version mixer_compile_version; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7603 const ALmixer_version * mixer_link_version=ALmixer_GetLinkedVersion(); |
0 | 7604 FILE* stream = stdout; |
7605 | |
7606 fprintf(stream, "OpenAL Information:\n"); | |
7607 fprintf(stream, "\tAL_VENDOR: %s\n", alGetString( AL_VENDOR ) ); | |
7608 fprintf(stream, "\tAL_VERSION: %s\n", alGetString( AL_VERSION ) ); | |
7609 fprintf(stream, "\tAL_RENDERER: %s\n", alGetString( AL_RENDERER ) ); | |
7610 fprintf(stream, "\tAL_EXTENSIONS: %s\n", alGetString( AL_EXTENSIONS ) ); | |
7611 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7612 ALMIXER_GET_COMPILED_VERSION(&mixer_compile_version); |
0 | 7613 fprintf(stream, "\nSDL_ALmixer Information:\n"); |
7614 fprintf(stream, "\tCompiled with SDL_ALmixer version: %d.%d.%d\n", | |
7615 mixer_compile_version.major, | |
7616 mixer_compile_version.minor, | |
7617 mixer_compile_version.patch); | |
7618 | |
7619 fprintf(stream, "\tRunning (linked) with SDL_ALmixer version: %d.%d.%d\n", | |
7620 mixer_link_version->major, | |
7621 mixer_link_version->minor, | |
7622 mixer_link_version->patch); | |
7623 | |
7624 fprintf(stream, "\tCompile flags: "); | |
7625 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK | |
7626 fprintf(stream, "ENABLE_LOKI_QUEUE_FIX_HACK "); | |
7627 #endif | |
7628 #ifdef ENABLE_ALMIXER_THREADS | |
7629 fprintf(stream, "ENABLE_ALMIXER_THREADS "); | |
7630 #endif | |
7631 #ifdef ENABLE_ALC_SYNC | |
7632 fprintf(stream, "ENABLE_ALC_SYNC "); | |
7633 #endif | |
7634 fprintf(stream, "\n"); | |
7635 } | |
7636 | |
7637 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7638 ALint ALmixer_AllocateChannels(ALint numchans) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7639 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7640 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7641 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7642 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7643 #endif |
0 | 7644 retval = Internal_AllocateChannels(numchans); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7645 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7646 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7647 #endif |
0 | 7648 return retval; |
7649 } | |
7650 | |
7651 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7652 ALint ALmixer_ReserveChannels(ALint num) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7653 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7654 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7655 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7656 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7657 #endif |
0 | 7658 retval = Internal_ReserveChannels(num); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7659 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7660 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7661 #endif |
0 | 7662 return retval; |
7663 } | |
7664 | |
7665 | |
7666 | |
7667 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7668 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
|
7669 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7670 ALuint bytes_decoded; |
0 | 7671 ALmixer_Data* ret_data; |
7672 ALenum error; | |
7673 | |
7674 /* Allocate memory */ | |
7675 ret_data = (ALmixer_Data *)malloc(sizeof(ALmixer_Data)); | |
7676 if (NULL == ret_data) | |
7677 { | |
7678 ALmixer_SetError("Out of memory"); | |
7679 return(NULL); | |
7680 } | |
7681 | |
7682 /* Initialize the data fields */ | |
7683 | |
7684 /* Set the Sound_Sample pointer */ | |
7685 ret_data->sample = sample; | |
7686 | |
7687 /* Flag the data to note that it is not in use */ | |
7688 ret_data->in_use = 0; | |
7689 | |
7690 /* Initialize remaining flags */ | |
7691 ret_data->total_time = -1; | |
7692 ret_data->eof = 0; | |
7693 | |
7694 /* Just initialize */ | |
7695 ret_data->num_buffers_in_use = 0; | |
7696 | |
7697 /* Just initialize */ | |
7698 ret_data->total_bytes = 0; | |
7699 | |
7700 /* Just initialize */ | |
7701 ret_data->loaded_bytes = 0; | |
7702 | |
7703 /* Set the max queue buffers (minimum must be 2) */ | |
7704 if(max_queue_buffers < 2) | |
7705 { | |
7706 max_queue_buffers = ALMIXER_DEFAULT_QUEUE_BUFFERS; | |
7707 } | |
7708 ret_data->max_queue_buffers = max_queue_buffers; | |
7709 /* Set up the start up buffers */ | |
7710 if(0 == num_startup_buffers) | |
7711 { | |
7712 num_startup_buffers = ALMIXER_DEFAULT_STARTUP_BUFFERS; | |
7713 } | |
7714 /* Make sure start up buffers is less or equal to max_queue_buffers */ | |
7715 if(num_startup_buffers > max_queue_buffers) | |
7716 { | |
7717 num_startup_buffers = max_queue_buffers; | |
7718 } | |
7719 ret_data->num_startup_buffers = num_startup_buffers; | |
7720 | |
7721 ret_data->buffer_map_list = NULL; | |
7722 ret_data->current_buffer = 0; | |
7723 | |
7724 ret_data->circular_buffer_queue = NULL; | |
7725 | |
7726 /* Now decode and load the data into a data chunk */ | |
7727 /* Different cases for Streamed and Predecoded | |
7728 * Streamed might turn into a predecoded if buffersize | |
7729 * is large enough */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7730 if(AL_FALSE == decode_mode_is_predecoded) |
0 | 7731 { |
7732 bytes_decoded = Sound_Decode(sample); | |
7733 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7734 { | |
7735 ALmixer_SetError(Sound_GetError()); | |
7736 Sound_FreeSample(sample); | |
7737 free(ret_data); | |
7738 return NULL; | |
7739 } | |
7740 | |
7741 /* If no data, return an error */ | |
7742 if(0 == bytes_decoded) | |
7743 { | |
7744 ALmixer_SetError("File has no data"); | |
7745 Sound_FreeSample(sample); | |
7746 free(ret_data); | |
7747 return NULL; | |
7748 } | |
7749 | |
7750 /* Note, currently, my Ogg conservative modifications | |
7751 * prevent EOF from being detected in the first read | |
7752 * because of the weird packet behavior of ov_read(). | |
7753 * The EAGAIN will get set, but not the EOF. | |
7754 * I don't know the best way to handle this, | |
7755 * so for now, Ogg's can only be explicitly | |
7756 * predecoded. | |
7757 */ | |
7758 | |
7759 /* Correction: Since we no longer actually keep the | |
7760 * streamed data we read here (we rewind and throw | |
7761 * it away, and start over on Play), it is | |
7762 * safe to read another chunk to see if we've hit EOF | |
7763 */ | |
7764 if(sample->flags & SOUND_SAMPLEFLAG_EAGAIN) | |
7765 { | |
7766 bytes_decoded = Sound_Decode(sample); | |
7767 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
7768 { | |
7769 ALmixer_SetError(Sound_GetError()); | |
7770 Sound_FreeSample(sample); | |
7771 free(ret_data); | |
7772 return NULL; | |
7773 } | |
7774 } | |
7775 | |
7776 | |
7777 /* If we found an EOF, the entire file was | |
7778 * decoded, so we can treat it like one. | |
7779 */ | |
7780 | |
7781 if(sample->flags & SOUND_SAMPLEFLAG_EOF) | |
7782 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7783 /* |
0 | 7784 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
|
7785 */ |
0 | 7786 ret_data->decoded_all = 1; |
7787 /* Need to keep this information around for | |
7788 * seek and rewind abilities. | |
7789 */ | |
7790 ret_data->total_bytes = bytes_decoded; | |
7791 /* For now, the loaded bytes is the same as total bytes, but | |
7792 * this could change during a seek operation | |
7793 */ | |
7794 ret_data->loaded_bytes = bytes_decoded; | |
7795 | |
7796 /* Let's compute the total playing time | |
7797 * SDL_sound does not yet provide this (we're working on | |
7798 * that at the moment...) | |
7799 */ | |
7800 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
7801 | |
7802 /* Create one element in the buffer array for data for OpanAL */ | |
7803 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
7804 if(NULL == ret_data->buffer) | |
7805 { | |
7806 ALmixer_SetError("Out of Memory"); | |
7807 Sound_FreeSample(sample); | |
7808 free(ret_data); | |
7809 return NULL; | |
7810 } | |
7811 /* Clear the error code */ | |
7812 alGetError(); | |
7813 /* Now generate an OpenAL buffer using that first element */ | |
7814 alGenBuffers(1, ret_data->buffer); | |
7815 if( (error = alGetError()) != AL_NO_ERROR) | |
7816 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7817 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7818 Sound_FreeSample(sample); |
7819 free(ret_data->buffer); | |
7820 free(ret_data); | |
7821 return NULL; | |
7822 } | |
7823 | |
7824 | |
7825 /* Now copy the data to the OpenAL buffer */ | |
7826 /* We can't just set a pointer because the API needs | |
7827 * its own copy to assist hardware acceleration */ | |
7828 alBufferData(ret_data->buffer[0], | |
7829 TranslateFormat(&sample->desired), | |
7830 sample->buffer, | |
7831 bytes_decoded, | |
7832 sample->desired.rate | |
7833 ); | |
7834 if( (error = alGetError()) != AL_NO_ERROR) | |
7835 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7836 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 7837 Sound_FreeSample(sample); |
7838 alDeleteBuffers(1, ret_data->buffer); | |
7839 free(ret_data->buffer); | |
7840 free(ret_data); | |
7841 return NULL; | |
7842 } | |
7843 | |
7844 /* We should be done with the sample since it's all | |
7845 * predecoded. So we can free the memory */ | |
7846 | |
7847 /* Additional notes: | |
7848 * We need to keep data around in case Seek() is needed | |
7849 * or other Sound_AudioInfo is needed. | |
7850 * This can either be done by not deleting the sample, | |
7851 * or it can be done by dynamically recreating it | |
7852 * when we need it. | |
7853 */ | |
7854 /* Since OpenAL won't let us retrieve it | |
7855 * (aka dynamically), we have to keep the Sample | |
7856 * around because since the user requested | |
7857 * streamed and we offered predecoded, | |
7858 * we don't want to mess up the user who | |
7859 * was expecting seek support | |
7860 * So Don't Do anything | |
7861 */ | |
7862 /* | |
7863 if(0 == access_data) | |
7864 { | |
7865 Sound_FreeSample(sample); | |
7866 ret_data->sample = NULL; | |
7867 } | |
7868 */ | |
7869 /* Else, We keep a copy of the sample around. | |
7870 * so don't do anything. | |
7871 */ | |
7872 | |
7873 #if 0 | |
7874 #if defined(DISABLE_PREDECODED_SEEK) | |
7875 Sound_FreeSample(sample); | |
7876 ret_data->sample = NULL; | |
7877 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
7878 Sound_FreeSample(sample); | |
7879 ret_data->sample = NULL; | |
7880 #else | |
7881 /* We keep a copy of the sample around. | |
7882 * so don't do anything. | |
7883 */ | |
7884 #endif | |
7885 #endif | |
7886 /* okay we're done here */ | |
7887 | |
7888 } | |
7889 /* Else, we need to stream the data, so we'll | |
7890 * create multple buffers for queuing */ | |
7891 else | |
7892 { | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
7893 /* |
0 | 7894 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
|
7895 */ |
0 | 7896 ret_data->decoded_all = 0; |
7897 | |
7898 /* This information is for predecoded. | |
7899 * Set to 0, since we don't know. | |
7900 */ | |
7901 ret_data->total_bytes = 0; | |
7902 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7903 ret_data->total_time = Sound_GetDuration(sample); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
7904 |
0 | 7905 /* Create buffers for data |
7906 */ | |
7907 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) * max_queue_buffers); | |
7908 if(NULL == ret_data->buffer) | |
7909 { | |
7910 ALmixer_SetError("Out of Memory"); | |
7911 Sound_FreeSample(sample); | |
7912 free(ret_data); | |
7913 return NULL; | |
7914 } | |
7915 | |
7916 /* Clear the error code */ | |
7917 alGetError(); | |
7918 /* Now generate an OpenAL buffer using that first element */ | |
7919 alGenBuffers(max_queue_buffers, ret_data->buffer); | |
7920 if( (error = alGetError()) != AL_NO_ERROR) | |
7921 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7922 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 7923 Sound_FreeSample(sample); |
7924 free(ret_data->buffer); | |
7925 free(ret_data); | |
7926 return NULL; | |
7927 } | |
7928 | |
7929 /* Redesign: Okay, because of the unqueuing problems and such, | |
7930 * I've decided to redesign where and how queuing is handled. | |
7931 * Before, everything was queued up here. However, this | |
7932 * placed a penalty on load and made performance inconsistent | |
7933 * when samples had to be rewound. It did make things easier | |
7934 * to queue because I could let OpenAL decide which buffer | |
7935 * needed to be queued next. | |
7936 * Now, I'm going to push off the queuing to the actual | |
7937 * Play() command. I'm going to add some book keeping, | |
7938 * and allow for additional buffers to be filled at later | |
7939 * times. | |
7940 */ | |
7941 | |
7942 | |
7943 /* So first of all, because of I already decoded the sample | |
7944 * for testing, I need to decide what to do with it. | |
7945 * The best thing would be be to alBufferData() it. | |
7946 * The problem is it may conflict with the rest of | |
7947 * the system because everything now assumes buffers | |
7948 * are entirely stripped (because of the unqueing | |
7949 * problem). | |
7950 * So it looks like I have to do the crappy thing | |
7951 * and throw away the data, and rewind. | |
7952 */ | |
7953 | |
7954 if(0 == Sound_Rewind(ret_data->sample)) | |
7955 { | |
7956 ALmixer_SetError("Cannot use sample for streamed data because it must be rewindable: %s", Sound_GetError() ); | |
7957 Sound_FreeSample(sample); | |
7958 free(ret_data->buffer); | |
7959 free(ret_data); | |
7960 return NULL; | |
7961 } | |
7962 | |
7963 | |
7964 /* If the user has selected access_data, we need to | |
7965 * keep copies of the queuing buffers around because | |
7966 * OpenAL won't let us access the data. | |
7967 * Allocate the memory for the buffers here | |
7968 * and initialize the albuffer-index map | |
7969 */ | |
7970 if(access_data) | |
7971 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
7972 ALuint j; |
0 | 7973 /* Create buffers for data access |
7974 * Should be the same number as the number of queue buffers | |
7975 */ | |
1 | 7976 ret_data->buffer_map_list = (ALmixer_Buffer_Map*)malloc( sizeof(ALmixer_Buffer_Map) * max_queue_buffers); |
0 | 7977 if(NULL == ret_data->buffer_map_list) |
7978 { | |
7979 ALmixer_SetError("Out of Memory"); | |
7980 Sound_FreeSample(sample); | |
7981 free(ret_data->buffer); | |
7982 free(ret_data); | |
7983 return NULL; | |
7984 } | |
7985 | |
7986 ret_data->circular_buffer_queue = CircularQueueUnsignedInt_CreateQueue(max_queue_buffers); | |
7987 if(NULL == ret_data->circular_buffer_queue) | |
7988 { | |
7989 ALmixer_SetError("Out of Memory"); | |
7990 free(ret_data->buffer_map_list); | |
7991 Sound_FreeSample(sample); | |
7992 free(ret_data->buffer); | |
7993 free(ret_data); | |
7994 return NULL; | |
7995 } | |
7996 | |
7997 | |
7998 for(j=0; j<max_queue_buffers; j++) | |
7999 { | |
8000 ret_data->buffer_map_list[j].albuffer = ret_data->buffer[j]; | |
8001 ret_data->buffer_map_list[j].index = j; | |
8002 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
|
8003 ret_data->buffer_map_list[j].data = (ALbyte*)malloc( sizeof(ALbyte) * buffersize); |
0 | 8004 if(NULL == ret_data->buffer_map_list[j].data) |
8005 { | |
8006 ALmixer_SetError("Out of Memory"); | |
8007 break; | |
8008 } | |
8009 } | |
8010 /* If an error happened, we have to clean up the memory */ | |
8011 if(j < max_queue_buffers) | |
8012 { | |
8013 fprintf(stderr, "################## Buffer allocation failed\n"); | |
8014 for( ; j>=0; j--) | |
8015 { | |
8016 free(ret_data->buffer_map_list[j].data); | |
8017 } | |
8018 free(ret_data->buffer_map_list); | |
8019 CircularQueueUnsignedInt_FreeQueue(ret_data->circular_buffer_queue); | |
8020 Sound_FreeSample(sample); | |
8021 free(ret_data->buffer); | |
8022 free(ret_data); | |
8023 return NULL; | |
8024 } | |
8025 | |
8026 /* The Buffer_Map_List must be sorted by albuffer for binary searches | |
8027 */ | |
1 | 8028 qsort(ret_data->buffer_map_list, max_queue_buffers, sizeof(ALmixer_Buffer_Map), Compare_Buffer_Map); |
0 | 8029 } /* End if access_data==true */ |
8030 | |
8031 | |
8032 } /* End of do stream */ | |
8033 } /* end of DECODE_STREAM */ | |
8034 /* 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
|
8035 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
|
8036 { |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8037 #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
|
8038 /* 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
|
8039 * 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
|
8040 * 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
|
8041 * so looping isn't needed. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8042 * 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
|
8043 * 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
|
8044 * 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
|
8045 * 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
|
8046 * 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
|
8047 * 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
|
8048 * to load a file. |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8049 */ |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8050 ALint sound_duration = Sound_GetDuration(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8051 if(sound_duration > 0) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8052 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8053 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
|
8054 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
|
8055 if(0 == buffer_resize_succeeded) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8056 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8057 ALmixer_SetError(Sound_GetError()); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8058 Sound_FreeSample(sample); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8059 free(ret_data); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8060 return NULL; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8061 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8062 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8063 #endif /* ALMIXER_DISABLE_PREDECODED_PRECOMPUTE_BUFFER_SIZE_OPTIMIZATION */ |
0 | 8064 bytes_decoded = Sound_DecodeAll(sample); |
8065 if(sample->flags & SOUND_SAMPLEFLAG_ERROR) | |
8066 { | |
8067 ALmixer_SetError(Sound_GetError()); | |
8068 Sound_FreeSample(sample); | |
8069 free(ret_data); | |
8070 return NULL; | |
8071 } | |
8072 | |
8073 /* If no data, return an error */ | |
8074 if(0 == bytes_decoded) | |
8075 { | |
8076 ALmixer_SetError("File has no data"); | |
8077 Sound_FreeSample(sample); | |
8078 free(ret_data); | |
8079 return NULL; | |
8080 } | |
8081 | |
8082 | |
8083 ret_data->decoded_all = 1; | |
8084 /* Need to keep this information around for | |
8085 * seek and rewind abilities. | |
8086 */ | |
8087 ret_data->total_bytes = bytes_decoded; | |
8088 /* For now, the loaded bytes is the same as total bytes, but | |
8089 * this could change during a seek operation | |
8090 */ | |
8091 ret_data->loaded_bytes = bytes_decoded; | |
8092 | |
8093 /* Let's compute the total playing time | |
8094 * SDL_sound does not yet provide this (we're working on | |
8095 * that at the moment...) | |
8096 */ | |
8097 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded); | |
8098 | |
8099 /* Create one element in the buffer array for data for OpanAL */ | |
8100 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) ); | |
8101 if(NULL == ret_data->buffer) | |
8102 { | |
8103 ALmixer_SetError("Out of Memory"); | |
8104 Sound_FreeSample(sample); | |
8105 free(ret_data); | |
8106 return NULL; | |
8107 } | |
8108 /* Clear the error code */ | |
8109 alGetError(); | |
8110 /* Now generate an OpenAL buffer using that first element */ | |
8111 alGenBuffers(1, ret_data->buffer); | |
8112 if( (error = alGetError()) != AL_NO_ERROR) | |
8113 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8114 ALmixer_SetError("alGenBuffers failed: %s\n", alGetString(error)); |
0 | 8115 Sound_FreeSample(sample); |
8116 free(ret_data->buffer); | |
8117 free(ret_data); | |
8118 return NULL; | |
8119 } | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8120 /* |
0 | 8121 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
|
8122 */ |
0 | 8123 /* Now copy the data to the OpenAL buffer */ |
8124 /* We can't just set a pointer because the API needs | |
8125 * its own copy to assist hardware acceleration */ | |
8126 alBufferData(ret_data->buffer[0], | |
8127 TranslateFormat(&sample->desired), | |
8128 sample->buffer, | |
8129 bytes_decoded, | |
8130 sample->desired.rate | |
8131 ); | |
8132 if( (error = alGetError()) != AL_NO_ERROR) | |
8133 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8134 ALmixer_SetError("alBufferData failed: %s\n", alGetString(error)); |
0 | 8135 Sound_FreeSample(sample); |
8136 alDeleteBuffers(1, ret_data->buffer); | |
8137 free(ret_data->buffer); | |
8138 free(ret_data); | |
8139 return NULL; | |
8140 } | |
8141 | |
8142 /* We should be done with the sample since it's all | |
8143 * predecoded. So we can free the memory */ | |
8144 /* Need to keep around because Seek() needs it */ | |
8145 | |
8146 /* Additional notes: | |
8147 * We need to keep data around in case Seek() is needed | |
8148 * or other Sound_AudioInfo is needed. | |
8149 * This can either be done by not deleting the sample, | |
8150 * or it can be done by dynamically recreating it | |
8151 * when we need it. | |
8152 * Update: I think now it's up to the user by passing the | |
8153 * access_data flag. If they set the flag, then they get | |
8154 * data callbacks and seek support. If not, then they can | |
8155 * get all that stuff at the expense of keeping extra memory | |
8156 * around. | |
8157 */ | |
8158 if(0 == access_data) | |
8159 { | |
8160 Sound_FreeSample(sample); | |
8161 ret_data->sample = NULL; | |
8162 } | |
8163 | |
8164 /* Else, We keep a copy of the sample around. | |
8165 * so don't do anything. | |
8166 */ | |
8167 #if 0 | |
8168 #if defined(DISABLE_PREDECODED_SEEK) | |
8169 Sound_FreeSample(sample); | |
8170 ret_data->sample = NULL; | |
8171 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION) | |
8172 Sound_FreeSample(sample); | |
8173 ret_data->sample = NULL; | |
8174 #else | |
8175 /* We keep a copy of the sample around. | |
8176 * so don't do anything. | |
8177 */ | |
8178 #endif | |
8179 #endif | |
8180 | |
8181 /* okay we're done here */ | |
8182 } | |
8183 else | |
8184 { | |
8185 /* Shouldn't get here */ | |
8186 ALmixer_SetError("Unknown decode mode"); | |
8187 Sound_FreeSample(sample); | |
8188 free(ret_data); | |
8189 return NULL; | |
8190 } | |
8191 | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8192 /* 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
|
8193 * 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
|
8194 */ |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8195 LinkedList_PushBack(s_listOfALmixerData, ret_data); |
0 | 8196 return ret_data; |
8197 } | |
8198 | |
8199 | |
8200 /* This will load a sample for us. Most of the uglyness is | |
8201 * error checking and the fact that streamed/predecoded files | |
8202 * must be treated differently. | |
8203 * I don't like the AudioInfo parameter. I removed it once, | |
8204 * but the system will fail on RAW samples because the user | |
8205 * must specify it, so I had to bring it back. | |
8206 * Remember I must close the rwops if there is an error before NewSample() | |
8207 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8208 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 | 8209 { |
8210 Sound_Sample* sample = NULL; | |
8211 Sound_AudioInfo target; | |
8212 | |
8213 /* Initialize target values to defaults | |
8214 * 0 tells SDL_sound to use the "actual" values | |
8215 */ | |
8216 target.channels = 0; | |
8217 target.rate = 0; | |
8218 #if 0 | |
8219 /* This requires my new additions to SDL_sound. It will | |
8220 * convert the sample to the proper endian order. | |
8221 * If the actual is 8-bit, it will do unsigned, if | |
8222 * the actual is 16-bit, it will do signed. | |
8223 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
8224 * in this way. | |
8225 */ | |
8226 target.format = AUDIO_U8S16SYS; | |
8227 #else | |
8228 target.format = AUDIO_S16SYS; | |
8229 #endif | |
8230 | |
8231 /* Set a default buffersize if needed */ | |
8232 if(0 == buffersize) | |
8233 { | |
8234 buffersize = ALMIXER_DEFAULT_BUFFERSIZE; | |
8235 } | |
8236 | |
8237 sample = Sound_NewSample(rwops, fileext, &target, buffersize); | |
8238 if(NULL == sample) | |
8239 { | |
8240 ALmixer_SetError(Sound_GetError()); | |
8241 return NULL; | |
8242 } | |
8243 | |
1 | 8244 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8245 } |
8246 | |
8247 | |
8248 | |
8249 /* This will load a sample for us from | |
8250 * a file (instead of RWops). Most of the uglyness is | |
8251 * error checking and the fact that streamed/predecoded files | |
8252 * must be treated differently. | |
8253 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8254 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 | 8255 { |
8256 Sound_Sample* sample = NULL; | |
8257 Sound_AudioInfo target; | |
8258 | |
8259 /* Initialize target values to defaults | |
8260 * 0 tells SDL_sound to use the "actual" values | |
8261 */ | |
8262 target.channels = 0; | |
8263 target.rate = 0; | |
8264 | |
8265 #if 0 | |
8266 /* This requires my new additions to SDL_sound. It will | |
8267 * convert the sample to the proper endian order. | |
8268 * If the actual is 8-bit, it will do unsigned, if | |
8269 * the actual is 16-bit, it will do signed. | |
8270 * I'm told by Ryan Gordon that OpenAL prefers the signedness | |
8271 * in this way. | |
8272 */ | |
8273 target.format = AUDIO_U8S16SYS; | |
8274 #else | |
8275 target.format = AUDIO_S16SYS; | |
8276 #endif | |
8277 | |
8278 #if 0 | |
8279 /* Okay, here's a messy hack. The problem is that we need | |
8280 * to convert the sample to have the correct bitdepth, | |
8281 * endian order, and signedness values. | |
8282 * The bit depth is 8 or 16. | |
8283 * The endian order is the native order of the system. | |
8284 * The signedness depends on what the original value | |
8285 * of the sample. Unfortunately, we can't specify these | |
8286 * values until we after we already know what the original | |
8287 * values were for bitdepth and signedness. | |
8288 * So we must open the file once to get the values, | |
8289 * then close it, and then reopen it with the | |
8290 * correct desired target values. | |
8291 * I tried changing the sample->desired field after | |
8292 * the NewSample call, but it had no effect, so | |
8293 * it looks like it must be set on open. | |
8294 */ | |
8295 /* Pick a small buffersize for the first open to not | |
8296 * waste much time allocating memory */ | |
8297 sample = Sound_NewSampleFromFile(filename, NULL, 512); | |
8298 if(NULL == sample) | |
8299 { | |
8300 ALmixer_SetError(Sound_GetError()); | |
8301 return NULL; | |
8302 } | |
8303 | |
8304 bit_depth = GetBitDepth(sample->actual.format); | |
8305 signedness_value = GetSignednessValue(sample->actual.format); | |
8306 if(8 == bit_depth) | |
8307 { | |
8308 /* If 8 bit, then we don't have to worry about | |
8309 * endian issues. We can just use the actual format | |
8310 * value and it should do the right thing | |
8311 */ | |
8312 target.format = sample->actual.format; | |
8313 } | |
8314 else | |
8315 { | |
8316 /* We'll assume it's 16-bit, and if it's not | |
8317 * hopefully SDL_sound will return an error, | |
8318 * or let us convert to 16-bit | |
8319 */ | |
8320 /* Now we need to get the correct signedness */ | |
8321 if(ALMIXER_UNSIGNED_VALUE == signedness_value) | |
8322 { | |
8323 /* Set to Unsigned 16-bit, system endian order */ | |
8324 target.format = AUDIO_U16SYS; | |
8325 } | |
8326 else | |
8327 { | |
8328 /* Again, we'll assume it's Signed 16-bit system order | |
8329 * or force the conversion and hope it works out | |
8330 */ | |
8331 target.format = AUDIO_S16SYS; | |
8332 } | |
8333 } | |
8334 | |
8335 /* Now we have the correct info. We need to close and reopen */ | |
8336 Sound_FreeSample(sample); | |
8337 #endif | |
8338 | |
8339 sample = Sound_NewSampleFromFile(filename, &target, buffersize); | |
8340 if(NULL == sample) | |
8341 { | |
8342 ALmixer_SetError(Sound_GetError()); | |
8343 return NULL; | |
8344 } | |
8345 | |
6
4b1048af7e55
Disabled some of the debugging printfs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
3
diff
changeset
|
8346 /* |
0 | 8347 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
|
8348 */ |
1 | 8349 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8350 } |
8351 | |
8352 | |
8353 /* This is a back door for RAW samples or if you need the | |
8354 * AudioInfo field. Use at your own risk. | |
8355 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8356 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 | 8357 { |
8358 Sound_Sample* sample = NULL; | |
1 | 8359 Sound_AudioInfo sound_desired; |
8360 /* Rather than copying the data from struct to struct, I could just | |
8361 * cast the thing since the structs are meant to be identical. | |
8362 * But if SDL_sound changes it's implementation, bad things | |
8363 * will probably happen. (Or if I change my implementation and | |
8364 * forget about the cast, same bad scenario.) Since this is a load | |
8365 * function, performance of this is negligible. | |
8366 */ | |
8367 if(NULL == desired) | |
8368 { | |
8369 sample = Sound_NewSample(rwops, fileext, NULL, buffersize); | |
8370 } | |
8371 else | |
8372 { | |
8373 sound_desired.format = desired->format; | |
8374 sound_desired.channels = desired->channels; | |
8375 sound_desired.rate = desired->rate; | |
8376 sample = Sound_NewSample(rwops, fileext, &sound_desired, buffersize); | |
8377 } | |
0 | 8378 if(NULL == sample) |
8379 { | |
8380 ALmixer_SetError(Sound_GetError()); | |
8381 return NULL; | |
8382 } | |
1 | 8383 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8384 } |
8385 | |
8386 | |
8387 | |
8388 | |
8389 /* This is a back door for RAW samples or if you need the | |
8390 * AudioInfo field. Use at your own risk. | |
8391 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8392 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 | 8393 { |
8394 Sound_Sample* sample = NULL; | |
1 | 8395 Sound_AudioInfo sound_desired; |
8396 /* Rather than copying the data from struct to struct, I could just | |
8397 * cast the thing since the structs are meant to be identical. | |
8398 * But if SDL_sound changes it's implementation, bad things | |
8399 * will probably happen. (Or if I change my implementation and | |
8400 * forget about the cast, same bad scenario.) Since this is a load | |
8401 * function, performance of this is negligible. | |
8402 */ | |
8403 if(NULL == desired) | |
8404 { | |
8405 sample = Sound_NewSampleFromFile(filename, NULL, buffersize); | |
8406 } | |
8407 else | |
8408 { | |
8409 sound_desired.format = desired->format; | |
8410 sound_desired.channels = desired->channels; | |
8411 sound_desired.rate = desired->rate; | |
8412 sample = Sound_NewSampleFromFile(filename, &sound_desired, buffersize); | |
8413 } | |
8414 | |
0 | 8415 if(NULL == sample) |
8416 { | |
8417 ALmixer_SetError(Sound_GetError()); | |
8418 return NULL; | |
8419 } | |
1 | 8420 return( DoLoad(sample, buffersize, decode_mode_is_predecoded, max_queue_buffers, num_startup_buffers, access_data)); |
0 | 8421 } |
8422 | |
8423 | |
8424 | |
8425 | |
8426 void ALmixer_FreeData(ALmixer_Data* data) | |
8427 { | |
8428 ALenum error; | |
8429 if(NULL == data) | |
8430 { | |
8431 return; | |
8432 } | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8433 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8434 /* Bypass if in interruption event */ |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8435 if(NULL == alcGetCurrentContext()) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8436 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8437 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
|
8438 return; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8439 } |
0 | 8440 |
8441 if(data->decoded_all) | |
8442 { | |
8443 /* If access_data was enabled, then the Sound_Sample* | |
8444 * still exists. We need to free it | |
8445 */ | |
8446 if(data->sample != NULL) | |
8447 { | |
8448 Sound_FreeSample(data->sample); | |
8449 } | |
8450 alDeleteBuffers(1, data->buffer); | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8451 if((error = alGetError()) != AL_NO_ERROR) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8452 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8453 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
|
8454 } |
0 | 8455 } |
8456 else | |
8457 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8458 ALuint i; |
0 | 8459 |
8460 /* Delete buffer copies if access_data was enabled */ | |
8461 if(data->buffer_map_list != NULL) | |
8462 { | |
8463 for(i=0; i<data->max_queue_buffers; i++) | |
8464 { | |
8465 free(data->buffer_map_list[i].data); | |
8466 } | |
8467 free(data->buffer_map_list); | |
8468 } | |
8469 if(data->circular_buffer_queue != NULL) | |
8470 { | |
8471 CircularQueueUnsignedInt_FreeQueue(data->circular_buffer_queue); | |
8472 } | |
8473 | |
8474 Sound_FreeSample(data->sample); | |
8475 alDeleteBuffers(data->max_queue_buffers, data->buffer); | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8476 if((error = alGetError()) != AL_NO_ERROR) |
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: alDeleteBuffers failed. %s\n", alGetString(error)); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8479 } |
0 | 8480 } |
8481 free(data->buffer); | |
13
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8482 |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8483 LinkedList_Remove(s_listOfALmixerData, |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8484 LinkedList_Find(s_listOfALmixerData, data, NULL) |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8485 ); |
54aa96ae8912
Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
12
diff
changeset
|
8486 |
0 | 8487 free(data); |
8488 } | |
8489 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8490 ALint ALmixer_GetTotalTime(ALmixer_Data* data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8491 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8492 if(NULL == data) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8493 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8494 return -1; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8495 } |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8496 |
0 | 8497 return data->total_time; |
8498 } | |
8499 | |
8500 /* This function will look up the source for the corresponding channel */ | |
8501 /* 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
|
8502 ALuint ALmixer_GetSource(ALint channel) |
0 | 8503 { |
8504 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8505 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8506 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8507 #endif |
0 | 8508 retval = Internal_GetSource(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8509 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8510 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8511 #endif |
0 | 8512 return retval; |
8513 } | |
8514 | |
8515 /* 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
|
8516 ALint ALmixer_GetChannel(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8517 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8518 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8519 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8520 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8521 #endif |
0 | 8522 retval = Internal_GetChannel(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8523 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8524 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8525 #endif |
0 | 8526 return retval; |
8527 } | |
8528 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8529 ALint ALmixer_FindFreeChannel(ALint start_channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8530 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8531 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8532 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8533 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8534 #endif |
0 | 8535 retval = Internal_FindFreeChannel(start_channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8536 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8537 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8538 #endif |
0 | 8539 return retval; |
8540 } | |
8541 | |
8542 | |
8543 | |
8544 /* API update function. | |
8545 * It should return the number of buffers that were | |
8546 * queued during the call. The value might be | |
8547 * used to guage how long you might wait to | |
8548 * call the next update loop in case you are worried | |
8549 * about preserving CPU cycles. The idea is that | |
8550 * when a buffer is queued, there was probably some | |
8551 * CPU intensive looping which took awhile. | |
8552 * 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
|
8553 * Timing the call with ALmixer_GetTicks() would produce |
0 | 8554 * more accurate information. |
8555 * Returns a negative value if there was an error, | |
8556 * the value being the number of errors. | |
8557 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8558 ALint ALmixer_Update() |
0 | 8559 { |
8560 #ifdef ENABLE_ALMIXER_THREADS | |
8561 /* The thread will handle all updates by itself. | |
8562 * Don't allow the user to explicitly call update. | |
8563 */ | |
8564 return 0; | |
8565 #else | |
8566 return( Update_ALmixer(NULL) ); | |
8567 #endif | |
8568 } | |
8569 | |
8570 | |
8571 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8572 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
|
8573 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8574 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8575 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8576 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8577 Channel_Done_Callback = playback_finished_callback; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8578 Channel_Done_Callback_Userdata = user_data; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8579 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8580 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8581 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8582 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8583 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8584 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8585 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
|
8586 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8587 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8588 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8589 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8590 Channel_Data_Callback = playback_data_callback; |
1 | 8591 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
|
8592 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8593 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8594 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8595 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8596 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8597 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8598 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8599 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8600 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8601 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
|
8602 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8603 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8604 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8605 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8606 #endif |
0 | 8607 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
|
8608 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8609 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8610 #endif |
0 | 8611 return retval; |
8612 } | |
8613 | |
8614 | |
8615 /* In case the user wants to specify a source instead of a channel, | |
8616 * they may use this function. This function will look up the | |
8617 * source-to-channel map, and convert the call into a | |
8618 * PlayChannelTimed() function call. | |
8619 * Returns the channel it's being played on. | |
8620 * Note: If you are prefer this method, then you need to be careful | |
8621 * about using PlayChannel, particularly if you request the | |
8622 * first available channels because source and channels have | |
8623 * a one-to-one mapping in this API. It is quite easy for | |
8624 * a channel/source to already be in use because of this. | |
8625 * In this event, an error message will be returned to you. | |
8626 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8627 ALuint ALmixer_PlaySourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALint ticks) |
0 | 8628 { |
8629 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8630 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8631 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8632 #endif |
0 | 8633 retval = Internal_PlaySourceTimed(source, data, loops, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8634 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8635 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8636 #endif |
0 | 8637 return retval; |
8638 } | |
8639 | |
8640 | |
8641 /* Will return the number of channels halted | |
8642 * or 0 for error | |
8643 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8644 ALint ALmixer_HaltChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8645 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8646 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8647 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8648 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8649 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8650 retval = Internal_HaltChannel(channel, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8651 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8652 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8653 #endif |
0 | 8654 return retval; |
8655 } | |
8656 | |
8657 /* Will return the number of channels halted | |
8658 * or 0 for error | |
8659 */ | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8660 ALint ALmixer_HaltSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8661 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8662 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8663 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8664 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8665 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8666 retval = Internal_HaltSource(source, AL_FALSE); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8667 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8668 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8669 #endif |
0 | 8670 return retval; |
8671 } | |
8672 | |
8673 | |
8674 /* This will rewind the SDL_Sound sample for streamed | |
8675 * samples and start buffering up the data for the next | |
8676 * playback. This may require samples to be halted | |
8677 */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8678 ALboolean ALmixer_RewindData(ALmixer_Data* data) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8679 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8680 ALboolean retval; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8681 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8682 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8683 #endif |
0 | 8684 retval = Internal_RewindData(data); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8685 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8686 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8687 #endif |
0 | 8688 return retval; |
8689 } | |
8690 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8691 ALint ALmixer_RewindChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8692 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8693 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8694 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8695 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8696 #endif |
0 | 8697 retval = Internal_RewindChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8698 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8699 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8700 #endif |
0 | 8701 return retval; |
8702 } | |
8703 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8704 ALint ALmixer_RewindSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8705 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8706 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8707 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8708 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8709 #endif |
0 | 8710 retval = Internal_RewindSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8711 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8712 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8713 #endif |
0 | 8714 return retval; |
8715 } | |
8716 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8717 ALint ALmixer_PauseChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8718 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8719 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8720 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8721 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8722 #endif |
0 | 8723 retval = Internal_PauseChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8724 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8725 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8726 #endif |
0 | 8727 return retval; |
8728 } | |
8729 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8730 ALint ALmixer_PauseSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8731 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8732 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8733 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8734 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8735 #endif |
0 | 8736 retval = Internal_PauseSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8737 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8738 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8739 #endif |
0 | 8740 return retval; |
8741 } | |
8742 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8743 ALint ALmixer_ResumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8744 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8745 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8746 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8747 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8748 #endif |
0 | 8749 retval = Internal_ResumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8750 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8751 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8752 #endif |
0 | 8753 return retval; |
8754 } | |
8755 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8756 ALint ALmixer_ResumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8757 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8758 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8759 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8760 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8761 #endif |
0 | 8762 retval = Internal_ResumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8763 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8764 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8765 #endif |
0 | 8766 return retval; |
8767 } | |
8768 | |
8769 /* Might consider setting eof to 0 as a "feature" | |
8770 * This will allow seek to end to stay there because | |
8771 * Play automatically rewinds if at the end */ | |
12
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8772 ALboolean ALmixer_SeekData(ALmixer_Data* data, ALuint msec) |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8773 { |
bfe90b4f3d87
Bug fixes to FadeIn.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
10
diff
changeset
|
8774 ALboolean retval; |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8775 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8776 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8777 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8778 retval = Internal_SeekData(data, msec); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8779 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8780 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8781 #endif |
0 | 8782 return retval; |
8783 } | |
8784 | |
22
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8785 ALint ALmixer_SeekChannel(ALint channel, ALuint msec) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8786 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8787 ALint retval; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8788 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8789 SDL_LockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8790 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8791 retval = Internal_SeekChannel(channel, msec); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8792 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8793 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8794 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8795 return retval; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8796 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8797 |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8798 ALint ALmixer_SeekSource(ALuint source, ALuint msec) |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8799 { |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8800 ALint retval; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8801 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8802 SDL_LockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8803 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8804 retval = Internal_SeekSource(source, msec); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8805 #ifdef ENABLE_ALMIXER_THREADS |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8806 SDL_UnlockMutex(s_simpleLock); |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8807 #endif |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8808 return retval; |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8809 } |
58f03008ea05
- Added Seek APIs
Eric Wing <ewing . public |-at-| gmail . com>
parents:
16
diff
changeset
|
8810 |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8811 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
|
8812 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8813 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8814 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8815 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8816 #endif |
0 | 8817 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
|
8818 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8819 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8820 #endif |
0 | 8821 return retval; |
8822 } | |
8823 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8824 ALuint ALmixer_FadeInSourceTimed(ALuint source, ALmixer_Data* data, ALint loops, ALuint fade_ticks, ALint expire_ticks) |
0 | 8825 { |
8826 ALuint retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8827 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8828 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8829 #endif |
0 | 8830 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
|
8831 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8832 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8833 #endif |
0 | 8834 return retval; |
8835 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8836 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8837 ALint ALmixer_FadeOutChannel(ALint channel, ALuint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8838 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8839 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8840 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8841 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8842 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8843 retval = Internal_FadeOutChannel(channel, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8844 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8845 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8846 #endif |
0 | 8847 return retval; |
8848 } | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8849 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8850 ALint ALmixer_FadeOutSource(ALuint source, ALuint ticks) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8851 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8852 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8853 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8854 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8855 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8856 retval = Internal_FadeOutSource(source, ticks); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8857 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8858 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8859 #endif |
0 | 8860 return retval; |
8861 } | |
8862 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8863 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
|
8864 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8865 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8866 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8867 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8868 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8869 retval = Internal_FadeChannel(channel, ticks, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8870 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8871 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8872 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8873 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8874 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8875 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8876 ALint ALmixer_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
|
8877 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8878 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8879 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8880 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8881 #endif |
0 | 8882 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
|
8883 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8884 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8885 #endif |
0 | 8886 return retval; |
8887 } | |
8888 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8889 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8890 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
|
8891 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8892 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8893 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8894 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8895 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8896 retval = Internal_SetVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8897 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8898 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8899 #endif |
0 | 8900 return retval; |
8901 } | |
8902 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8903 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
|
8904 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8905 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8906 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8907 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8908 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8909 retval = Internal_SetVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8910 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8911 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8912 #endif |
0 | 8913 return retval; |
8914 } | |
8915 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8916 ALfloat ALmixer_GetVolumeChannel(ALint channel) |
0 | 8917 { |
8918 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8919 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8920 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8921 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8922 retval = Internal_GetVolumeChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8923 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8924 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8925 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8926 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8927 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8928 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8929 ALfloat ALmixer_GetVolumeSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8930 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8931 ALfloat retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8932 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8933 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8934 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8935 retval = Internal_GetVolumeSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8936 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8937 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8938 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8939 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8940 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8941 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8942 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
|
8943 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8944 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8945 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8946 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8947 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8948 retval = Internal_SetMaxVolumeChannel(channel, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8949 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8950 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8951 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8952 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8953 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8954 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8955 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
|
8956 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8957 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8958 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8959 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8960 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8961 retval = Internal_SetMaxVolumeSource(source, volume); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8962 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8963 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8964 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8965 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8966 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8967 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8968 ALfloat ALmixer_GetMaxVolumeChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8969 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8970 ALfloat retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8971 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8972 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8973 #endif |
0 | 8974 retval = Internal_GetMaxVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8975 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8976 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8977 #endif |
0 | 8978 return retval; |
8979 } | |
8980 | |
8981 ALfloat ALmixer_GetMaxVolumeSource(ALuint source) | |
8982 { | |
8983 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8984 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8985 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8986 #endif |
0 | 8987 retval = Internal_GetMaxVolumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8988 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8989 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8990 #endif |
0 | 8991 return retval; |
8992 } | |
8993 | |
8994 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8995 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
|
8996 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8997 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8998 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
8999 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9000 #endif |
0 | 9001 retval = Internal_SetMinVolumeChannel(channel, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9002 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9003 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9004 #endif |
0 | 9005 return retval; |
9006 } | |
9007 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9008 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
|
9009 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9010 ALboolean retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9011 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9012 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9013 #endif |
0 | 9014 retval = Internal_SetMinVolumeSource(source, volume); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9015 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9016 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9017 #endif |
0 | 9018 return retval; |
9019 } | |
9020 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9021 ALfloat ALmixer_GetMinVolumeChannel(ALint channel) |
0 | 9022 { |
9023 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9024 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9025 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9026 #endif |
0 | 9027 retval = Internal_GetMinVolumeChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9028 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9029 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9030 #endif |
0 | 9031 return retval; |
9032 } | |
9033 | |
9034 ALfloat ALmixer_GetMinVolumeSource(ALuint source) | |
9035 { | |
9036 ALfloat retval; | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9037 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9038 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9039 #endif |
0 | 9040 retval = Internal_GetMinVolumeSource(source); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9041 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9042 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9043 #endif |
0 | 9044 return retval; |
9045 } | |
9046 | |
9047 | |
9048 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9049 ALboolean ALmixer_SetMasterVolume(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_SetMasterVolume(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 | |
9062 ALfloat ALmixer_GetMasterVolume() | |
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_GetMasterVolume(); |
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 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9075 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
|
9076 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9077 ALint retval; |
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_ExpireChannel(channel, ticks); |
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 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9088 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
|
9089 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9090 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9091 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9092 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9093 #endif |
0 | 9094 retval = Internal_ExpireSource(source, ticks); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9095 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9096 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9097 #endif |
0 | 9098 return retval; |
9099 } | |
9100 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9101 ALint ALmixer_IsActiveChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9102 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9103 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9104 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9105 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9106 #endif |
0 | 9107 retval = Internal_QueryChannel(channel); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9108 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9109 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9110 #endif |
0 | 9111 return retval; |
9112 } | |
9113 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9114 ALint ALmixer_IsActiveSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9115 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9116 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9117 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9118 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9119 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9120 retval = Internal_QuerySource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9121 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9122 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9123 #endif |
0 | 9124 return retval; |
9125 } | |
9126 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9127 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9128 ALint ALmixer_IsPlayingChannel(ALint channel) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9129 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9130 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9131 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9132 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9133 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9134 retval = Internal_PlayingChannel(channel); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9135 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9136 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9137 #endif |
0 | 9138 return retval; |
9139 } | |
9140 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9141 ALint ALmixer_IsPlayingSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9142 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9143 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9144 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9145 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9146 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9147 retval = Internal_PlayingSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9148 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9149 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9150 #endif |
0 | 9151 return retval; |
9152 } | |
9153 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9154 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9155 ALint ALmixer_IsPausedChannel(ALint channel) |
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_PausedChannel(channel); |
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 ALint ALmixer_IsPausedSource(ALuint source) |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9169 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9170 ALint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9171 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9172 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9173 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9174 retval = Internal_PausedSource(source); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9175 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9176 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9177 #endif |
0 | 9178 return retval; |
9179 } | |
9180 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9181 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9182 ALuint ALmixer_CountAllFreeChannels() |
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 ALuint 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_CountAllFreeChannels(); |
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 ALuint ALmixer_CountUnreservedFreeChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9196 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9197 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9198 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9199 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9200 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9201 retval = Internal_CountUnreservedFreeChannels(); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9202 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9203 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9204 #endif |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9205 return retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9206 } |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9207 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9208 ALuint ALmixer_CountAllUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9209 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9210 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9211 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9212 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9213 #endif |
0 | 9214 retval = Internal_CountAllUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9215 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9216 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9217 #endif |
0 | 9218 return retval; |
9219 } | |
9220 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9221 ALuint ALmixer_CountUnreservedUsedChannels() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9222 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9223 ALuint retval; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9224 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9225 SDL_LockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9226 #endif |
0 | 9227 retval = Internal_CountUnreservedUsedChannels(); |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9228 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9229 SDL_UnlockMutex(s_simpleLock); |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9230 #endif |
0 | 9231 return retval; |
9232 } | |
9233 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9234 ALboolean ALmixer_IsPredecoded(ALmixer_Data* data) |
1 | 9235 { |
9236 if(NULL == data) | |
9237 { | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9238 return AL_FALSE; |
1 | 9239 } |
9240 return data->decoded_all; | |
9241 } | |
9242 | |
2
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9243 ALboolean ALmixer_CompiledWithThreadBackend() |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9244 { |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9245 #ifdef ENABLE_ALMIXER_THREADS |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9246 return AL_TRUE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9247 #else |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9248 return AL_FALSE; |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9249 #endif |
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 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9252 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9253 |
279d0427ef26
Overhaul prep for first public release.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
1
diff
changeset
|
9254 |