0
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2 /* Here's an OpenAL implementation modeled after
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3 * the SDL_SoundMixer which was built ontop of SDL_Mixer
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4 * and SDL_Sound.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5 * Eric Wing
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
8 #include "SDL_ALmixer.h"
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
9
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
10 #include "SDL.h" /* For SDL_GetTicks(), SDL_Delay */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
11 #include "al.h" /* OpenAL */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
12 #include "alc.h" /* For creating OpenAL contexts */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
13
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
14 /* For malloc, bsearch, qsort */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
15 #include <stdlib.h>
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
16
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
17 /* For memcpy */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
18 #include <string.h>
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
19
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
20 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
21 /* for toupper */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
22 #include <ctype.h>
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
23 /* for strrchr */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
24 #include <string.h>
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
25 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
26
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
27 /* Currently used in the output debug functions */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
28 #include <stdio.h>
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
29
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
30 /* My own CircularQueue implementation needed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
31 * to work around the Nvidia problem of the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
32 * lack of a buffer query.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
33 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
34 #include "CircularQueue.h"
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
35
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
36 /* Needed for the Mutex locks (and threads if enabled) */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
37 #include "SDL_thread.h"
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
38
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
39 /* Because of the API differences between the Loki
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
40 * and Creative distributions, we need to know which
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
41 * version to use. The LOKI distribution currently
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
42 * has AL_BYTE_LOKI defined in altypes.h which
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
43 * I will use as a flag to identify the distributions.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
44 * If this is ever removed, I might revert back to the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
45 * if defined(_WIN32) or defined(__APPLE__) test to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
46 * identify the Creative dist.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
47 * I'm not sure if or how the Nvidia distribution differs
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
48 * from the Creative distribution. So for
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
49 * now, the Nvidia distribution gets lumped with the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
50 * Creative dist and I hope nothing will break.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
51 * My aluGetErrorString may be the most vulnerable.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
52 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
53 #ifdef AL_BYTE_LOKI
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
54 #define USING_LOKI_AL_DIST
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
55 /* This is a short term fix to get around the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
56 * queuing problem with non-power of two buffer sizes.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
57 * Hopefully the maintainers will fix this before
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
58 * we're ready to ship.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
59 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
60 #define ENABLE_LOKI_QUEUE_FIX_HACK
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
61
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
62 /* The AL_GAIN in the Loki dist doesn't seem to do
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
63 * what I want/expect it to do. I want to use it for
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
64 * Fading, but it seems to work like an off/on switch.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
65 * 0 = off, >0 = on.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
66 * The AL_GAIN_LINEAR_LOKI switch seems to do what
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
67 * I want, so I'll redefine it here so the code is consistent
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
68 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
69 /* Update: I've changed the source volume implementations
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
70 * to use AL_MAX_GAIN, so I don't think I need this block
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
71 * of code anymore. The listener uses AL_GAIN, but I
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
72 * hope they got this one right since there isn't a AL_MAX_GAIN
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
73 * for the listener.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
74 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
75 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
76 #undef AL_GAIN
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
77 #include "alexttypes.h"
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
78 #define AL_GAIN AL_GAIN_LINEAR_LOKI
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
79 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
80 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
81 /* Might need to run other tests to figure out the DIST */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
82 /* I've been told that Nvidia doesn't define constants
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
83 * in the headers like Creative. Instead of
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
84 * #define AL_REFERENCE_DISTANCE 0x1020,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
85 * Nvidia prefers you query OpenAL for a value.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
86 * int AL_REFERENCE_DISTANCE = alGetEnumValue(ALubyte*)"AL_REFERNECE_DISTANCE");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
87 * So I'm assuming this means the Nvidia lacks this value.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
88 * If this is the case,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
89 * I guess we can use it to identify the Nvidia dist
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
90 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
91 #ifdef AL_REFERENCE_DISTANCE
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
92 #define USING_CREATIVE_AL_DIST
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
93 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
94 #define USING_NVIDIA_AL_DIST
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
95 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
96 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
97
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
98 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
99 /* Need memset to zero out data */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
100 #include <string.h>
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
101 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
102
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
103
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
104 /* Seek issues for predecoded samples:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
105 * The problem is that OpenAL makes us copy an
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
106 * entire buffer if we want to use it. This
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
107 * means we potentially have two copies of the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
108 * same data. For predecoded data, this can be a
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
109 * large amount of memory. However, for seek
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
110 * support, I need to be able to get access to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
111 * the original data so I can set byte positions.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
112 * The following flags let you disable seek support
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
113 * if you don't want the memory hit, keep everything,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
114 * or let you try to minimize the memory wasted by
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
115 * fetching it from the OpenAL buffer if needed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
116 * and making a copy of it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
117 * Update: I don't think I need this flag anymore. I've made the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
118 * effects of this user customizable by the access_data flag on load.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
119 * If set to true, then seek and data callbacks work, with the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
120 * cost of more memory and possibly CPU for copying the data through
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
121 * the callbacks. If false, then the extra memory is freed, but
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
122 * you don't get the features.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
123 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
124 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
125 #define DISABLE_PREDECODED_SEEK
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
126 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
127 /* Problem: Even though alGetBufferi(., AL_DATA, .)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
128 * is in the Creative Programmer's reference,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
129 * it actually isn't in the dist. (Invalid enum
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
130 * in Creative, can't compile in Loki.)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
131 * So we have to keep it disabled
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
132 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
133 #define DISABLE_SEEK_MEMORY_OPTIMIZATION
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
134
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
135 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
136 /* Needed for memcpy */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
137 #include <string.h>
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
138 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
139
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
140 /* Old way of doing things:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
141 #if defined(_WIN32) || defined(__APPLE__)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
142 #define USING_CREATIVE_AL_DIST
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
143 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
144 #define USING_LOKI_AL_DIST
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
145 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
146 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
147
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
148 /************ REMOVE ME (Don't need anymore) ********/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
149 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
150 /* Let's get fancy and see if triple buffering
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
151 * does anything good for us
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
152 * Must be 2 or more or things will probably break
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
153 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
154 #define NUMBER_OF_QUEUE_BUFFERS 5
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
155 /* This is the number of buffers that are queued up
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
156 * when play first starts up. This should be at least 1
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
157 * and no more than NUMBER_OF_QUEUE_BUFFERS
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
158 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
159 #define NUMBER_OF_START_UP_BUFFERS 2
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
160 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
161 /************ END REMOVE ME (Don't need anymore) ********/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
162
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
163 static Uint8 ALmixer_Initialized = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
164 /* This should be set correctly by Init */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
165 static Uint32 ALmixer_Frequency_global = ALMIXER_DEFAULT_FREQUENCY;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
166
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
167 /* Will be initialized in Init */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
168 static Sint32 Number_of_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
169 static Sint32 Number_of_Reserve_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
170 static Uint32 Is_Playing_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
171
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
172 /* This is for a simple lock system. It is not meant to be good,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
173 * but just sufficient to minimize/avoid threading issues
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
174 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
175 static SDL_mutex* simple_lock;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
176
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
177 #ifdef ENABLE_ALMIXER_THREADS
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
178 static SDL_Thread* Stream_Thread_global = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
179 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
180
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
181
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
182 /* If ENABLE_PARANOID_SIGNEDNESS_CHECK is used,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
183 * these values will be reset on Init()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
184 * Consider these values Read-Only.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
185 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
186
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
187 #define ALMIXER_SIGNED_VALUE 127
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
188 #define ALMIXER_UNSIGNED_VALUE 255
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
189
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
190 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
191 static Uint16 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
192 static Uint16 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
193 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
194 static const Uint16 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
195 static const Uint16 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
196 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
197
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
198 static struct ALmixer_Channel
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
199 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
200 Uint8 channel_in_use;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
201 Uint8 callback_update; /* For streaming determination */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
202 Uint8 needs_stream; /* For streaming determination */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
203 Uint8 halted;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
204 Uint8 paused;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
205 ALuint alsource;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
206 ALmixer_Data* almixer_data;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
207 Sint32 loops;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
208 Sint32 expire_ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
209 Uint32 start_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
210
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
211 Uint8 fade_enabled;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
212 Uint32 fade_expire_ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
213 Uint32 fade_start_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
214 ALfloat fade_inv_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
215 ALfloat fade_start_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
216 ALfloat fade_end_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
217 ALfloat max_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
218 ALfloat min_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
219
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
220 /* Do we need other flags?
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
221 Uint8 *samples;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
222 int volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
223 int looping;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
224 int tag;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
225 Uint32 expire;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
226 Uint32 start_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
227 Mix_Fading fading;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
228 int fade_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
229 Uint32 fade_length;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
230 Uint32 ticks_fade;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
231 effect_info *effects;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
232 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
233 } *ALmixer_Channel_List = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
234
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
235 /* This will be used to find a channel if the user supplies a source */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
236 typedef struct Source_Map
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
237 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
238 ALuint source;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
239 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
240 } Source_Map;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
241 /* Keep an array of all sources with their associated channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
242 static Source_Map* Source_Map_List;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
243
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
244 static int Compare_Source_Map(const void* a, const void* b)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
245 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
246 return ( ((Source_Map*)a)->source - ((Source_Map*)b)->source );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
247 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
248
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
249 /* Sort by channel instead of source */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
250 static int Compare_Source_Map_by_channel(const void* a, const void* b)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
251 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
252 return ( ((Source_Map*)a)->channel - ((Source_Map*)b)->channel );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
253 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
254
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
255 /* Compare by albuffer */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
256 static int Compare_Buffer_Map(const void* a, const void* b)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
257 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
258 return ( ((Buffer_Map*)a)->albuffer - ((Buffer_Map*)b)->albuffer );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
259 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
260
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
261 /* This is for the user defined callback via
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
262 * ALmixer_ChannelFinished()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
263 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
264 static void (*Channel_Done_Callback)(Sint32 channel, void* userdata) = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
265 static void* Channel_Done_Callback_Userdata = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
266 static void (*Channel_Data_Callback)(Sint32 which_channel, Uint8* data, Uint32 num_bytes, Uint32 frequency, Uint8 channels, Uint8 bitdepth, Uint16 format, Uint8 decode_mode) = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
267
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
268
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
269 /* I thought OpenAL seemed to lack an error number to string converter...
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
270 * but I was wrong. Apparently they call it alGetString() which
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
271 * breaks from the OpenGL gluGetErrorString() convention.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
272 * (And since the documentation for OpenAL is so bad, I didn't see
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
273 * it until I had already written my own aluGetErrorString().)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
274 * So for convenience, I will just call alGetString from here.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
275 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
276 static const ALubyte* aluGetErrorString(ALenum error)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
277 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
278 return alGetString(error);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
279
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
280 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
281 switch(error)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
282 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
283 case AL_NO_ERROR:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
284 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
285 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
286 case AL_INVALID_NAME:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
287 return "Invalid name (ID)";
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
288 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
289 case AL_INVALID_VALUE:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
290 return "Invalid value";
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
291 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
292 case AL_OUT_OF_MEMORY:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
293 return "Out of memory";
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
294 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
295 /* Damn, even the error values are skewed between distributions */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
296 /* For the Creative Labs distributions (don't know about Nvidia) */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
297 /* For the Loki based distributions */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
298 #ifdef USING_LOKI_AL_DIST
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
299 case AL_ILLEGAL_ENUM:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
300 return "Invalid enum value";
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
301 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
302 case AL_ILLEGAL_COMMAND:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
303 return "Requested operation is not valid";
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
304 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
305 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
306 #elif USING_CREATIVE_AL_DIST
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
307 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
308 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
309 case AL_INVALID_ENUM:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
310 return "Invalid enum value";
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
311 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
312 case AL_INVALID_OPERATION:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
313 return "Requested operation is not valid";
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
314 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
315 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
316 #elif USING_NVIDIA_AL_DIST
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
317 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
318 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
319 case alGetEnumValue((ALubyte*)"??????");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
320 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
321 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
322 default:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
323 return "Unknown error value passed to aluGetErrorString()";
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
324 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
325 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
326
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
327 /* Make compiler happy */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
328 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
329 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
330 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
331
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
332
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
333 static void PrintQueueStatus(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
334 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
335 ALint buffers_queued = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
336 ALint buffers_processed = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
337 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
338
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
339 /* Get the number of buffers still queued */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
340 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
341 source,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
342 AL_BUFFERS_QUEUED,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
343 &buffers_queued
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
344 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
345
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
346 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
347 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
348 fprintf(stderr, "Error in PrintQueueStatus, Can't get buffers_queued: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
349 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
350 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
351 /* Get the number of buffers processed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
352 * so we know if we need to refill
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
353 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
354 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
355 source,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
356 AL_BUFFERS_PROCESSED,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
357 &buffers_processed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
358 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
359 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
360 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
361 fprintf(stderr, "Error in PrintQueueStatus, Can't get buffers_processed: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
362 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
363 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
364
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
365 fprintf(stderr, "For source: %d, buffers_queued=%d, buffers_processed=%d\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
366 source,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
367 buffers_queued,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
368 buffers_processed);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
369 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
370
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
371
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
372
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
373 static void Init_Channel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
374 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
375
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
376 fprintf(stderr, "Init channel %d\n", channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
377 ALmixer_Channel_List[channel].channel_in_use = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
378 ALmixer_Channel_List[channel].callback_update = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
379 ALmixer_Channel_List[channel].needs_stream = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
380 ALmixer_Channel_List[channel].paused = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
381 ALmixer_Channel_List[channel].halted = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
382 ALmixer_Channel_List[channel].loops = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
383
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
384 ALmixer_Channel_List[channel].expire_ticks = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
385 ALmixer_Channel_List[channel].start_time = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
386
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
387 ALmixer_Channel_List[channel].fade_enabled = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
388 ALmixer_Channel_List[channel].fade_expire_ticks = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
389 ALmixer_Channel_List[channel].fade_start_time = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
390 ALmixer_Channel_List[channel].fade_inv_time = 0.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
391 ALmixer_Channel_List[channel].fade_start_volume = 0.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
392 ALmixer_Channel_List[channel].fade_end_volume = 0.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
393 ALmixer_Channel_List[channel].max_volume = 1.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
394 ALmixer_Channel_List[channel].min_volume = 0.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
395
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
396 ALmixer_Channel_List[channel].almixer_data = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
397 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
398 /* Quick helper function to clean up a channel
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
399 * after it's done playing */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
400 static void Clean_Channel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
401 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
402 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
403 ALmixer_Channel_List[channel].channel_in_use = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
404 ALmixer_Channel_List[channel].callback_update = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
405 ALmixer_Channel_List[channel].needs_stream = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
406 ALmixer_Channel_List[channel].paused = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
407 ALmixer_Channel_List[channel].halted = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
408 ALmixer_Channel_List[channel].loops = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
409
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
410
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
411 ALmixer_Channel_List[channel].expire_ticks = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
412 ALmixer_Channel_List[channel].start_time = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
413
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
414 ALmixer_Channel_List[channel].fade_enabled = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
415 ALmixer_Channel_List[channel].fade_expire_ticks = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
416 ALmixer_Channel_List[channel].fade_start_time = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
417 ALmixer_Channel_List[channel].fade_inv_time = 0.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
418 ALmixer_Channel_List[channel].fade_start_volume = 0.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
419 ALmixer_Channel_List[channel].fade_end_volume = 0.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
420
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
421 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MAX_GAIN,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
422 ALmixer_Channel_List[channel].max_volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
423
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
424 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
425 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
426 fprintf(stderr, "10Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
427 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
428 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
429
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
430 alSourcef(ALmixer_Channel_List[channel].alsource, AL_MIN_GAIN,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
431 ALmixer_Channel_List[channel].min_volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
432 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
433 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
434 fprintf(stderr, "11Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
435 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
436 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
437
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
438 if(ALmixer_Channel_List[channel].almixer_data != NULL)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
439 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
440 if(ALmixer_Channel_List[channel].almixer_data->in_use > 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
441 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
442 ALmixer_Channel_List[channel].almixer_data->in_use--;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
443 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
444 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
445 /* Needed to determine if rewind is needed, can't reset */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
446 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
447 ALmixer_Channel_List[channel].almixer_data->eof = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
448 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
449
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
450 ALmixer_Channel_List[channel].almixer_data = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
451 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
452
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
453
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
454 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
455 /* Not needed anymore because not doing any fileext checks.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
456 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
457 * Unfortunately, strcasecmp isn't portable so here's a
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
458 * reimplementation of it (taken from SDL_sound)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
459 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
460 static int ALmixer_strcasecmp(const char* x, const char* y)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
461 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
462 int ux, uy;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
463
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
464 if (x == y) /* same pointer? Both NULL? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
465 return(0);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
466
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
467 if (x == NULL)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
468 return(-1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
469
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
470 if (y == NULL)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
471 return(1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
472
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
473 do
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
474 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
475 ux = toupper((int) *x);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
476 uy = toupper((int) *y);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
477 if (ux > uy)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
478 return(1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
479 else if (ux < uy)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
480 return(-1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
481 x++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
482 y++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
483 } while ((ux) && (uy));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
484
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
485 return(0);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
486 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
487 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
488
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
489
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
490 /* What shoud this return?
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
491 * 127 for signed, 255 for unsigned
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
492 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
493 static Uint8 GetSignednessValue(Uint16 format)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
494 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
495 switch(format)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
496 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
497 case AUDIO_U8:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
498 case AUDIO_U16LSB:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
499 case AUDIO_U16MSB:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
500 return ALMIXER_UNSIGNED_VALUE;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
501 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
502 case AUDIO_S8:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
503 case AUDIO_S16LSB:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
504 case AUDIO_S16MSB:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
505 return ALMIXER_SIGNED_VALUE;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
506 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
507 default:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
508 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
509 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
510 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
511 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
512
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
513
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
514 static Uint8 GetBitDepth(Uint16 format)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
515 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
516 Uint8 bit_depth = 16;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
517
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
518 switch(format)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
519 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
520 case AUDIO_U8:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
521 case AUDIO_S8:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
522 bit_depth = 8;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
523 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
524
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
525 case AUDIO_U16LSB:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
526 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
527 case AUDIO_U16:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
528 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
529 case AUDIO_S16LSB:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
530 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
531 case AUDIO_S16:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
532 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
533 case AUDIO_U16MSB:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
534 case AUDIO_S16MSB:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
535 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
536 case AUDIO_U16SYS:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
537 case AUDIO_S16SYS:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
538 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
539 bit_depth = 16;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
540 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
541 default:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
542 bit_depth = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
543 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
544 return bit_depth;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
545 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
546
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
547 /* Need to translate between SDL/SDL_Sound audiospec
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
548 * and OpenAL conventions */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
549 static ALenum TranslateFormat(Sound_AudioInfo* info)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
550 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
551 Uint8 bit_depth;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
552
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
553 bit_depth = GetBitDepth(info->format);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
554 if(0 == bit_depth)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
555 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
556 fprintf(stderr, "Warning: Unknown bit depth. Setting to 16\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
557 bit_depth = 16;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
558 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
559
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
560 if(2 == info->channels)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
561 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
562 if(16 == bit_depth)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
563 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
564 return AL_FORMAT_STEREO16;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
565 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
566 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
567 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
568 return AL_FORMAT_STEREO8;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
569 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
570 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
571 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
572 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
573 if(16 == bit_depth)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
574 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
575 return AL_FORMAT_MONO16;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
576 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
577 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
578 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
579 return AL_FORMAT_MONO8;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
580 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
581 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
582 /* Make compiler happy. Shouldn't get here */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
583 return AL_FORMAT_STEREO16;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
584 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
585
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
586 /**************** REMOVED ****************************/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
587 /* This was removed because I originally thought
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
588 * OpenAL could return a pointer to the buffer data,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
589 * but I was wrong. If something like that is ever
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
590 * implemented, then this might become useful.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
591 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
592 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
593 /* Reconstruct_Sound_Sample and Set_AudioInfo only
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
594 * are needed if the Seek memory optimization is
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
595 * used. Also, the Loki dist doesn't seem to support
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
596 * AL_DATA which I need for it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
597 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
598 #ifndef DISABLE_SEEK_MEMORY_OPTIMIZATION
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
599
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
600 static void Set_AudioInfo(Sound_AudioInfo* info, ALint frequency, ALint bits, ALint channels)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
601 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
602 info->rate = (Uint32)frequency;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
603 info->channels = (Uint8)channels;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
604
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
605 /* Not sure if it should be signed or unsigned. Hopefully
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
606 * that detail won't be needed.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
607 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
608 if(8 == bits)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
609 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
610 info->format = AUDIO_U8;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
611 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
612 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
613 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
614 info->format = AUDIO_U16SYS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
615 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
616 fprintf(stderr, "Audio info: freq=%d, chan=%d, format=%d\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
617 info->rate, info->channels, info->format);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
618
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
619 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
620
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
621
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
622 static Sint32 Reconstruct_Sound_Sample(ALmixer_Data* data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
623 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
624 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
625 ALint* data_from_albuffer;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
626 ALint freq;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
627 ALint bits;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
628 ALint channels;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
629 ALint size;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
630
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
631 /* Create memory all initiallized to 0. */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
632 data->sample = (Sound_Sample*)calloc(1, sizeof(Sound_Sample));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
633 if(NULL == data->sample)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
634 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
635 ALmixer_SetError("Out of memory for Sound_Sample");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
636 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
637 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
638
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
639 /* Clear errors */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
640 alGetError();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
641
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
642 alGetBufferi(data->buffer[0], AL_FREQUENCY, &freq);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
643 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
644 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
645 ALmixer_SetError("alGetBufferi(AL_FREQUENCT): %s", aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
646 free(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
647 data->sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
648 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
649 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
650
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
651 alGetBufferi(data->buffer[0], AL_BITS, &bits);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
652 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
653 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
654 ALmixer_SetError("alGetBufferi(AL_BITS): %s", aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
655 free(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
656 data->sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
657 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
658 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
659
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
660 alGetBufferi(data->buffer[0], AL_CHANNELS, &channels);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
661 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
662 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
663 ALmixer_SetError("alGetBufferi(AL_CHANNELS): %s", aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
664 free(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
665 data->sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
666 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
667 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
668
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
669 alGetBufferi(data->buffer[0], AL_SIZE, &size);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
670 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
671 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
672 ALmixer_SetError("alGetBufferi(AL_SIZE): %s", aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
673 free(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
674 data->sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
675 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
676 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
677
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
678 alGetBufferi(data->buffer[0], AL_DATA, data_from_albuffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
679 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
680 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
681 ALmixer_SetError("alGetBufferi(AL_DATA): %s", aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
682 free(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
683 data->sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
684 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
685 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
686
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
687 if(size <= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
688 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
689 ALmixer_SetError("No data in al buffer");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
690 free(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
691 data->sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
692 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
693 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
694
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
695 /* Now that we have all the attributes, we need to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
696 * allocate memory for the buffer and reconstruct
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
697 * the AudioInfo attributes.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
698 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
699 data->sample->buffer = malloc(size*sizeof(Uint8));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
700 if(NULL == data->sample->buffer)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
701 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
702 ALmixer_SetError("Out of memory for sample->buffer");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
703 free(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
704 data->sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
705 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
706 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
707
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
708 memcpy(data->sample->buffer, data_from_albuffer, size);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
709 data->sample->buffer_size = size;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
710
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
711 /* Fill up the Sound_AudioInfo structures */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
712 Set_AudioInfo(&data->sample->desired, freq, bits, channels);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
713 Set_AudioInfo(&data->sample->actual, freq, bits, channels);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
714
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
715 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
716 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
717
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
718 #endif /* End DISABLE_SEEK_MEMORY_OPTIMIZATION */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
719 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
720 /*************** END REMOVED *************************/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
721
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
722 static void Invoke_Channel_Done_Callback(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
723 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
724 if(NULL == Channel_Done_Callback)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
725 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
726 return;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
727 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
728 Channel_Done_Callback(channel, Channel_Done_Callback_Userdata);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
729 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
730
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
731 static Sint32 LookUpBuffer(ALuint buffer, Buffer_Map* buffer_map_list, Uint32 num_items_in_list)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
732 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
733 /* Only the first value is used for the key */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
734 Buffer_Map key = { 0, 0, NULL, 0 };
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
735 Buffer_Map* found_item = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
736 key.albuffer = buffer;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
737
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
738 /* Use the ANSI C binary search feature (yea!) */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
739 found_item = (Buffer_Map*)bsearch(&key, buffer_map_list, num_items_in_list, sizeof(Buffer_Map), Compare_Buffer_Map);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
740 if(NULL == found_item)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
741 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
742 ALmixer_SetError("Can't find buffer");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
743 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
744 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
745 return found_item->index;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
746 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
747
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
748
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
749 /* FIXME: Need to pass back additional info to be useful.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
750 * Bit rate, stereo/mono (num chans), time in msec?
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
751 * Precoded/streamed flag so user can plan for future data?
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
752 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
753 static void Invoke_Channel_Data_Callback(Sint32 which_channel, Uint8* data, Uint32 num_bytes, Uint32 frequency, Uint8 channels, Uint16 format, Uint8 decode_mode)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
754 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
755 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
756 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);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
757 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
758 if(NULL == Channel_Data_Callback)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
759 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
760 return;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
761 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
762 Channel_Data_Callback(which_channel, data, num_bytes, frequency, channels, GetBitDepth(format), format, decode_mode);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
763 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
764
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
765 static void Invoke_Predecoded_Channel_Data_Callback(Sint32 channel, ALmixer_Data* data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
766 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
767 if(NULL == data->sample)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
768 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
769 return;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
770 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
771 /* The buffer position is complicated because if the current data was seeked,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
772 * we must adjust the buffer to the seek position
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
773 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
774 Invoke_Channel_Data_Callback(channel,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
775 (((Uint8*) data->sample->buffer) + (data->total_bytes - data->loaded_bytes) ),
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
776 data->loaded_bytes,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
777 data->sample->desired.rate,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
778 data->sample->desired.channels,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
779 data->sample->desired.format,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
780 ALMIXER_DECODE_ALL
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
781 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
782 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
783
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
784 static void Invoke_Streamed_Channel_Data_Callback(Sint32 channel, ALmixer_Data* data, ALuint buffer)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
785 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
786 Sint32 index;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
787 if(NULL == data->buffer_map_list)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
788 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
789 return;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
790 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
791 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
792 /* This should catch the case where all buffers are unqueued
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
793 * and the "current" buffer is id: 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
794 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
795 if(-1 == index)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
796 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
797 return;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
798 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
799 Invoke_Channel_Data_Callback(channel,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
800 data->buffer_map_list[index].data,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
801 data->buffer_map_list[index].num_bytes,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
802 data->sample->desired.rate,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
803 data->sample->desired.channels,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
804 data->sample->desired.format,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
805 ALMIXER_DECODE_STREAM
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
806 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
807 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
808
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
809 /* From SDL_Sound's playsound. Converts milliseconds to byte positions.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
810 * This is needed for seeking on predecoded samples
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
811 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
812 static Uint32 Convert_Msec_To_Byte_Pos(Sound_AudioInfo *info, Uint32 ms)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
813 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
814 float frames_per_ms;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
815 Uint32 frame_offset;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
816 Uint32 frame_size;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
817 fprintf(stderr, "In convert\n" );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
818 if(info == NULL)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
819 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
820 fprintf(stderr, "Error, info is NULL\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
821 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
822 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
823 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
824 fprintf(stderr, "Not an error: info is not NULL\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
825 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
826 fprintf(stderr, "The rate=%d\n", info->rate);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
827
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
828 /* "frames" == "sample frames" */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
829 frames_per_ms = ((float) info->rate) / 1000.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
830 fprintf(stderr, "%f\n", frames_per_ms);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
831 frame_offset = (Uint32) (frames_per_ms * ((float) ms));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
832 fprintf(stderr, "%d\n", frame_offset);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
833 frame_size = (Uint32) ((info->format & 0xFF) / 8) * info->channels;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
834 fprintf(stderr, "%d\n", frame_size);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
835 return(frame_offset * frame_size);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
836 } /* cvtMsToBytePos */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
837
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
838 static Sint32 Set_Predecoded_Seek_Position(ALmixer_Data* data, Uint32 byte_position)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
839 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
840 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
841 /* clear error */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
842 alGetError();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
843
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
844 /* Is it greater than, or greater-than or equal to ?? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
845 if(byte_position > data->total_bytes)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
846 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
847 /* We can't go past the end, so set to end? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
848 fprintf(stderr, "Error, can't seek past end\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
849
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
850 /* In case the below thing doesn't work,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
851 * just rewind the whole thing.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
852 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
853 alBufferData(data->buffer[0],
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
854 TranslateFormat(&data->sample->desired),
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
855 (Uint8*) data->sample->buffer,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
856 data->total_bytes,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
857 data->sample->desired.rate
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
858 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
859 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
860
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
861 /* I was trying to set to the end, (1 byte remaining),
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
862 * but I was getting freezes. I'm thinking it might be
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
863 * another Power of 2 bug in the Loki dist. I tried 2,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
864 * and it still hung. 4 didn't hang, but I got a clip
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
865 * artifact. 8 seemed to work okay.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
866 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
867 alBufferData(data->buffer[0],
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
868 TranslateFormat(&data->sample->desired),
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
869 (((Uint8*) data->sample->buffer) + (data->total_bytes - 8) ),
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
870 8,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
871 data->sample->desired.rate
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
872 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
873 if( (error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
874 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
875 ALmixer_SetError("Can't seek past end and alBufferData failed: %s\n", aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
876 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
877 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
878 /* Need to set the loaded_bytes field because I don't trust the OpenAL
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
879 * query command to work because I don't know if it will mutilate the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
880 * size for its own purposes or return the original size
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
881 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
882 data->loaded_bytes = 8;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
883
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
884 /* Not sure if this should be an error or not */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
885 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
886 ALmixer_SetError("Can't Seek past end");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
887 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
888 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
889 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
890 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
891
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
892 alBufferData(data->buffer[0],
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
893 TranslateFormat(&data->sample->desired),
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
894 &(((Uint8*)data->sample->buffer)[byte_position]),
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
895 data->total_bytes - byte_position,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
896 data->sample->desired.rate
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
897 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
898 if( (error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
899 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
900 ALmixer_SetError("alBufferData failed: %s\n", aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
901 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
902 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
903 /* Need to set the loaded_bytes field because I don't trust the OpenAL
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
904 * query command to work because I don't know if it will mutilate the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
905 * size for its own purposes or return the original size
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
906 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
907 data->loaded_bytes = data->total_bytes - byte_position;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
908
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
909 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
910 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
911
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
912 /* This will compute the total playing time
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
913 * based upon the number of bytes and audio info.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
914 * (In prinicple, it should compute the time for any given length)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
915 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
916 static Uint32 Compute_Total_Time(Sound_AudioInfo *info, Uint32 total_bytes)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
917 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
918 Uint32 bytes_per_sec;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
919 Uint32 bytes_per_sample;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
920 double total_sec;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
921 Uint32 total_msec;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
922
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
923 if(0 == total_bytes)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
924 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
925 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
926 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
927 /* SDL has a mask trick I was not aware of. Mask the upper bits
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
928 * of the format, and you get 8 or 16 which is the bits per sample.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
929 * Divide by 8bits_per_bytes and you get bytes_per_sample
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
930 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
931 bytes_per_sample = (Uint32) ((info->format & 0xFF) / 8);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
932 /* To compute Bytes per second, do
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
933 * samples_per_sec * bytes_per_sample * number_of_channels
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
934 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
935 bytes_per_sec = info->rate * bytes_per_sample * info->channels;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
936
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
937 /* Now to get total time (sec), do
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
938 * total_bytes / bytes_per_sec
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
939 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
940 total_sec = total_bytes / (double)bytes_per_sec;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
941
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
942 /* Now convert seconds to milliseconds
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
943 * Add .5 to the float to do rounding before the final cast
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
944 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
945 total_msec = (Uint32) ( (total_sec * 1000) + 0.5 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
946
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
947 fprintf(stderr, "%d\n", total_msec);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
948 return total_msec;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
949 } /* End Compute_Total_Time */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
950
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
951
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
952
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
953
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
954 /* Because we have multiple queue buffers and OpenAL won't let
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
955 * us access them, we need to keep copies of each buffer around
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
956 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
957 static Sint32 CopyDataToAccessBuffer(ALmixer_Data* data, Uint32 num_bytes, ALuint buffer)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
958 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
959 Sint32 index;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
960 /* We only want to copy if access_data is true.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
961 * This is determined by whether memory has been
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
962 * allocated in the buffer_map_list or not
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
963 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
964 if(NULL == data->buffer_map_list)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
965 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
966 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
967 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
968 index = LookUpBuffer(buffer, data->buffer_map_list, data->max_queue_buffers);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
969 if(-1 == index)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
970 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
971 fprintf(stderr, ">>>>>>>CopyData catch, albuffer=%d\n",buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
972 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
973 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
974 /* Copy the data to the access buffer */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
975 memcpy(data->buffer_map_list[index].data, data->sample->buffer, num_bytes);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
976 data->buffer_map_list[index].num_bytes = data->sample->buffer_size;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
977
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
978 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
979 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
980
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
981
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
982 /* For streamed data, gets more data
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
983 * and prepares it in the active Mix_chunk
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
984 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
985 static Uint32 GetMoreData(ALmixer_Data* data, ALuint buffer)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
986 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
987 Uint32 bytes_decoded;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
988 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
989 if(NULL == data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
990 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
991 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
992 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
993 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
994
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
995 bytes_decoded = Sound_Decode(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
996 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
997 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
998 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
999 ALmixer_SetError(Sound_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1000 /* Force cleanup through FreeData
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1001 Sound_FreeSample(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1002 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1003 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1004 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1005
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1006
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1007 /* Don't forget to add check for EOF */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1008 /* Will return 0 bytes and pass the buck to check sample->flags */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1009 if(0 == bytes_decoded)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1010 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1011 #if 1
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1012 fprintf(stderr, "Hit eof while trying to buffer\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1013 data->eof = 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1014 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1015 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1016 fprintf(stderr, "\tEOF flag\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1017 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1018 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1019 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1020 fprintf(stderr, "\tCanSeek flag\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1021 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1022 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1023 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1024 fprintf(stderr, "\tEAGAIN flag\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1025 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1026 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1027 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1028 fprintf(stderr, "\tNONE flag\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1029 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1030 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1031 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1032 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1033
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1034 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1035 /******* REMOVE ME ********************************/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1036 /***************** ANOTHER EXPERIEMENT *******************/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1037 /* The PROBLEM: It seems that the Loki distribution has problems
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1038 * with Queuing when the buffer size is not a power of two
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1039 * and additional buffers must come after it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1040 * The behavior is inconsistent, but one of several things
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1041 * usually happens:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1042 * Playback is normal
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1043 * Playback immediately stops after the non-pow2 buffer
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1044 * Playback gets distorted on the non-pow2 buffer
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1045 * The entire program segfaults.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1046 * The workaround is to always specify a power of two buffer size
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1047 * and hope that SDL_sound always fill it. (By lucky coincidence,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1048 * I already submitted the Ogg fix.) However, this won't catch
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1049 * cases where a loop happens because the read at the end of the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1050 * file is typically less than the buffer size.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1051 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1052 * This fix addresses this issue, however it may break in
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1053 * other conditions. Always decode in buffer sizes of powers of 2.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1054 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1055 * The HACK:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1056 * If the buffer is short, try filling it up with 0's
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1057 * to meet the user requested buffer_size which
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1058 * is probably a nice number OpenAL likes, in
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1059 * hopes to avoid a possible Loki bug with
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1060 * short buffers. If looping (which is the main
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1061 * reason for this), the negative side effect is
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1062 * that it may take longer for the loop to start
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1063 * because it must play dead silence. Or if the decoder
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1064 * doesn't guarantee to return the requested bytes
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1065 * (like Ogg), then you will get breakup in between
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1066 * packets.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1067 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1068 if( (bytes_decoded) < data->sample->buffer_size)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1069 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1070 Uint8 bit_depth;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1071 Uint8 signedness_value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1072 int silence_value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1073 /* Crap, memset value needs to be the "silent" value,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1074 * but it will differ for signed/unsigned and bit depth
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1075 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1076 bit_depth = GetBitDepth(data->sample->desired.format);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1077 signedness_value = GetSignednessValue(data->sample->desired.format);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1078 if(ALMIXER_SIGNED_VALUE == signedness_value)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1079 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1080 /* I'm guessing that if it's signed, then 0 is the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1081 * "silent" value */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1082 silence_value = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1083 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1084 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1085 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1086 if(8 == bit_depth)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1087 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1088 /* If 8 bit, I'm guessing it's (2^7)-1 = 127 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1089 silence_value = 127;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1090 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1091 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1092 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1093 /* For 16 bit, I'm guessing it's (2^15)-1 = 32767 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1094 silence_value = 32767;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1095 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1096 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1097 /* Now fill up the rest of the data buffer with the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1098 * silence_value.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1099 * I don't think I have to worry about endian issues for
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1100 * this part since the data is for internal use only
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1101 * at this point.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1102 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1103 memset( &( ((Uint8*)(data->sample->buffer))[bytes_decoded] ), silence_value, data->sample->buffer_size - bytes_decoded);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1104 /* Now reset the bytes_decoded to reflect the entire
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1105 * buffer to tell alBufferData what our full size is.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1106 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1107 fprintf(stderr, "ALTERED bytes decoded for silence: Original end was %d\n", bytes_decoded);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1108 bytes_decoded = data->sample->buffer_size;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1109 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1110 /*********** END EXPERIMENT ******************************/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1111 /******* END REMOVE ME ********************************/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1112 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1113
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1114 /* Now copy the data to the OpenAL buffer */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1115 /* We can't just set a pointer because the API needs
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1116 * its own copy to assist hardware acceleration */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1117 alBufferData(buffer,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1118 TranslateFormat(&data->sample->desired),
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1119 data->sample->buffer,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1120 bytes_decoded,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1121 data->sample->desired.rate
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1122 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1123 if( (error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1124 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1125 ALmixer_SetError("alBufferData failed: %s\n", aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1126 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1127 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1128
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1129 /* If we need to, copy the data also to the access area
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1130 * (the function will do the check for us)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1131 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1132 CopyDataToAccessBuffer(data, bytes_decoded, buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1133 return bytes_decoded;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1134 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1135
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1136
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1137
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1138
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1139 /******************** EXPERIEMENT ****************************
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1140 * Test function to force maximum buffer filling during loops
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1141 * REMOVE LATER
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1142 *********************************************/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1143 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1144 static Sint32 GetMoreData2(ALmixer_Data* data, ALuint buffer)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1145 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1146 Sint32 bytes_decoded;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1147 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1148 if(NULL == data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1149 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1150 ALmixer_SetError("Cannot GetMoreData() because ALmixer_Data* is NULL\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1151 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1152 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1153
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1154 if(AL_FALSE == alIsBuffer(buffer))
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1155 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1156 fprintf(stderr, "NOT A BUFFER>>>>>>>>>>>>>>>\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1157 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1158 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1159 fprintf(stderr, "Entered GetMoreData222222: buffer id is %d\n", buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1160
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1161 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1162 fprintf(stderr, "Decode in GetMoreData\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1163 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1164
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1165 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1166 if(buffer%2 == 1)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1167 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1168 fprintf(stderr, "Setting buffer size to 16384\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1169 Sound_SetBufferSize(data->sample, 16384);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1170 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1171 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1172 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1173 fprintf(stderr, "Setting buffer size to 8192\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1174 Sound_SetBufferSize(data->sample, 8192);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1175 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1176 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1177
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1178 bytes_decoded = Sound_Decode(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1179 if(data->sample->flags & SOUND_SAMPLEFLAG_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1180 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1181 fprintf(stderr, "Sound_Decode triggered an ERROR>>>>>>\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1182 ALmixer_SetError(Sound_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1183 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1184 Sound_FreeSample(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1185 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1186 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1187 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1188 /* Don't forget to add check for EOF */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1189 /* Will return 0 bytes and pass the buck to check sample->flags */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1190 if(0 == bytes_decoded)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1191 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1192 #if 1
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1193 fprintf(stderr, "Hit eof while trying to buffer\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1194 data->eof = 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1195 if(data->sample->flags & SOUND_SAMPLEFLAG_EOF)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1196 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1197 fprintf(stderr, "\tEOF flag\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1198 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1199 if(data->sample->flags & SOUND_SAMPLEFLAG_CANSEEK)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1200 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1201 fprintf(stderr, "\tCanSeek flag\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1202 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1203 if(data->sample->flags & SOUND_SAMPLEFLAG_EAGAIN)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1204 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1205 fprintf(stderr, "\tEAGAIN flag\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1206 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1207 if(data->sample->flags & SOUND_SAMPLEFLAG_NONE)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1208 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1209 fprintf(stderr, "\tNONE flag\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1210 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1211 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1212 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1213 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1214
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1215 if(bytes_decoded < 16384)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1216 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1217 char* tempbuffer1 = (char*)malloc(16384);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1218 char* tempbuffer2 = (char*)malloc(16384);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1219 int retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1220 memcpy(tempbuffer1, data->sample->buffer, bytes_decoded);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1221 retval = Sound_SetBufferSize(data->sample, 16384-bytes_decoded);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1222 if(retval == 1)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1223 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1224 Uint32 new_bytes;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1225 Sound_Rewind(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1226 new_bytes = Sound_Decode(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1227 fprintf(stderr, "Orig bytes: %d, Make up bytes_decoded=%d, total=%d\n", bytes_decoded, new_bytes, new_bytes+bytes_decoded);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1228
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1229 memcpy(tempbuffer2, data->sample->buffer, new_bytes);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1230
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1231 retval = Sound_SetBufferSize(data->sample, 16384);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1232 fprintf(stderr, "Finished reset...now danger copy\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1233 memcpy(data->sample->buffer, tempbuffer1,bytes_decoded);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1234
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1235 fprintf(stderr, "Finished reset...now danger copy2\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1236 memcpy( &( ((char*)(data->sample->buffer))[bytes_decoded] ), tempbuffer2, new_bytes);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1237
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1238 fprintf(stderr, "Finished \n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1239
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1240 free(tempbuffer1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1241 free(tempbuffer2);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1242 bytes_decoded += new_bytes;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1243 fprintf(stderr, "ASSERT bytes should equal 16384: %d\n", bytes_decoded);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1244 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1245 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1246 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1247 fprintf(stderr, "Experiment failed: %s\n", Sound_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1248 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1249 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1250
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1251 /* Now copy the data to the OpenAL buffer */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1252 /* We can't just set a pointer because the API needs
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1253 * its own copy to assist hardware acceleration */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1254 alBufferData(buffer,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1255 TranslateFormat(&data->sample->desired),
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1256 data->sample->buffer,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1257 bytes_decoded,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1258 data->sample->desired.rate
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1259 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1260 if( (error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1261 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1262 ALmixer_SetError("alBufferData failed: %s\n", aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1263 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1264 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1265
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1266 fprintf(stderr, "GetMoreData2222 returning %d bytes decoded\n", bytes_decoded);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1267 return bytes_decoded;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1268 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1269 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1270
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1271 /************ END EXPERIEMENT - REMOVE ME *************************/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1272
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1273
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1274
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1275
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1276
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1277
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1278
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1279
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1280
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1281 /* This function will look up the source for the corresponding channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1282 /* Must return 0 on error instead of -1 because of unsigned int */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1283 static ALuint Internal_GetSource(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1284 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1285 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1286 /* Make sure channel is in bounds */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1287 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1288 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1289 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);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1290 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1291 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1292 /* If the user specified -1, then return the an available source */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1293 if(channel < 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1294 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1295 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1296 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1297 if( ! ALmixer_Channel_List[i].channel_in_use )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1298 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1299 return ALmixer_Channel_List[i].alsource;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1300 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1301 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1302 /* If we get here, all sources are in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1303 /* Error message seems too harsh
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1304 ALmixer_SetError("All sources are in use");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1305 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1306 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1307 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1308 /* Last case: Return the source for the channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1309 return ALmixer_Channel_List[channel].alsource;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1310 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1311
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1312 /* This function will look up the channel for the corresponding source */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1313 static Sint32 Internal_GetChannel(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1314 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1315 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1316 /* Only the first value is used for the key */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1317 Source_Map key = { 0, 0 };
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1318 Source_Map* found_item = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1319 key.source = source;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1320
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1321 /* If the source is 0, look up the first available channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1322 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1323 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1324 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1325 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1326 if( ! ALmixer_Channel_List[i].channel_in_use )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1327 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1328 return i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1329 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1330 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1331 /* If we get here, all sources are in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1332 /* Error message seems too harsh
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1333 ALmixer_SetError("All channels are in use");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1334 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1335 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1336 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1337
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1338
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1339 /* Else, look up the source and return the channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1340 if(AL_FALSE == alIsSource(source))
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1341 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1342 ALmixer_SetError("Is not a source");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1343 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1344 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1345
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1346 /* Use the ANSI C binary search feature (yea!) */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1347 found_item = (Source_Map*)bsearch(&key, Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1348 if(NULL == found_item)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1349 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1350 ALmixer_SetError("Source is valid but not registered with ALmixer (to a channel)");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1351 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1352 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1353 return found_item->channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1354 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1355
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1356
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1357
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1358 /* This function will find the first available channel (not in use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1359 * from the specified start channel. Reserved channels to not qualify
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1360 * as available.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1361 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1362 static Sint32 Internal_FindFreeChannel(Sint32 start_channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1363 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1364 /* Start at the number of reserved so we skip over
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1365 * all the reserved channels.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1366 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1367 Sint32 i = Number_of_Reserve_Channels_global;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1368 /* Quick check to see if we're out of bounds */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1369 if(start_channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1370 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1371 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1372 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1373
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1374 /* If the start channel is even higher than the reserved,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1375 * then start at the higher value.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1376 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1377 if(start_channel > Number_of_Reserve_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1378 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1379 i = start_channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1380 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1381
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1382 /* i has already been set */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1383 for( ; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1384 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1385 if( ! ALmixer_Channel_List[i].channel_in_use )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1386 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1387 return i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1388 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1389 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1390 /* If we get here, all sources are in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1391 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1392 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1393
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1394
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1395
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1396
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1397 /* Note: Behaves, almost like SDL_mixer, but keep in mind
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1398 * that there is no "music" channel anymore, so 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1399 * will remove everything. (Note, I no longer allow 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1400 * so it gets set to the default number.)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1401 * Also, callbacks for deleted channels will not be called.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1402 * I really need to do error checking, for realloc and
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1403 * GenSources, but reversing the damage is too painful
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1404 * for me to think about at the moment, so it's not in here.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1405 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1406 static Sint32 Internal_AllocateChannels(Sint32 numchans)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1407 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1408 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1409 int i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1410 /* Return info */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1411 if(numchans < 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1412 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1413 return Number_of_Channels_global;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1414 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1415 if(0 == numchans)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1416 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1417 numchans = ALMIXER_DEFAULT_NUM_CHANNELS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1418 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1419 /* No change */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1420 if(numchans == Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1421 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1422 return Number_of_Channels_global;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1423 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1424 /* We need to increase the number of channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1425 if(numchans > Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1426 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1427 /* Not sure how safe this is, but SDL_mixer does it
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1428 * the same way */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1429 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1430
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1431 /* Allocate memory for the list of sources that map to the channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1432 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1433
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1434 for(i=Number_of_Channels_global; i<numchans; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1435 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1436 Init_Channel(i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1437 /* Generate a new source and associate it with the channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1438 alGenSources(1, &ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1439 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1440 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1441 fprintf(stderr, "12Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1442 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1443 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1444 /* Copy the source so the SourceMap has it too */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1445 Source_Map_List[i].source = ALmixer_Channel_List[i].alsource;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1446 Source_Map_List[i].channel = i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1447 /* Clean the channel because there are some things that need to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1448 * be done that can't happen until the source is set
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1449 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1450 Clean_Channel(i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1451 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1452
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1453 /* The Source_Map_List must be sorted by source for binary searches
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1454 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1455 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1456
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1457 Number_of_Channels_global = numchans;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1458 return numchans;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1459 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1460 /* Need to remove channels. This might be dangerous */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1461 if(numchans < Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1462 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1463 for(i=numchans; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1464 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1465 /* Halt the channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1466 ALmixer_HaltChannel(i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1467
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1468 /* Delete source associated with the channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1469 alDeleteSources(1, &ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1470 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1471 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1472 fprintf(stderr, "13Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1473 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1474 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1475 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1476
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1477
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1478 /* Not sure how safe this is, but SDL_mixer does it
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1479 * the same way */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1480 ALmixer_Channel_List = (struct ALmixer_Channel*) realloc( ALmixer_Channel_List, numchans * sizeof(struct ALmixer_Channel));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1481
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1482 /* The tricky part is that we must remove the entries
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1483 * in the source map that correspond to the deleted channels.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1484 * We'll resort the map by channels so we can pick them off
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1485 * in order.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1486 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1487 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map_by_channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1488
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1489 /* Deallocate memory for the list of sources that map to the channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1490 Source_Map_List = (Source_Map*) realloc(Source_Map_List, numchans * sizeof(Source_Map));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1491
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1492 /* Now resort the map by source and the correct num of chans */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1493 qsort(Source_Map_List, numchans, sizeof(Source_Map), Compare_Source_Map);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1494
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1495 /* Reset the number of channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1496 Number_of_Channels_global = numchans;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1497 return numchans;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1498 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1499 /* Shouldn't ever reach here */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1500 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1501
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1502 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1503
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1504 static Sint32 Internal_ReserveChannels(Sint32 num)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1505 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1506 /* Can't reserve more than the max num of channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1507 /* Actually, I'll allow it for people who just want to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1508 * set the value really high to effectively disable
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1509 * auto-assignment
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1510 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1511
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1512 /* Return the current number of reserved channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1513 if(num < 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1514 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1515 return Number_of_Reserve_Channels_global;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1516 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1517 Number_of_Reserve_Channels_global = num;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1518 return Number_of_Reserve_Channels_global;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1519 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1520
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1521
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1522
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1523
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1524
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1525 static Sint32 Internal_PlayChannelTimed(Sint32 channel, ALmixer_Data* data, Sint32 loops, Sint32 ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1526 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1527 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1528 int ret_flag = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1529 if(NULL == data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1530 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1531 ALmixer_SetError("Can't play because data is NULL\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1532 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1533 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1534
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1535 /* There isn't a good way to share streamed files because
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1536 * the decoded data doesn't stick around.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1537 * You must "Load" a brand new instance of
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1538 * the data. If you try using the same data,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1539 * bad things may happen. This check will attempt
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1540 * to prevent sharing
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1541 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1542 if(0 == data->decoded_all)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1543 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1544 if(data->in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1545 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1546 ALmixer_SetError("Can't play shared streamed sample because it is already in use");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1547 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1548 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1549
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1550 /* Make sure SDL_sound sample is not at EOF.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1551 * This mainly affects streamed files,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1552 * so the check is placed here
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1553 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1554 if(data->eof)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1555 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1556 if( -1 == ALmixer_RewindData(data) )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1557 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1558 ALmixer_SetError("Can't play sample because it is at EOF and cannot rewind");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1559 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1560 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1561 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1562 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1563 /* We need to provide the user with the first available channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1564 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1565 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1566 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1567 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1568 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1569 if(0 == ALmixer_Channel_List[i].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1570 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1571 channel = i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1572 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1573 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1574 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1575 /* if we couldn't find a channel, return an error */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1576 if(i == Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1577 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1578 ALmixer_SetError("No channels available for playing");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1579 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1580 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1581 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1582 /* If we didn't assign the channel number, make sure it's not
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1583 * out of bounds or in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1584 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1585 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1586 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1587 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1588 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);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1589 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1590 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1591 else if(ALmixer_Channel_List[channel].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1592 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1593 ALmixer_SetError("Requested channel (%d) is in use", channel, Number_of_Channels_global-1, Number_of_Channels_global);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1594 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1595 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1596 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1597 /* Make sure the user doesn't enter some meaningless value */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1598 if(loops < -1)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1599 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1600 loops = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1601 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1602
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1603 /* loops will probably have to change to be controlled by SDL_Sound */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1604
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1605 /* Set up the initial values for playing */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1606 ALmixer_Channel_List[channel].channel_in_use = 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1607 data->in_use++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1608
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1609 /* Shouldn't need updating until a callback is fired
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1610 * (assuming that we call Play in this function
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1611 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1612 ALmixer_Channel_List[channel].needs_stream = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1613 ALmixer_Channel_List[channel].almixer_data = data;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1614 ALmixer_Channel_List[channel].start_time = SDL_GetTicks();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1615
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1616 /* If user entered -1 (or less), set to -1 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1617 if(ticks < 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1618 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1619 ALmixer_Channel_List[channel].expire_ticks = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1620 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1621 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1622 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1623 ALmixer_Channel_List[channel].expire_ticks = ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1624 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1625
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1626
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1627 ALmixer_Channel_List[channel].halted = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1628 ALmixer_Channel_List[channel].paused = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1629
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1630 /* Ran just use OpenAL to control loops if predecoded and infinite */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1631 ALmixer_Channel_List[channel].loops = loops;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1632 if( (-1 == loops) && (data->decoded_all) )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1633 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1634 alSourcei(ALmixer_Channel_List[channel].alsource, AL_LOOPING, AL_TRUE);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1635 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1636 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1637 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1638 alSourcei(ALmixer_Channel_List[channel].alsource, AL_LOOPING, AL_FALSE);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1639 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1640 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1641 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1642 fprintf(stderr, "13Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1643 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1644 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1645
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1646 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1647 /* Because of the corner case, predecoded
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1648 * files must add +1 to the loops.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1649 * Streams do not have this problem
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1650 * because they can use the eof flag to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1651 * avoid the conflict.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1652 * Sharing data chunks prevents the use of the eof flag.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1653 * Since streams, cannot share, only predecoded
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1654 * files are affected
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1655 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1656 if(data->decoded_all)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1657 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1658 /* Corner Case: Now that play calls are pushed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1659 * off to update(), the start call must
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1660 * also come through here. So, start loops
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1661 * must be +1
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1662 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1663 if(-1 == loops)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1664 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1665 /* -1 is a special case, and you don't want
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1666 * to add +1 to it */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1667 ALmixer_Channel_List[channel].loops = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1668 alSourcei(ALmixer_Channel_List[channel].alsource, AL_LOOPING, AL_TRUE);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1669 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1670 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1671 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1672 ALmixer_Channel_List[channel].loops = loops+1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1673 alSourcei(ALmixer_Channel_List[channel].alsource, AL_LOOPING, AL_FALSE);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1674 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1675 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1676 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1677 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1678 ALmixer_Channel_List[channel].loops = loops;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1679 /* Can we really loop on streamed data? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1680 alSourcei(ALmixer_Channel_List[channel].alsource, AL_LOOPING, AL_TRUE);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1681 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1682 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1683
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1684 /* Should I start playing here or pass the buck to update? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1685 /* Unlike SDL_SoundMixer, I think I'll do it here because
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1686 * this library isn't a *total* hack and OpenAL has more
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1687 * built in functionality I need, so less needs to be
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1688 * controlled and directed through the update function.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1689 * The downside is less functionality is centralized.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1690 * The upside is that the update function should be
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1691 * easier to maintain.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1692 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1693
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1694 /* Clear the error flag */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1695 alGetError();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1696 if(data->decoded_all)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1697 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1698 /* Bind the data to the source */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1699 alSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1700 ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1701 AL_BUFFER,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1702 data->buffer[0]);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1703 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1704 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1705 ALmixer_SetError("Could not bind data to source: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1706 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1707 Clean_Channel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1708 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1709 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1710
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1711 /* Make data available if access_data is enabled */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1712 Invoke_Predecoded_Channel_Data_Callback(channel, data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1713 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1714 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1715 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1716 /* Need to use the streaming buffer for binding */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1717
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1718 Uint32 bytes_returned;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1719 Uint32 j;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1720 data->num_buffers_in_use=0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1721 /****** MODIFICATION must go here *********/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1722 /* Since buffer queuing is pushed off until here to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1723 * avoid buffer conflicts, we must start reading
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1724 * data here. First we make sure we have at least one
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1725 * packet. Then we queue up until we hit our limit.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1726 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1727 bytes_returned = GetMoreData(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1728 data,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1729 data->buffer[0]);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1730 if(0 == bytes_returned)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1731 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1732 /* No data or error */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1733 ALmixer_SetError("Could not get data for streamed PlayChannel: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1734 Clean_Channel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1735 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1736 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1737 /* Increment the number of buffers in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1738 data->num_buffers_in_use++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1739
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1740
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1741 /* Now we need to fill up the rest of the buffers.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1742 * There is a corner case where we run out of data
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1743 * before the last buffer is filled.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1744 * Stop conditions are we run out of
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1745 * data or we max out our preload buffers.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1746 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1747
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1748 fprintf(stderr, "Filling buffer #%d (AL id is %d)\n", 0, data->buffer[0]);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1749 for(j=1; j<data->num_startup_buffers; j++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1750 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1751 fprintf(stderr, "Filling buffer #%d (AL id is %d)\n", j, data->buffer[j]);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1752 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1753 fprintf(stderr, ">>>>>>>>>>>>>>>>>>HACK for GetMoreData2\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1754 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1755 bytes_returned = GetMoreData(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1756 data,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1757 data->buffer[j]);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1758 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1759 * This might be a problem. I made a mistake with the types. I accidentally
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1760 * made the bytes returned an Sint32 and returned -1 on error.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1761 * Bytes returned should be a Uint32, so now I no longer have a -1 case
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1762 * to check. I hope I didn't break anything here
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1763 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1764 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1765 if(bytes_returned < 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1766 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1767 /* Error found */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1768 ALmixer_SetError("Could not get data for additional startup buffers for PlayChannel: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1769 /* We'll continue on because we do have some valid data */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1770 ret_flag = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1771 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1772 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1773 else if(0 == bytes_returned)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1774 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1775 if(0 == bytes_returned)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1776 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1777 /* No more data to buffer */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1778 /* Check for loops */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1779 if( ALmixer_Channel_List[channel].loops != 0 )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1780 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1781 fprintf(stderr, "Need to rewind. In RAMPUP, handling loop\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1782 if(0 == Sound_Rewind(data->sample))
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1783 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1784 fprintf(stderr, "error in rewind\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1785 ALmixer_SetError( Sound_GetError() );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1786 ALmixer_Channel_List[channel].loops = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1787 ret_flag = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1788 /* We'll continue on because we do have some valid data */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1789 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1790 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1791 /* Remember to reset the data->eof flag */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1792 data->eof = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1793 if(ALmixer_Channel_List[channel].loops > 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1794 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1795 ALmixer_Channel_List[channel].loops--;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1796 fprintf(stderr, "Inside 000 >>>>>>>>>>Loops=%d\n", ALmixer_Channel_List[channel].loops);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1797 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1798 /* Would like to redo the loop, but due to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1799 * Sound_Rewind() bugs, we would risk falling
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1800 * into an infinite loop
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1801 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1802 bytes_returned = GetMoreData(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1803 data,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1804 data->buffer[j]);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1805 if(bytes_returned <= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1806 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1807 ALmixer_SetError("Could not get data: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1808 /* We'll continue on because we do have some valid data */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1809 ret_flag = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1810 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1811 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1812 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1813 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1814 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1815 /* No loops to do so quit here */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1816 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1817 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1818 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1819 /* Increment the number of buffers in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1820 data->num_buffers_in_use++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1821 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1822 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1823 fprintf(stderr, "In PlayChannel, about to queue: source=%d, num_buffers_in_use=%d\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1824 ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1825 data->num_buffers_in_use);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1826 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1827
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1828 alSourceQueueBuffers(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1829 ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1830 data->num_buffers_in_use,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1831 data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1832 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1833 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1834 ALmixer_SetError("Could not bind data to source: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1835 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1836 Clean_Channel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1837 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1838 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1839 /* This is part of the hideous Nvidia workaround. In order to figure out
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1840 * which buffer to show during callbacks (for things like
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1841 * o-scopes), I must keep a copy of the buffers that are queued in my own
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1842 * data structure. This code will be called only if
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1843 * "access_data" was set, indicated by whether the queue is NULL.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1844 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1845 if(data->circular_buffer_queue != NULL)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1846 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1847 Uint32 k;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1848 Uint32 queue_ret_flag;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1849 for(k=0; k<data->num_buffers_in_use; k++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1850 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1851 queue_ret_flag = CircularQueueUnsignedInt_PushBack(data->circular_buffer_queue, data->buffer[k]);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1852 if(0 == queue_ret_flag)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1853 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1854 fprintf(stderr, "Serious internal error: CircularQueue could not push into queue.\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1855 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1856 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1857 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1858 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1859 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1860 fprintf(stderr, "Queue in PlayTimed\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1861 CircularQueueUnsignedInt_Print(data->circular_buffer_queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1862 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1863 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1864 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1865 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1866
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1867
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1868 /****** END **********/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1869 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1870 /* We have finished loading the data (predecoded or queued)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1871 * so now we can play
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1872 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1873 alSourcePlay(ALmixer_Channel_List[channel].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1874 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1875 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1876 ALmixer_SetError("Play failed: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1877 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1878 Clean_Channel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1879 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1880 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1881
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1882 /* Add to the counter that something is playing */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1883 Is_Playing_global++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1884 if(-1 == ret_flag)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1885 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1886 fprintf(stderr, "BACKDOOR ERROR >>>>>>>>>>>>>>>>>>\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1887 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1888 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1889 return channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1890 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1891
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1892
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1893 /* In case the user wants to specify a source instead of a channel,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1894 * they may use this function. This function will look up the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1895 * source-to-channel map, and convert the call into a
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1896 * PlayChannelTimed() function call.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1897 * Returns the channel it's being played on.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1898 * Note: If you are prefer this method, then you need to be careful
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1899 * about using PlayChannel, particularly if you request the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1900 * first available channels because source and channels have
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1901 * a one-to-one mapping in this API. It is quite easy for
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1902 * a channel/source to already be in use because of this.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1903 * In this event, an error message will be returned to you.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1904 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1905 static ALuint Internal_PlaySourceTimed(ALuint source, ALmixer_Data* data, Sint32 loops, Sint32 ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1906 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1907 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1908 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1909 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1910 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1911 retval = Internal_PlayChannelTimed(-1, data, loops, ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1912 if(-1 == retval)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1913 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1914 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1915 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1916 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1917 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1918 return Internal_GetSource(retval);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1919 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1920 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1921
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1922 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1923 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1924 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1925 ALmixer_SetError("Cannot Play source: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1926 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1927 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1928 retval = Internal_PlayChannelTimed(channel, data, loops, ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1929 if(-1 == retval)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1930 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1931 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1932 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1933 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1934 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1935 return source;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1936 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1937 /* make compiler happy */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1938 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1939 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1940
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1941
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1942
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1943 /* Will return the number of channels halted
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1944 * or 0 for error
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1945 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1946 static Sint32 Internal_HaltChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1947 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1948 Sint32 retval = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1949 Sint32 counter = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1950 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1951 ALint buffers_still_queued;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1952 ALint buffers_processed;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1953
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1954 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1955 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1956 ALmixer_SetError("Cannot halt channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1957 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1958 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1959 /* If the user specified a specific channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1960 if(channel >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1961 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1962 fprintf(stderr, "Halt on channel %d\n", channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1963 /* only need to process channel if in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1964 if(ALmixer_Channel_List[channel].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1965 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1966 alSourceStop(ALmixer_Channel_List[channel].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1967 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1968 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1969 fprintf(stderr, "14Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1970 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1971 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1972 /* Here's the situation. My old method of using
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1973 * alSourceUnqueueBuffers() seemed to be invalid in light
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1974 * of all the problems I suffered through with getting
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1975 * the CoreData backend to work with this code.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1976 * As such, I'm changing all the code to set the buffer to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1977 * AL_NONE. Furthermore, the queued vs. non-queued issue
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1978 * doesn't need to apply here. For non-queued, Loki,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1979 * Creative Windows, and CoreAudio seem to leave the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1980 * buffer queued (Old Mac didn't.) For queued, we need to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1981 * remove the processed buffers and force remove the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1982 * still-queued buffers.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1983 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1984 fprintf(stderr, "Halt on channel %d, channel in use\n", channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1985 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1986 ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1987 AL_BUFFERS_QUEUED, &buffers_still_queued
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1988 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1989 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1990 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1991 fprintf(stderr, "17Testing Error with buffers_still_queued: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1992 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1993 ALmixer_SetError("Failed detecting still queued buffers: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1994 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1995 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1996 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1997 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1998 ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
1999 AL_BUFFERS_PROCESSED, &buffers_processed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2000 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2001 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2002 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2003 fprintf(stderr, "17Testing Error with buffers_processed: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2004 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2005 ALmixer_SetError("Failed detecting still processed buffers: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2006 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2007 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2008 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2009 /* If either of these is greater than 0, it means we need
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2010 * to clear the source
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2011 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2012 if((buffers_still_queued > 0) || (buffers_processed > 0))
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2013 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2014 alSourcei(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2015 AL_BUFFER,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2016 AL_NONE);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2017 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2018 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2019 fprintf(stderr, "17Testing Error with clearing buffer from source: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2020 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2021 ALmixer_SetError("Failed to clear buffer from source: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2022 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2023 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2024 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2025 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2026
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2027 ALmixer_Channel_List[channel].almixer_data->num_buffers_in_use = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2028
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2029 Clean_Channel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2030 Is_Playing_global--;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2031 /* Launch callback for consistency? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2032 Invoke_Channel_Done_Callback(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2033 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2034 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2035 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2036 /* The user wants to halt all channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2037 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2038 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2039 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2040 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2041 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2042 fprintf(stderr, "Halting channel %d\n", i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2043 fprintf(stderr, "in use %d\n", ALmixer_Channel_List[i].channel_in_use );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2044 /* only need to process channel if in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2045 if(ALmixer_Channel_List[i].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2046 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2047 fprintf(stderr, "SourceStop %d\n", i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2048 alSourceStop(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2049 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2050 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2051 fprintf(stderr, "19Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2052 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2053 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2054
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2055 /* Here's the situation. My old method of using
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2056 * alSourceUnqueueBuffers() seemed to be invalid in light
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2057 * of all the problems I suffered through with getting
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2058 * the CoreData backend to work with this code.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2059 * As such, I'm changing all the code to set the buffer to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2060 * AL_NONE. Furthermore, the queued vs. non-queued issue
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2061 * doesn't need to apply here. For non-queued, Loki,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2062 * Creative Windows, and CoreAudio seem to leave the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2063 * buffer queued (Old Mac didn't.) For queued, we need to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2064 * remove the processed buffers and force remove the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2065 * still-queued buffers.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2066 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2067 fprintf(stderr, "Halt on channel %d, channel in use\n", channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2068 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2069 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2070 AL_BUFFERS_QUEUED, &buffers_still_queued
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2071 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2072 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2073 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2074 fprintf(stderr, "17Testing Error with buffers_still_queued: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2075 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2076 ALmixer_SetError("Failed detecting still queued buffers: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2077 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2078 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2079 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2080 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2081 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2082 AL_BUFFERS_PROCESSED, &buffers_processed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2083 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2084 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2085 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2086 fprintf(stderr, "17Testing Error with buffers_processed: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2087 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2088 ALmixer_SetError("Failed detecting still processed buffers: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2089 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2090 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2091 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2092 /* If either of these is greater than 0, it means we need
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2093 * to clear the source
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2094 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2095 if((buffers_still_queued > 0) || (buffers_processed > 0))
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2096 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2097 alSourcei(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2098 AL_BUFFER,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2099 AL_NONE);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2100 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2101 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2102 fprintf(stderr, "17Testing Error with clearing buffer from source: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2103 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2104 ALmixer_SetError("Failed to clear buffer from source: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2105 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2106 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2107 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2108 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2109
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2110 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2111
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2112 fprintf(stderr, "Clean channel %d\n", i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2113 Clean_Channel(i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2114 Is_Playing_global--;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2115 /* Launch callback for consistency? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2116 fprintf(stderr, "Callback%d\n", i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2117 Invoke_Channel_Done_Callback(i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2118
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2119 /* Increment the counter */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2120 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2121 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2122 /* Let's halt everything just in case there
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2123 * are bugs.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2124 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2125 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2126 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2127 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2128 alSourceStop(ALmixer_Channel_List[channel].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2129 / * Can't clean because the in_use counter for
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2130 * data will get messed up * /
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2131 Clean_Channel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2132 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2133 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2134 /* Just in case */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2135 Is_Playing_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2136 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2137 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2138 if(-1 == retval)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2139 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2140 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2141 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2142 return counter;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2143 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2144
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2145
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2146 /* Will return the source halted or the total number of channels
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2147 * if all were halted or 0 for error
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2148 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2149 static Sint32 Internal_HaltSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2150 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2151 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2152 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2153 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2154 /* Will return the number of sources halted */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2155 return Internal_HaltChannel(-1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2156 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2157
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2158 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2159 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2160 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2161 ALmixer_SetError("Cannot halt source: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2162 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2163 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2164 return Internal_HaltChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2165 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2166
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2167
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2168 /* This will rewind the SDL_Sound sample for streamed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2169 * samples and start buffering up the data for the next
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2170 * playback. This may require samples to be halted
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2171 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2172 static Sint32 Internal_RewindData(ALmixer_Data* data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2173 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2174 Sint32 retval = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2175 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2176 Sint32 bytes_returned;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2177 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2178 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2179 if(NULL == data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2180 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2181 ALmixer_SetError("Cannot rewind because data is NULL\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2182 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2183 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2184
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2185
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2186 /* Might have to require Halt */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2187 /* Okay, we assume Halt or natural stop has already
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2188 * cleared the data buffers
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2189 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2190 if(data->in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2191 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2192 fprintf(stderr, "Warning sample is in use. May not be able to rewind\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2193 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2194 ALmixer_SetError("Data is in use. Cannot rewind unless all sources using the data are halted\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2195 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2196 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2197 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2198
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2199
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2200 /* Because Seek can alter things even in predecoded data,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2201 * decoded data must also be rewound
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2202 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2203 if(data->decoded_all)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2204 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2205 data->eof = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2206
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2207 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2208 #if defined(DISABLE_PREDECODED_SEEK)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2209 /* Since we can't seek predecoded stuff, it should be rewound */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2210 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2211 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2212 /* This case is if the Sound_Sample has been deleted.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2213 * It assumes the data is already at the beginning.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2214 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2215 if(NULL == data->sample)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2216 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2217 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2218 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2219 /* Else, the sample has already been reallocated,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2220 * and we can fall to normal behavior
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2221 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2222 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2223 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2224 /* If access_data, was enabled, the sound sample
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2225 * still exists and we can do stuff.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2226 * If it's NULL, we can't do anything, but
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2227 * it should already be "rewound".
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2228 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2229 if(NULL == data->sample)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2230 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2231 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2232 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2233 /* Else, the sample has already been reallocated,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2234 * and we can fall to normal behavior
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2235 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2236
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2237 Set_Predecoded_Seek_Position(data, 0);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2238 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2239 return data->total_bytes;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2240 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2241 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2242 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2243
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2244 /* Remaining stuff for streamed data */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2245
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2246 fprintf(stderr, "Rewinding for stream\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2247 data->eof = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2248 retval = Sound_Rewind(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2249 if(0 == retval)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2250 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2251 ALmixer_SetError( Sound_GetError() );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2252 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2253 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2254 fprintf(stderr, "Rewinding succeeded\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2255 fprintf(stderr, "calling GetMoreData for Rewinding for stream\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2256 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2257 /* Clear error */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2258 alGetError();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2259 for(i=0; i<data->num_buffers; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2260 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2261 bytes_returned = GetMoreData(data, data->buffer[i]);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2262 if(-1 == bytes_returned)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2263 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2264 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2265 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2266 else if(0 == bytes_returned)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2267 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2268 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2269 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2270 retval += bytes_returned;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2271
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2272 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2273 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2274
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2275
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2276 fprintf(stderr, "end Rewinding for stream\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2277
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2278 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2279 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2280
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2281
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2282
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2283
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2284 static Sint32 Internal_RewindChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2285 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2286 Sint32 retval = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2287 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2288 ALint state;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2289
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2290 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2291 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2292 ALmixer_SetError("Cannot rewind channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2293 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2294 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2295
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2296 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2297 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2298 fprintf(stderr, "24Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2299 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2300 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2301 /* Clear error */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2302 alGetError();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2303
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2304 /* If the user specified a specific channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2305 if(channel >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2306 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2307 /* only need to process channel if in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2308 if(ALmixer_Channel_List[channel].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2309 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2310
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2311 /* What should I do? Do I just rewind the channel
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2312 * or also rewind the data? Since the data is
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2313 * shared, let's make it the user's responsibility
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2314 * to rewind the data.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2315 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2316 if(ALmixer_Channel_List[channel].almixer_data->decoded_all)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2317 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2318 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2319 ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2320 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2321 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2322 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2323 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2324 fprintf(stderr, "25Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2325 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2326 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2327 alSourceRewind(ALmixer_Channel_List[channel].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2328 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2329 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2330 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2331 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2332 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2333 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2334 /* Need to resume playback if it was originally playing */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2335 if(AL_PLAYING == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2336 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2337 alSourcePlay(ALmixer_Channel_List[channel].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2338 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2339 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2340 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2341 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2342 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2343 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2344 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2345 else if(AL_PAUSED == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2346 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2347 /* HACK: The problem is that when paused, after
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2348 * the Rewind, I can't get it off the INITIAL
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2349 * state without restarting
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2350 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2351 alSourcePlay(ALmixer_Channel_List[channel].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2352 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2353 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2354 fprintf(stderr, "25Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2355 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2356 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2357 alSourcePause(ALmixer_Channel_List[channel].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2358 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2359 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2360 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2361 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2362 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2363 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2364 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2365 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2366 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2367 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2368 /* Streamed data is different. Rewinding the channel
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2369 * does no good. Rewinding the data will have an
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2370 * effect, but it will be lagged based on how
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2371 * much data is queued. Recommend users call Halt
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2372 * before rewind if they want immediate results.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2373 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2374 retval = Internal_RewindData(ALmixer_Channel_List[channel].almixer_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2375 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2376 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2377 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2378 /* The user wants to halt all channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2379 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2380 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2381 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2382 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2383 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2384 fprintf(stderr, "in use %d\n", ALmixer_Channel_List[i].channel_in_use );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2385 /* only need to process channel if in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2386 if(ALmixer_Channel_List[i].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2387 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2388 /* What should I do? Do I just rewind the channel
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2389 * or also rewind the data? Since the data is
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2390 * shared, let's make it the user's responsibility
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2391 * to rewind the data.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2392 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2393 if(ALmixer_Channel_List[i].almixer_data->decoded_all)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2394 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2395 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2396 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2397 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2398 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2399 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2400 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2401 fprintf(stderr, "26Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2402 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2403 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2404 alSourceRewind(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2405 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2406 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2407 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2408 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2409 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2410 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2411 /* Need to resume playback if it was originally playing */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2412 if(AL_PLAYING == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2413 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2414 alSourcePlay(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2415 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2416 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2417 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2418 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2419 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2420 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2421 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2422 else if(AL_PAUSED == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2423 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2424 /* HACK: The problem is that when paused, after
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2425 * the Rewind, I can't get it off the INITIAL
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2426 * state without restarting
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2427 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2428 alSourcePlay(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2429 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2430 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2431 fprintf(stderr, "27Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2432 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2433 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2434 alSourcePause(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2435 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2436 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2437 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2438 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2439 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2440 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2441 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2442 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2443 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2444 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2445 /* Streamed data is different. Rewinding the channel
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2446 * does no good. Rewinding the data will have an
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2447 * effect, but it will be lagged based on how
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2448 * much data is queued. Recommend users call Halt
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2449 * before rewind if they want immediate results.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2450 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2451 retval = Internal_RewindData(ALmixer_Channel_List[i].almixer_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2452 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2453 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2454 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2455 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2456 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2457 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2458
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2459
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2460 static Sint32 Internal_RewindSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2461 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2462 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2463 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2464 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2465 return Internal_RewindChannel(-1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2466 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2467
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2468 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2469 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2470 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2471 ALmixer_SetError("Cannot rewind source: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2472 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2473 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2474 return Internal_RewindChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2475 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2476
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2477
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2478
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2479 /* Returns the channel or number of channels actually paused */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2480
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2481 static Sint32 Internal_PauseChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2482 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2483 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2484 ALint state;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2485 Sint32 retval = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2486 Sint32 counter = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2487
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2488 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2489 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2490 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2491 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2492 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2493
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2494 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2495 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2496 fprintf(stderr, "28Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2497 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2498 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2499 /* Clear error */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2500 alGetError();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2501
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2502 /* If the user specified a specific channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2503 if(channel >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2504 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2505 fprintf(stderr, "Pause on channel %d\n", channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2506 /* only need to process channel if in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2507 if(ALmixer_Channel_List[channel].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2508 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2509 /* We don't want to repause if already
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2510 * paused because the fadeout/expire
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2511 * timing will get messed up
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2512 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2513 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2514 ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2515 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2516 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2517 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2518 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2519 fprintf(stderr, "29Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2520 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2521 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2522 if(AL_PLAYING == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2523 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2524 /* Count the actual number of channels being paused */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2525 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2526
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2527 alSourcePause(ALmixer_Channel_List[channel].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2528 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2529 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2530 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2531 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2532 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2533 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2534 /* We need to pause the expire time count down */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2535 if(ALmixer_Channel_List[channel].expire_ticks != -1)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2536 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2537 Uint32 current_time = SDL_GetTicks();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2538 Uint32 diff_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2539 diff_time = current_time -
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2540 ALmixer_Channel_List[channel].start_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2541 /* When we unpause, we will want to reset
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2542 * the start time so we can continue
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2543 * to base calculations off GetTicks().
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2544 * This means we need to subtract the amount
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2545 * of time already used up from expire_ticks.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2546 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2547 ALmixer_Channel_List[channel].expire_ticks =
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2548 ALmixer_Channel_List[channel].expire_ticks -
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2549 diff_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2550 /* Because -1 is a special value, we can't
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2551 * allow the time to go negative
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2552 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2553 if(ALmixer_Channel_List[channel].expire_ticks < 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2554 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2555 ALmixer_Channel_List[channel].expire_ticks = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2556 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2557 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2558 /* Do the same as expire time for fading */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2559 if(ALmixer_Channel_List[channel].fade_enabled)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2560 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2561 Uint32 current_time = SDL_GetTicks();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2562 Uint32 diff_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2563 diff_time = current_time -
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2564 ALmixer_Channel_List[channel].fade_start_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2565 /* When we unpause, we will want to reset
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2566 * the start time so we can continue
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2567 * to base calculations off GetTicks().
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2568 * This means we need to subtract the amount
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2569 * of time already used up from expire_ticks.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2570 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2571 ALmixer_Channel_List[channel].fade_expire_ticks =
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2572 ALmixer_Channel_List[channel].fade_expire_ticks -
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2573 diff_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2574 /* Don't allow the time to go negative */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2575 if(ALmixer_Channel_List[channel].expire_ticks < 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2576 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2577 ALmixer_Channel_List[channel].expire_ticks = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2578 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2579 } /* End fade check */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2580 } /* End if PLAYING */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2581 } /* End If in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2582 } /* End specific channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2583 /* The user wants to halt all channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2584 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2585 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2586 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2587 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2588 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2589 fprintf(stderr, "Pausing channel %d\n", i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2590 fprintf(stderr, "in use %d\n", ALmixer_Channel_List[i].channel_in_use );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2591 /* only need to process channel if in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2592 if(ALmixer_Channel_List[i].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2593 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2594 /* We don't want to repause if already
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2595 * paused because the fadeout/expire
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2596 * timing will get messed up
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2597 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2598 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2599 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2600 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2601 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2602 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2603 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2604 fprintf(stderr, "30Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2605 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2606 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2607 if(AL_PLAYING == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2608 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2609 /* Count the actual number of channels being paused */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2610 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2611
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2612 fprintf(stderr, "SourcePause %d\n", i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2613 alSourcePause(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2614 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2615 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2616 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2617 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2618 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2619 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2620 /* We need to pause the expire time count down */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2621 if(ALmixer_Channel_List[i].expire_ticks != -1)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2622 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2623 Uint32 current_time = SDL_GetTicks();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2624 Uint32 diff_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2625 diff_time = current_time -
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2626 ALmixer_Channel_List[i].start_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2627 /* When we unpause, we will want to reset
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2628 * the start time so we can continue
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2629 * to base calculations off GetTicks().
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2630 * This means we need to subtract the amount
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2631 * of time already used up from expire_ticks.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2632 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2633 ALmixer_Channel_List[i].expire_ticks =
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2634 ALmixer_Channel_List[i].expire_ticks -
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2635 diff_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2636 /* Because -1 is a special value, we can't
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2637 * allow the time to go negative
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2638 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2639 if(ALmixer_Channel_List[i].expire_ticks < 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2640 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2641 ALmixer_Channel_List[i].expire_ticks = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2642 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2643 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2644 /* Do the same as expire time for fading */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2645 if(ALmixer_Channel_List[i].fade_enabled)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2646 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2647 Uint32 current_time = SDL_GetTicks();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2648 Uint32 diff_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2649 diff_time = current_time -
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2650 ALmixer_Channel_List[i].fade_start_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2651 /* When we unpause, we will want to reset
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2652 * the start time so we can continue
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2653 * to base calculations off GetTicks().
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2654 * This means we need to subtract the amount
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2655 * of time already used up from expire_ticks.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2656 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2657 ALmixer_Channel_List[i].fade_expire_ticks =
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2658 ALmixer_Channel_List[i].fade_expire_ticks -
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2659 diff_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2660 /* Don't allow the time to go negative */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2661 if(ALmixer_Channel_List[i].expire_ticks < 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2662 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2663 ALmixer_Channel_List[i].expire_ticks = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2664 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2665 } /* End fade check */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2666 } /* End if PLAYING */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2667 } /* End channel in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2668 } /* End for-loop */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2669 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2670 if(-1 == retval)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2671 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2672 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2673 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2674 return counter;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2675 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2676
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2677 /* Returns the channel or number of channels actually paused */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2678 static Sint32 Internal_PauseSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2679 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2680 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2681 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2682 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2683 return Internal_PauseChannel(-1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2684 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2685
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2686 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2687 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2688 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2689 ALmixer_SetError("Cannot pause source: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2690 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2691 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2692 return Internal_PauseChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2693 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2694
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2695
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2696
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2697 static Sint32 Internal_ResumeChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2698 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2699 ALint state;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2700 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2701 Sint32 retval = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2702 Sint32 counter = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2703
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2704 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2705 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2706 ALmixer_SetError("Cannot pause channel %d because it exceeds maximum number of channels (%d)\n", channel, Number_of_Channels_global);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2707 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2708 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2709
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2710 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2711 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2712 fprintf(stderr, "31Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2713 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2714 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2715 /* Clear error */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2716 alGetError();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2717
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2718 /* If the user specified a specific channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2719 if(channel >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2720 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2721 fprintf(stderr, "Pause on channel %d\n", channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2722 /* only need to process channel if in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2723 if(ALmixer_Channel_List[channel].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2724 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2725 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2726 ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2727 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2728 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2729 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2730 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2731 fprintf(stderr, "32Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2732 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2733 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2734 if(AL_PAUSED == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2735 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2736 /* Count the actual number of channels resumed */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2737 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2738
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2739 /* We need to resume the expire time count down */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2740 if(ALmixer_Channel_List[channel].expire_ticks != -1)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2741 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2742 ALmixer_Channel_List[channel].start_time = SDL_GetTicks();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2743 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2744 /* Do the same as expire time for fading */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2745 if(ALmixer_Channel_List[channel].fade_enabled)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2746 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2747 ALmixer_Channel_List[channel].fade_start_time = SDL_GetTicks();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2748 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2749
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2750 alSourcePlay(ALmixer_Channel_List[channel].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2751 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2752 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2753 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2754 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2755 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2756 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2757 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2758 fprintf(stderr, "Pause on channel %d, channel in use\n", channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2759 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2760 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2761 /* The user wants to halt all channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2762 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2763 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2764 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2765 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2766 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2767 fprintf(stderr, "Pausing channel %d\n", i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2768 fprintf(stderr, "in use %d\n", ALmixer_Channel_List[i].channel_in_use );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2769 /* only need to process channel if in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2770 if(ALmixer_Channel_List[i].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2771 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2772 fprintf(stderr, "SourcePause %d\n", i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2773 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2774 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2775 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2776 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2777 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2778 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2779 fprintf(stderr, "33Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2780 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2781 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2782 if(AL_PAUSED == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2783 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2784 /* Count the actual number of channels resumed */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2785 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2786
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2787 /* We need to resume the expire time count down */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2788 if(ALmixer_Channel_List[i].expire_ticks != -1)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2789 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2790 ALmixer_Channel_List[i].start_time = SDL_GetTicks();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2791 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2792 /* Do the same as expire time for fading */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2793 if(ALmixer_Channel_List[i].fade_enabled)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2794 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2795 ALmixer_Channel_List[i].fade_start_time = SDL_GetTicks();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2796 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2797
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2798 alSourcePlay(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2799 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2800 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2801 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2802 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2803 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2804 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2805 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2806 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2807 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2808 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2809 if(-1 == retval)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2810 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2811 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2812 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2813 return counter;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2814 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2815
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2816
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2817 static Sint32 Internal_ResumeSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2818 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2819 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2820 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2821 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2822 return Internal_ResumeChannel(-1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2823 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2824
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2825 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2826 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2827 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2828 ALmixer_SetError("Cannot resume source: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2829 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2830 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2831 return Internal_ResumeChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2832 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2833
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2834
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2835 /* Might consider setting eof to 0 as a "feature"
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2836 * This will allow seek to end to stay there because
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2837 * Play automatically rewinds if at the end */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2838 static Sint32 Internal_Seek(ALmixer_Data* data, Uint32 msec)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2839 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2840 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2841
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2842 if(NULL == data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2843 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2844 ALmixer_SetError("Cannot Seek because data is NULL");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2845 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2846 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2847
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2848 /* Seek for predecoded files involves moving the chunk pointer around */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2849 if(data->decoded_all)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2850 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2851 Uint32 byte_position;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2852
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2853 /* OpenAL doesn't seem to like it if I change the buffer
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2854 * while playing (crashes), so I must require that Seek only
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2855 * be done when the data is not in use.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2856 * Since data may be shared among multiple sources,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2857 * I can't shut them down myself, so I have to return an error.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2858 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2859 if(data->in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2860 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2861 ALmixer_SetError("Cannot seek on predecoded data while instances are playing");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2862 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2863 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2864 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2865 #if defined(DISABLE_PREDECODED_SEEK)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2866 ALmixer_SetError("Seek support for predecoded samples was not compiled in");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2867 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2868
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2869 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2870 /* By default, ALmixer frees the Sound_Sample for predecoded
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2871 * samples because of the potential memory waste.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2872 * However, to seek a sample, we need to have a full
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2873 * copy of the data around. So the strategy is to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2874 * recreate a hackish Sound_Sample to be used for seeking
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2875 * purposes. If Sound_Sample is NULL, we will reallocate
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2876 * memory for it and then procede as if everything
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2877 * was normal.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2878 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2879 if(NULL == data->sample)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2880 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2881 if( -1 == Reconstruct_Sound_Sample(data) )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2882 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2883 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2884 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2885 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2886 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2887 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2888 /* If access_data was set, then we still have the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2889 * Sound_Sample and we can move around in the data.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2890 * If it was not set, the data has been freed and we
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2891 * cannot do anything because there is no way to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2892 * recover the data because OpenAL won't let us
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2893 * get access to the buffers
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2894 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2895 if(NULL == data->sample)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2896 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2897 ALmixer_SetError("Cannot seek because access_data flag was set false when data was initialized");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2898 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2899 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2900
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2901 fprintf(stderr, "Calling convert\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2902 byte_position = Convert_Msec_To_Byte_Pos(&data->sample->desired, msec);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2903 fprintf(stderr, "Calling Set_Predecoded_Seek...%d\n", byte_position);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2904 return( Set_Predecoded_Seek_Position(data, byte_position) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2905 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2906 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2907 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2908 /* Reset eof flag?? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2909 data->eof = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2910 retval = Sound_Seek(data->sample, msec);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2911 if(0 == retval)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2912 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2913 ALmixer_SetError(Sound_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2914
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2915 fprintf(stderr, "Sound seek error: %s\n", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2916 /* Try rewinding to clean up? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2917 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2918 Internal_RewindData(data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2919 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2920 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2921 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2922 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2923 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2924
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2925 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2926 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2927
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2928
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2929
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2930 static Sint32 Internal_FadeInChannelTimed(Sint32 channel, ALmixer_Data* data, Sint32 loops, Uint32 fade_ticks, Sint32 expire_ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2931 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2932 ALfloat value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2933 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2934 ALfloat original_value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2935 Uint32 current_time = SDL_GetTicks();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2936 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2937
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2938
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2939
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2940 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2941 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2942 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);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2943 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2944 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2945 /* Let's call PlayChannelTimed to do the job.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2946 * There are two catches:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2947 * First is that we must set the volumes before the play call(s).
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2948 * Second is that we must initialize the channel values
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2949 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2950
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2951 if(channel < 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2952 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2953 /* This might cause a problem for threads/race conditions.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2954 * We need to set the volume on an unknown channel,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2955 * so we need to request a channel first. Remember
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2956 * that requesting a channel doesn't lock and it
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2957 * could be surrendered to somebody else before we claim it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2958 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2959 channel = Internal_GetChannel(0);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2960 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2961 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2962 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2963 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2964 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2965 else if(ALmixer_Channel_List[channel].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2966 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2967 ALmixer_SetError("Channel %d is already in use", channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2968 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2969 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2970
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2971
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2972 /* Get the original volume in case of a problem */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2973 alGetSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2974 AL_MAX_GAIN, &original_value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2975
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2976 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2977 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2978 fprintf(stderr, "35Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2979 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2980 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2981 /* Get the Max volume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2982 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2983 alGetSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2984 AL_MAX_GAIN, &value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2985 ALmixer_Channel_List[channel].fade_end_volume = value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2986 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2987 ALmixer_Channel_List[channel].fade_end_volume =
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2988 ALmixer_Channel_List[channel].max_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2989
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2990 fprintf(stderr, "MAX gain: %f\n", value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2991 /* Get the Min volume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2992 alGetSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2993 AL_MIN_GAIN, &value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2994 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2995 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2996 fprintf(stderr, "36Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2997 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2998 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
2999 ALmixer_Channel_List[channel].fade_start_volume = value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3000 fprintf(stderr, "MIN gain: %f\n", value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3001
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3002 /* Set the actual volume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3003 alSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3004 AL_MAX_GAIN, value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3005 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3006 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3007 fprintf(stderr, "37Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3008 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3009 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3010
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3011
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3012 /* Now call PlayChannelTimed */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3013 retval = Internal_PlayChannelTimed(channel, data, loops, expire_ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3014 if(-1 == retval)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3015 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3016 /* Chance of failure is actually pretty high since
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3017 * a channel might already be in use or streamed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3018 * data can be shared
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3019 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3020 /* Restore the original value to avoid accidental
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3021 * distruption of playback
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3022 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3023 alSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3024 AL_MAX_GAIN, original_value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3025 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3026 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3027 fprintf(stderr, "38Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3028 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3029 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3030 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3031 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3032
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3033 /* We can't accept 0 as a value because of div-by-zero.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3034 * If zero, just call PlayChannelTimed at normal
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3035 * volume
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3036 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3037 if(0 == fade_ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3038 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3039 alSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3040 AL_MAX_GAIN,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3041 ALmixer_Channel_List[channel].fade_end_volume
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3042 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3043 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3044 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3045 fprintf(stderr, "39Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3046 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3047 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3048
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3049 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3050 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3051
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3052 /* Enable fading effects via the flag */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3053 ALmixer_Channel_List[channel].fade_enabled = 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3054 /* Set fade start time */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3055 ALmixer_Channel_List[channel].fade_start_time
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3056 = ALmixer_Channel_List[channel].start_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3057 fprintf(stderr, "Current time =%d\n", current_time);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3058 /* Set the fade expire ticks */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3059 ALmixer_Channel_List[channel].fade_expire_ticks = fade_ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3060
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3061 /* Set 1/(endtime-starttime) or 1/deltaT */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3062 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / fade_ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3063
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3064 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3065
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3066 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3067
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3068
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3069 static ALuint Internal_FadeInSourceTimed(ALuint source, ALmixer_Data* data, Sint32 loops, Uint32 fade_ticks, Sint32 expire_ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3070 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3071 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3072 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3073 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3074 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3075 retval = Internal_FadeInChannelTimed(-1, data, loops, fade_ticks, expire_ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3076 if(-1 == retval)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3077 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3078 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3079 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3080 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3081 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3082 return Internal_GetSource(retval);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3083 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3084 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3085
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3086 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3087 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3088 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3089 ALmixer_SetError("Cannot FadeIn source: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3090 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3091 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3092 retval = Internal_FadeInChannelTimed(channel, data, loops, fade_ticks, expire_ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3093 if(-1 == retval)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3094 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3095 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3096 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3097 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3098 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3099 return source;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3100 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3101 /* make compiler happy */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3102 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3103 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3104
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3105
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3106
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3107
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3108 /* Will fade out currently playing channels.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3109 * It starts at the current volume level and goes down */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3110 static Sint32 Internal_FadeOutChannel(Sint32 channel, Uint32 ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3111 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3112 ALfloat value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3113 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3114 Uint32 current_time = SDL_GetTicks();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3115 Uint32 counter = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3116
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3117 /* We can't accept 0 as a value because of div-by-zero.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3118 * If zero, just call Halt at normal
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3119 * volume
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3120 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3121 if(0 == ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3122 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3123 return Internal_HaltChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3124 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3125
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3126
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3127 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3128 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3129 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);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3130 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3131 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3132
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3133 if(channel >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3134 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3135 if(ALmixer_Channel_List[channel].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3136 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3137 /* Get the current volume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3138 alGetSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3139 AL_MAX_GAIN, &value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3140 ALmixer_Channel_List[channel].fade_start_volume = value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3141 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3142 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3143 fprintf(stderr, "40Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3144 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3145 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3146
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3147 /* Get the Min volume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3148 alGetSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3149 AL_MIN_GAIN, &value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3150 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3151 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3152 fprintf(stderr, "41Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3153 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3154 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3155 ALmixer_Channel_List[channel].fade_end_volume = value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3156 fprintf(stderr, "MIN gain: %f\n", value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3157
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3158 /* Set expire start time */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3159 ALmixer_Channel_List[channel].start_time = current_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3160 /* Set the expire ticks */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3161 ALmixer_Channel_List[channel].expire_ticks = ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3162 /* Set fade start time */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3163 ALmixer_Channel_List[channel].fade_start_time = current_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3164 /* Set the fade expire ticks */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3165 ALmixer_Channel_List[channel].fade_expire_ticks = ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3166 /* Enable fading effects via the flag */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3167 ALmixer_Channel_List[channel].fade_enabled = 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3168
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3169 /* Set 1/(endtime-starttime) or 1/deltaT */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3170 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3171
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3172 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3173 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3174 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3175 /* Else need to fade out all channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3176 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3177 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3178 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3179 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3180 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3181 if(ALmixer_Channel_List[i].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3182 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3183 /* Get the current volume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3184 alGetSourcef(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3185 AL_MAX_GAIN, &value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3186 ALmixer_Channel_List[i].fade_start_volume = value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3187 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3188 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3189 fprintf(stderr, "42Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3190 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3191 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3192
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3193 /* Get the Min volume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3194 alGetSourcef(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3195 AL_MIN_GAIN, &value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3196 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3197 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3198 fprintf(stderr, "43Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3199 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3200 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3201 ALmixer_Channel_List[i].fade_end_volume = value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3202 fprintf(stderr, "MIN gain: %f\n", value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3203
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3204 /* Set expire start time */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3205 ALmixer_Channel_List[i].start_time = current_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3206 /* Set the expire ticks */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3207 ALmixer_Channel_List[i].expire_ticks = ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3208 /* Set fade start time */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3209 ALmixer_Channel_List[i].fade_start_time = current_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3210 /* Set the fade expire ticks */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3211 ALmixer_Channel_List[i].fade_expire_ticks = ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3212 /* Enable fading effects via the flag */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3213 ALmixer_Channel_List[i].fade_enabled = 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3214
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3215 /* Set 1/(endtime-starttime) or 1/deltaT */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3216 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3217
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3218 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3219 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3220 } /* End for loop */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3221 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3222 return counter;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3223 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3224
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3225
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3226 static Sint32 Internal_FadeOutSource(ALuint source, Uint32 ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3227 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3228 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3229 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3230 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3231 return Internal_FadeOutChannel(-1, ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3232 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3233
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3234 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3235 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3236 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3237 ALmixer_SetError("Cannot FadeOut source: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3238 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3239 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3240 return Internal_FadeOutChannel(channel, ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3241 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3242
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3243
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3244 /* Will fade currently playing channels.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3245 * It starts at the current volume level and go to target
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3246 * Only affects channels that are playing
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3247 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3248 static Sint32 Internal_FadeChannel(Sint32 channel, Uint32 ticks, ALfloat volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3249 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3250 ALfloat value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3251 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3252 Uint32 current_time = SDL_GetTicks();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3253 Uint32 counter = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3254
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3255 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3256 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3257 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);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3258 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3259 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3260
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3261 if(channel >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3262 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3263 if(volume < ALmixer_Channel_List[channel].min_volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3264 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3265 volume = ALmixer_Channel_List[channel].min_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3266 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3267 else if(volume > ALmixer_Channel_List[channel].max_volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3268 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3269 volume = ALmixer_Channel_List[channel].max_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3270 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3271
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3272 if(ALmixer_Channel_List[channel].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3273 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3274 if(ticks > 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3275 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3276 /* Get the current volume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3277 alGetSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3278 AL_MAX_GAIN, &value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3279 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3280 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3281 fprintf(stderr, "44Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3282 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3283 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3284 ALmixer_Channel_List[channel].fade_start_volume = value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3285
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3286 /* Set the target volume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3287 ALmixer_Channel_List[channel].fade_end_volume = volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3288
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3289 /* Set fade start time */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3290 ALmixer_Channel_List[channel].fade_start_time = current_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3291 /* Set the fade expire ticks */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3292 ALmixer_Channel_List[channel].fade_expire_ticks = ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3293 /* Enable fading effects via the flag */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3294 ALmixer_Channel_List[channel].fade_enabled = 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3295
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3296 /* Set 1/(endtime-starttime) or 1/deltaT */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3297 ALmixer_Channel_List[channel].fade_inv_time = 1.0f / ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3298 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3299 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3300 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3301 alSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3302 AL_MAX_GAIN, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3303 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3304 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3305 fprintf(stderr, "45Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3306 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3307 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3308 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3309 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3310 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3311 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3312 /* Else need to fade out all channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3313 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3314 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3315 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3316 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3317 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3318 if(volume < ALmixer_Channel_List[i].min_volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3319 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3320 volume = ALmixer_Channel_List[i].min_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3321 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3322 else if(volume > ALmixer_Channel_List[i].max_volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3323 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3324 volume = ALmixer_Channel_List[i].max_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3325 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3326
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3327 if(ALmixer_Channel_List[i].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3328 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3329 if(ticks > 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3330 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3331 /* Get the current volume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3332 alGetSourcef(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3333 AL_MAX_GAIN, &value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3334 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3335 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3336 fprintf(stderr, "46Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3337 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3338 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3339 ALmixer_Channel_List[i].fade_start_volume = value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3340
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3341 /* Set target volume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3342 ALmixer_Channel_List[i].fade_end_volume = volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3343
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3344 /* Set fade start time */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3345 ALmixer_Channel_List[i].fade_start_time = current_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3346 /* Set the fade expire ticks */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3347 ALmixer_Channel_List[i].fade_expire_ticks = ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3348 /* Enable fading effects via the flag */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3349 ALmixer_Channel_List[i].fade_enabled = 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3350
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3351 /* Set 1/(endtime-starttime) or 1/deltaT */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3352 ALmixer_Channel_List[i].fade_inv_time = 1.0f / ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3353 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3354 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3355 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3356 alSourcef(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3357 AL_MAX_GAIN, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3358 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3359 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3360 fprintf(stderr, "47Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3361 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3362 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3363 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3364 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3365 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3366 } /* End for loop */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3367 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3368 return counter;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3369 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3370
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3371 static Sint32 Internal_FadeSource(ALuint source, Uint32 ticks, ALfloat volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3372 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3373 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3374 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3375 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3376 return Internal_FadeChannel(-1, ticks, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3377 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3378
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3379 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3380 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3381 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3382 ALmixer_SetError("Cannot Fade source: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3383 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3384 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3385 return Internal_FadeChannel(channel, ticks, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3386 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3387
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3388
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3389
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3390
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3391 /* Set a volume regardless if it's in use or not.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3392 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3393 static Sint32 Internal_SetMaxVolumeChannel(Sint32 channel, ALfloat volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3394 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3395 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3396 Sint32 retval = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3397
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3398 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3399 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3400 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);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3401 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3402 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3403
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3404 if(channel >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3405 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3406 if(volume < 0.0f)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3407 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3408 volume = 0.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3409 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3410 else if(volume > 1.0f)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3411 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3412 volume = 1.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3413 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3414 ALmixer_Channel_List[channel].max_volume = volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3415 alSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3416 AL_MAX_GAIN, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3417 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3418 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3419 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3420 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3421 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3422 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3423 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3424 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3425 ALmixer_Channel_List[channel].min_volume = volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3426 alSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3427 AL_MIN_GAIN, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3428 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3429 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3430 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3431 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3432 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3433 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3434 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3435 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3436 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3437 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3438 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3439 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3440 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3441 if(volume < 0.0f)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3442 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3443 volume = 0.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3444 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3445 else if(volume > 1.0f)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3446 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3447 volume = 1.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3448 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3449 ALmixer_Channel_List[i].max_volume = volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3450 alSourcef(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3451 AL_MAX_GAIN, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3452 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3453 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3454 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3455 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3456 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3457 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3458 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3459 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3460 ALmixer_Channel_List[i].min_volume = volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3461 alSourcef(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3462 AL_MIN_GAIN, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3463 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3464 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3465 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3466 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3467 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3468 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3469 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3470 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3471 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3472 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3473 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3474
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3475 static Sint32 Internal_SetMaxVolumeSource(ALuint source, ALfloat volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3476 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3477 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3478 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3479 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3480 return Internal_SetMaxVolumeChannel(-1, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3481 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3482
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3483 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3484 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3485 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3486 ALmixer_SetError("Cannot SetMaxVolume: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3487 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3488 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3489 return Internal_SetMaxVolumeChannel(channel, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3490 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3491
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3492 static ALfloat Internal_GetMaxVolumeChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3493 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3494 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3495 ALfloat value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3496 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3497 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3498 ALfloat running_total = 0.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3499 ALfloat retval = 0.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3500
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3501 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3502 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3503 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);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3504 return -1.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3505 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3506
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3507 if(channel >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3508 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3509 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3510 alGetSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3511 AL_GAIN, &value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3512 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3513 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3514 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3515 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3516 retval = -1.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3517 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3518 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3519 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3520 retval = value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3521 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3522 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3523 retval = ALmixer_Channel_List[channel].max_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3524
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3525 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3526 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3527 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3528 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3529 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3530 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3531 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3532 alGetSourcef(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3533 AL_GAIN, &value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3534 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3535 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3536 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3537 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3538 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3539 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3540 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3541 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3542 running_total += value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3543 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3544 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3545 running_total += ALmixer_Channel_List[i].max_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3546 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3547 if(0 == Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3548 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3549 ALmixer_SetError("No channels are allocated");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3550 retval = -1.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3551 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3552 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3553 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3554 retval = running_total / Number_of_Channels_global;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3555 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3556 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3557 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3558 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3559
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3560 static ALfloat Internal_GetMaxVolumeSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3561 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3562 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3563 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3564 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3565 return Internal_GetMaxVolumeChannel(-1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3566 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3567
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3568 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3569 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3570 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3571 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3572 return -1.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3573 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3574
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3575 return Internal_GetMaxVolumeChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3576 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3577
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3578
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3579 /* Set a volume regardless if it's in use or not.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3580 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3581 static Sint32 Internal_SetMinVolumeChannel(Sint32 channel, ALfloat volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3582 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3583 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3584 Sint32 retval = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3585
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3586 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3587 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3588 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);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3589 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3590 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3591
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3592 if(channel >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3593 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3594 if(volume < 0.0f)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3595 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3596 volume = 0.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3597 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3598 else if(volume > 1.0f)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3599 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3600 volume = 1.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3601 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3602 ALmixer_Channel_List[channel].min_volume = volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3603 alSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3604 AL_MIN_GAIN, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3605 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3606 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3607 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3608 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3609 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3610 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3611 if(ALmixer_Channel_List[channel].max_volume < ALmixer_Channel_List[channel].min_volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3612 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3613 ALmixer_Channel_List[channel].max_volume = volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3614 alSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3615 AL_MAX_GAIN, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3616 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3617 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3618 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3619 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3620 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3621 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3622 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3623 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3624 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3625 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3626 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3627 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3628 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3629 if(volume < 0.0f)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3630 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3631 volume = 0.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3632 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3633 else if(volume > 1.0f)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3634 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3635 volume = 1.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3636 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3637 ALmixer_Channel_List[i].min_volume = volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3638 alSourcef(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3639 AL_MIN_GAIN, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3640 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3641 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3642 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3643 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3644 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3645 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3646 if(ALmixer_Channel_List[i].max_volume < ALmixer_Channel_List[i].min_volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3647 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3648 ALmixer_Channel_List[i].max_volume = volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3649 alSourcef(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3650 AL_MAX_GAIN, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3651 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3652 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3653 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3654 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3655 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3656 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3657 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3658 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3659 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3660 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3661 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3662
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3663 static Sint32 Internal_SetMinVolumeSource(ALuint source, ALfloat volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3664 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3665 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3666 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3667 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3668 return Internal_SetMinVolumeChannel(-1, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3669 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3670
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3671 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3672 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3673 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3674 ALmixer_SetError("Cannot SetMaxVolume: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3675 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3676 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3677 return Internal_SetMinVolumeChannel(channel, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3678 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3679
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3680 static ALfloat Internal_GetMinVolumeChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3681 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3682 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3683 ALfloat value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3684 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3685 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3686 ALfloat running_total = 0.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3687 ALfloat retval = 0.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3688
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3689 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3690 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3691 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);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3692 return -1.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3693 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3694
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3695 if(channel >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3696 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3697 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3698 alGetSourcef(ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3699 AL_GAIN, &value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3700 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3701 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3702 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3703 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3704 retval = -1.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3705 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3706 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3707 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3708 retval = value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3709 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3710 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3711 retval = ALmixer_Channel_List[channel].min_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3712
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3713 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3714 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3715 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3716 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3717 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3718 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3719 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3720 alGetSourcef(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3721 AL_GAIN, &value);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3722 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3723 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3724 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3725 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3726 retval = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3727 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3728 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3729 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3730 running_total += value;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3731 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3732 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3733 running_total += ALmixer_Channel_List[i].min_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3734 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3735 if(0 == Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3736 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3737 ALmixer_SetError("No channels are allocated");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3738 retval = -1.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3739 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3740 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3741 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3742 retval = running_total / Number_of_Channels_global;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3743 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3744 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3745 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3746 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3747
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3748 static ALfloat Internal_GetMinVolumeSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3749 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3750 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3751 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3752 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3753 return Internal_GetMinVolumeChannel(-1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3754 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3755
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3756 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3757 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3758 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3759 ALmixer_SetError("Cannot GetVolume: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3760 return -1.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3761 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3762
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3763 return Internal_GetMinVolumeChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3764 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3765
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3766
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3767 /* Changes the listener volume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3768 static Sint32 Internal_SetMasterVolume(ALfloat volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3769 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3770 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3771 alListenerf(AL_GAIN, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3772 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3773 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3774 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3775 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3776 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3777 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3778 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3779 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3780
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3781 static ALfloat Internal_GetMasterVolume()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3782 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3783 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3784 ALfloat volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3785 alGetListenerf(AL_GAIN, &volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3786 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3787 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3788 ALmixer_SetError("%s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3789 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3790 return -1.0f;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3791 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3792 return volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3793 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3794
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3795
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3796
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3797
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3798 /* Will fade out currently playing channels.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3799 * It starts at the current volume level and goes down */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3800 static Sint32 Internal_ExpireChannel(Sint32 channel, Sint32 ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3801 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3802 Uint32 current_time = SDL_GetTicks();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3803 Uint32 counter = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3804
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3805 /* We can't accept 0 as a value because of div-by-zero.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3806 * If zero, just call Halt at normal
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3807 * volume
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3808 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3809 if(0 == ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3810 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3811 return Internal_HaltChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3812 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3813 if(ticks < -1)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3814 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3815 ticks = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3816 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3817
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3818
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3819 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3820 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3821 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);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3822 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3823 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3824
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3825 if(channel >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3826 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3827 if(ALmixer_Channel_List[channel].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3828 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3829 /* Set expire start time */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3830 ALmixer_Channel_List[channel].start_time = current_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3831 /* Set the expire ticks */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3832 ALmixer_Channel_List[channel].expire_ticks = ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3833
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3834 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3835 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3836 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3837 /* Else need to fade out all channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3838 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3839 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3840 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3841 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3842 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3843 if(ALmixer_Channel_List[i].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3844 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3845 /* Set expire start time */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3846 ALmixer_Channel_List[i].start_time = current_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3847 /* Set the expire ticks */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3848 ALmixer_Channel_List[i].expire_ticks = ticks;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3849
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3850 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3851 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3852 } /* End for loop */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3853 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3854 return counter;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3855 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3856
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3857
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3858 static Sint32 Internal_ExpireSource(ALuint source, Sint32 ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3859 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3860 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3861 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3862 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3863 return Internal_ExpireChannel(-1, ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3864 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3865
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3866 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3867 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3868 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3869 ALmixer_SetError("Cannot Expire source: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3870 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3871 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3872 return Internal_ExpireChannel(channel, ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3873 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3874
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3875
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3876 static Sint32 Internal_QueryChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3877 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3878 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3879 Sint32 counter = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3880 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3881 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3882 ALmixer_SetError("Invalid channel: %d", channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3883 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3884 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3885
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3886 if(channel >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3887 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3888 return ALmixer_Channel_List[channel].channel_in_use;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3889 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3890
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3891 /* Else, return the number of channels in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3892 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3893 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3894 if(ALmixer_Channel_List[i].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3895 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3896 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3897 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3898 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3899 return counter;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3900 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3901
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3902
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3903 static Sint32 Internal_QuerySource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3904 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3905 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3906 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3907 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3908 return Internal_QueryChannel(-1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3909 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3910
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3911 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3912 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3913 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3914 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3915 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3916 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3917
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3918 return Internal_QueryChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3919 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3920
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3921
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3922 static Sint32 Internal_CountUnreservedUsedChannels()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3923 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3924 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3925 Sint32 counter = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3926
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3927
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3928 /* Else, return the number of channels in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3929 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3930 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3931 if(ALmixer_Channel_List[i].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3932 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3933 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3934 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3935 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3936 return counter;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3937 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3938
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3939 static Sint32 Internal_CountUnreservedFreeChannels()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3940 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3941 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3942 Sint32 counter = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3943
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3944
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3945 /* Else, return the number of channels in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3946 for(i=Number_of_Reserve_Channels_global; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3947 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3948 if( ! ALmixer_Channel_List[i].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3949 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3950 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3951 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3952 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3953 return counter;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3954 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3955
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3956 static Sint32 Internal_CountAllUsedChannels()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3957 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3958 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3959 Sint32 counter = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3960
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3961
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3962 /* Else, return the number of channels in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3963 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3964 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3965 if(ALmixer_Channel_List[i].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3966 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3967 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3968 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3969 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3970 return counter;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3971 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3972
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3973 static Sint32 Internal_CountAllFreeChannels()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3974 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3975 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3976 Sint32 counter = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3977
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3978
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3979 /* Else, return the number of channels in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3980 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3981 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3982 if( ! ALmixer_Channel_List[i].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3983 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3984 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3985 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3986 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3987 return counter;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3988 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3989
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3990
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3991 static Sint32 Internal_PlayingChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3992 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3993 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3994 Sint32 counter = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3995 ALint state;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3996
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3997 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3998 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
3999 ALmixer_SetError("Invalid channel: %d", channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4000 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4001 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4002
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4003 if(channel >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4004 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4005 if(ALmixer_Channel_List[channel].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4006 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4007 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4008 ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4009 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4010 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4011 if(AL_PLAYING == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4012 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4013 return 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4014 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4015 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4016 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4017 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4018
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4019 /* Else, return the number of channels in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4020 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4021 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4022 if(ALmixer_Channel_List[i].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4023 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4024 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4025 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4026 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4027 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4028 if(AL_PLAYING == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4029 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4030 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4031 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4032 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4033 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4034 return counter;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4035 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4036
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4037
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4038 static Sint32 Internal_PlayingSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4039 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4040 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4041 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4042 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4043 return Internal_PlayingChannel(-1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4044 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4045
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4046 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4047 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4048 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4049 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4050 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4051 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4052
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4053 return Internal_PlayingChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4054 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4055
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4056
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4057 static Sint32 Internal_PausedChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4058 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4059 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4060 Sint32 counter = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4061 ALint state;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4062
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4063 if(channel >= Number_of_Channels_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4064 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4065 ALmixer_SetError("Invalid channel: %d", channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4066 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4067 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4068
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4069 if(channel >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4070 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4071 if(ALmixer_Channel_List[channel].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4072 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4073 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4074 ALmixer_Channel_List[channel].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4075 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4076 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4077 if(AL_PAUSED == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4078 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4079 return 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4080 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4081 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4082 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4083 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4084
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4085 /* Else, return the number of channels in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4086 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4087 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4088 if(ALmixer_Channel_List[i].channel_in_use)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4089 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4090 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4091 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4092 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4093 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4094 if(AL_PAUSED == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4095 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4096 counter++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4097 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4098 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4099 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4100 return counter;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4101 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4102
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4103
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4104 static Sint32 Internal_PausedSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4105 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4106 Sint32 channel;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4107 if(0 == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4108 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4109 return Internal_PausedChannel(-1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4110 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4111
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4112 channel = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4113 if(-1 == channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4114 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4115 ALmixer_SetError("Cannot query source: %s", ALmixer_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4116 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4117 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4118
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4119 return Internal_PausedChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4120 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4121
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4122
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4123
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4124
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4125
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4126
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4127 /* Private function for Updating ALmixer.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4128 * This is a very big and ugly function.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4129 * It should return the number of buffers that were
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4130 * queued during the call. The value might be
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4131 * used to guage how long you might wait to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4132 * call the next update loop in case you are worried
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4133 * about preserving CPU cycles. The idea is that
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4134 * when a buffer is queued, there was probably some
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4135 * CPU intensive looping which took awhile.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4136 * It's mainly provided as a convenience.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4137 * Timing the call with SDL_GetTicks() would produce
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4138 * more accurate information.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4139 * Returns a negative value if there was an error,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4140 * the value being the number of errors.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4141 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4142 static Sint32 Update_ALmixer(void* data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4143 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4144 Sint32 retval = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4145 Sint32 error_flag = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4146 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4147 ALint state;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4148 Sint32 i=0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4149
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4150 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4151 if(0 == ALmixer_Initialized)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4152 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4153 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4154 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4155 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4156
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4157 /* Check the quick flag to see if anything needs updating */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4158 /* If anything is playing, then we have to do work */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4159 if( 0 == Is_Playing_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4160 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4161 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4162 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4163 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4164 /* Clear error */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4165 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4166 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4167 fprintf(stderr, "08Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4168 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4169 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4170 alGetError();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4171
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4172 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4173 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4174 if( ALmixer_Channel_List[i].channel_in_use )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4175 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4176
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4177 /* For simplicity, before we do anything else,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4178 * we can check the timeout and fading values
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4179 * and do the appropriate things
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4180 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4181 Uint32 current_time = SDL_GetTicks();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4182
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4183 /* Check to see if we need to halt due to Timed play */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4184 if(ALmixer_Channel_List[i].expire_ticks != -1)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4185 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4186 Uint32 target_time = (Uint32)ALmixer_Channel_List[i].expire_ticks
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4187 + ALmixer_Channel_List[i].start_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4188 alGetSourcei(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4189 AL_SOURCE_STATE, &state);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4190 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4191 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4192 fprintf(stderr, "06Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4193 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4194 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4195
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4196 /* Check the time, and also make sure that it is not
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4197 * paused (if paused, we don't want to make the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4198 * evaluation because when resumed, we will adjust
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4199 * the times to compensate for the pause).
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4200 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4201 if( (current_time >= target_time)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4202 && (state != AL_PAUSED) )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4203 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4204 /* Stop the playback */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4205 ALmixer_HaltChannel(i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4206 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4207 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4208 fprintf(stderr, "07Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4209 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4210 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4211
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4212 /* Everything should be done so go on to the next loop */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4213 continue;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4214 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4215 } /* End if time expired check */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4216
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4217 /* Check to see if we need to adjust the volume for fading */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4218 if( ALmixer_Channel_List[i].fade_enabled )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4219 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4220 Uint32 target_time = ALmixer_Channel_List[i].fade_expire_ticks
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4221 + ALmixer_Channel_List[i].fade_start_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4222 alGetSourcei(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4223 AL_SOURCE_STATE, &state);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4224 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4225 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4226 fprintf(stderr, "05Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4227 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4228 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4229
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4230 /* Check the time, and also make sure that it is not
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4231 * paused (if paused, we don't want to make the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4232 * evaluation because when resumed, we will adjust
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4233 * the times to compensate for the pause).
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4234 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4235 if(state != AL_PAUSED)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4236 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4237 ALfloat t;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4238 Uint32 delta_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4239 ALfloat current_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4240 if(current_time >= target_time)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4241 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4242 /* Need to constrain value to the end time
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4243 * (can't go pass the value for calculations)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4244 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4245 current_time = target_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4246 /* We can disable the fade flag now */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4247 ALmixer_Channel_List[i].fade_enabled = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4248 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4249 /* Use the linear interpolation formula:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4250 * X = (1-t)x0 + tx1
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4251 * where x0 would be the start value
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4252 * and x1 is the final value
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4253 * and t is delta_time*inv_time (adjusts 0 <= time <= 1)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4254 * delta_time = current_time-start_time
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4255 * inv_time = 1/ (end_time-start_time)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4256 * so t = current_time-start_time / (end_time-start_time)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4257 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4258 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4259 delta_time = current_time - ALmixer_Channel_List[i].fade_start_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4260 t = (ALfloat) delta_time * ALmixer_Channel_List[i].fade_inv_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4261
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4262 current_volume = (1.0f-t) * ALmixer_Channel_List[i].fade_start_volume
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4263 + t * ALmixer_Channel_List[i].fade_end_volume;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4264
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4265 /* Set the volume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4266 alSourcef(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4267 AL_MAX_GAIN, current_volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4268 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4269 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4270 fprintf(stderr, "04Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4271 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4272 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4273
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4274 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4275 fprintf(stderr, "Current time =%d\n", current_time);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4276 fprintf(stderr, "Current vol=%f on channel %d\n", current_volume, i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4277 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4278 } /* End if not PAUSED */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4279 } /* End if fade_enabled */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4280
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4281
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4282 /* Okay, now that the time expired and fading stuff
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4283 * is done, do the rest of the hard stuff
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4284 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4285
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4286
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4287 /* For predecoded, check to see if done */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4288 if( ALmixer_Channel_List[i].almixer_data->decoded_all )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4289 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4290
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4291 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4292 /********* Remove this **********/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4293 ALint buffers_processed;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4294 ALint buffers_still_queued;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4295 fprintf(stderr, "For Predecoded\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4296
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4297 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4298 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4299 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4300 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4301 switch(state) {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4302 case AL_PLAYING:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4303 fprintf(stderr, "Channel '%d' is PLAYING\n", i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4304 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4305 case AL_PAUSED:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4306 fprintf(stderr, "Channel '%d' is PAUSED\n",i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4307 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4308 case AL_STOPPED:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4309 fprintf(stderr, "Channel '%d' is STOPPED\n",i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4310 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4311 case AL_INITIAL:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4312 fprintf(stderr, "Channel '%d' is INITIAL\n",i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4313 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4314 default:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4315 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4316 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4317 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4318
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4319 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4320 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4321 AL_BUFFERS_PROCESSED, &buffers_processed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4322 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4323 fprintf(stderr, "Buffers processed = %d\n", buffers_processed);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4324
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4325 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4326 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4327 AL_BUFFERS_QUEUED, &buffers_still_queued
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4328 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4329
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4330 /******** END REMOVE *******/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4331 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4332 /* FIXME: Ugh! Somewhere an alError is being thrown ("Invalid Enum Value"), but I can't
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4333 * find it. It only seems to be thrown for OS X. I placed error messages after every al*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4334 * command I could find in the above loops, but the error doesn't seem to show
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4335 * up until around here. I mistook it for a get queued buffers
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4336 * error in OS X. I don't think there's an error down there.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4337 * For now, I'm clearing the error here.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4338 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4339
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4340 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4341 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4342 fprintf(stderr, "03Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4343 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4344 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4345
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4346
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4347 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4348 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4349 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4350 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4351 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4352 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4353 fprintf(stderr, "02Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4354 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4355 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4356
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4357
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4358 if(AL_STOPPED == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4359 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4360 /* Playback has ended.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4361 * Loop if necessary, or launch callback
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4362 * and clear channel (or clear channel and
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4363 * then launch callback?)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4364 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4365
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4366
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4367 /* Need to check for loops */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4368 if(ALmixer_Channel_List[i].loops != 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4369 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4370 /* Corner Case: If the buffer has
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4371 * been modified using Seek,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4372 * the loop will start at the seek
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4373 * position.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4374 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4375 if(ALmixer_Channel_List[i].loops != -1)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4376 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4377 ALmixer_Channel_List[i].loops--;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4378 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4379 alSourcePlay(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4380 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4381 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4382 fprintf(stderr, "50Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4383 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4384 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4385 continue;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4386 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4387 /* No loops. End play. */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4388 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4389 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4390 /* Problem: It seems that when mixing
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4391 * streamed and predecoded sources,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4392 * the previous instance lingers,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4393 * so we need to force remove
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4394 * the data from the source.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4395 * The sharing problem
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4396 * occurs when a previous predecoded buffer is played on
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4397 * a source, and then a streamed source is played later
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4398 * on that same source. OpenAL isn't consistently
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4399 * removing the previous buffer so both get played.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4400 * (Different dists seem to have different quirks.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4401 * The problem might lead to crashes in the worst case.)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4402 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4403 /* Additional problem: There is another
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4404 * inconsistency among OpenAL distributions.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4405 * Both Loki and Creative Windows seem to keep
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4406 * the buffer queued which requires removing.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4407 * But the Creative Macintosh version does
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4408 * not have any buffer queued after play
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4409 * and it returns the error: Invalid Enum Value
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4410 * if I try to unqueue it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4411 * So I'm going to put in a check to see if I
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4412 * can detect any buffers queued first
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4413 * and then unqueue them if I can see them.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4414 * Additional note: The new CoreAudio based
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4415 * implementation leaves it's buffer queued
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4416 * like Loki and Creative Windows. But
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4417 * considering all the problems I'm having
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4418 * with the different distributions, this
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4419 * check seems reasonable.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4420 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4421 ALint buffers_still_queued;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4422 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4423 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4424 fprintf(stderr, "01Testing errpr before unqueue because getting stuff, for OS X this is expected: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4425 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4426 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4427
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4428 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4429 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4430 AL_BUFFERS_QUEUED, &buffers_still_queued
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4431 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4432 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4433 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4434 fprintf(stderr, "Error with unqueue, for OS X this is expected: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4435 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4436 ALmixer_SetError("Failed detecting unqueued predecoded buffer (expected with OS X): %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4437 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4438 error_flag--;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4439 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4440 if(buffers_still_queued > 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4441 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4442 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4443 PrintQueueStatus(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4444 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4445
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4446 /* Rather than force unqueuing the buffer, let's see if
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4447 * setting the buffer to none works (the OpenAL 1.0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4448 * Reference Annotation suggests this should work).
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4449 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4450 alSourcei(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4451 AL_BUFFER, AL_NONE);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4452 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4453 PrintQueueStatus(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4454 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4455 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4456 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4457 fprintf(stderr, "Error with unqueue, after alSourceUnqueueBuffers, buffers_still_queued=%d, error is: %s", buffers_still_queued,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4458 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4459 ALmixer_SetError("Predecoded Unqueue buffer failed: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4460 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4461 error_flag--;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4462 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4463
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4464 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4465
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4466 Clean_Channel(i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4467 /* Subtract counter */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4468 Is_Playing_global--;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4469
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4470 /* Launch callback */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4471 Invoke_Channel_Done_Callback(i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4472
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4473 /* We're done for this loop.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4474 * Go to next channel
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4475 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4476 continue;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4477 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4478 continue;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4479 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4480 } /* End if decoded_all */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4481 /* For streamed */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4482 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4483 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4484 ALint buffers_processed;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4485 ALint buffers_still_queued;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4486 ALint current_buffer_id;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4487
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4488 ALuint unqueued_buffer_id;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4489 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4490 /********* Remove this **********/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4491 fprintf(stderr, "For Streamed\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4492
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4493 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4494 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4495 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4496 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4497 switch(state) {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4498 case AL_PLAYING:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4499 fprintf(stderr, "Channel '%d' is PLAYING\n", i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4500 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4501 case AL_PAUSED:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4502 fprintf(stderr, "Channel '%d' is PAUSED\n",i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4503 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4504 case AL_STOPPED:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4505 fprintf(stderr, "Channel '%d' is STOPPED\n",i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4506 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4507 case AL_INITIAL:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4508 fprintf(stderr, "Channel '%d' is INITIAL\n",i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4509 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4510 default:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4511 fprintf(stderr, "Channel '%d' is UNKNOWN\n",i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4512 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4513 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4514 /******** END REMOVE *******/
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4515 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4516 /* Get the number of buffers still queued */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4517 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4518 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4519 AL_BUFFERS_QUEUED, &buffers_still_queued
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4520 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4521 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4522 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4523 fprintf(stderr, "51Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4524 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4525 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4526 /* Get the number of buffers processed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4527 * so we know if we need to refill
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4528 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4529 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4530 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4531 AL_BUFFERS_PROCESSED, &buffers_processed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4532 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4533 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4534 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4535 fprintf(stderr, "52Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4536 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4537 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4538
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4539 /* WTF!!! The Nvidia distribution is failing on the alGetSourcei(source, AL_BUFFER, buf_id) call.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4540 * I need this call to figure out which buffer OpenAL is currently playing.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4541 * It keeps returning an "Invalid Enum" error.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4542 * This is totally inane! It's a basic query.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4543 * By the spec, this functionality is not explicitly defined so Nvidia refuses to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4544 * fix this behavior, even though all other distributions work fine with this.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4545 * The only workaround for this is for
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4546 * a significant rewrite of my code which requires me to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4547 * duplicate the OpenAL queued buffers state with my own
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4548 * code and try to derive what the current playing buffer is by indirect observation of
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4549 * looking at buffers_processed. But of course this has a ton of downsides since my
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4550 * queries do not give me perfect timing of what OpenAL is actually doing and
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4551 * the fact that some of the distributions seem to have buffer queuing problems
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4552 * with their query results (CoreAudio). This also means a ton of extra code
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4553 * on my side. The lack of support of a 1 line call has required me to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4554 * implement yet another entire state machine. <sigh>
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4555 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4556 #if 0 /* This code will not work until possibly OpenAL 1.1 because of Nvidia */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4557 /* Get the id to the current buffer playing */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4558 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4559 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4560 AL_BUFFER, ¤t_buffer_id
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4561 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4562 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4563 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4564 fprintf(stderr, "53Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4565 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4566 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4567
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4568 /* Before the hard stuff, check to see if the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4569 * current queued AL buffer has changed.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4570 * If it has, we should launch a data callback if
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4571 * necessary
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4572 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4573 if( ((ALuint)current_buffer_id) !=
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4574 ALmixer_Channel_List[i].almixer_data->current_buffer)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4575 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4576 ALmixer_Channel_List[i].almixer_data->current_buffer
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4577 = (ALuint)current_buffer_id;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4578
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4579 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4580 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4581 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4582 /* Only do this if "access_data" was requested (i.e. the circular_buffer!=NULL)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4583 * And if one of the two are true:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4584 * Either buffers_processed > 0 (because the current_buffer might have changed)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4585 * or if the current_buffer==0 (because we are in an initial state or recovering from
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4586 * a buffer underrun)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4587 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4588 if((ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4589 && (
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4590 (buffers_processed > 0) || (0 == ALmixer_Channel_List[i].almixer_data->current_buffer)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4591 )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4592 )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4593 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4594 Uint32 k;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4595 Uint32 queue_ret_flag;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4596 Uint8 is_out_of_sync = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4597 Uint32 my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4598 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4599 fprintf(stderr, "Queue in processed check, before pop, buffers_processed=%d\n", buffers_processed);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4600 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4601 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4602 /* We can't make any determinations solely based on the number of buffers_processed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4603 * because currently, we only unqueue 1 buffer per loop. That means if 2 or more
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4604 * buffers became processed in one loop, the following loop, we would have
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4605 * at least that_many-1 buffers_processed (plus possible new processed).
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4606 * If we tried to just remove 1 buffer from our queue, we would be incorrect
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4607 * because we would not actually reflect the current playing buffer.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4608 * So the solution seems to be to make sure our queue is the same size
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4609 * as the number of buffers_queued-buffers_processed, and return the head of our queue
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4610 * as the current playing buffer.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4611 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4612 /* Also, we have a corner case. When we first start playing or if we have
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4613 * a buffer underrun, we have not done a data callback.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4614 * In this case, we need to see if there is any new data in our queue
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4615 * and if so, launch that data callback.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4616 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4617 /* Warning, this code risks the possibility of no data callback being fired if
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4618 * the system is really late (or skipped buffers).
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4619 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4620
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4621 /* First, let's syncronize our queue with the OpenAL queue */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4622 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4623 fprintf(stderr, "inside, Buffers processed=%d, Buffers queued=%d, my queue=%d\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4624 buffers_processed, buffers_still_queued, my_queue_size);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4625 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4626 if(my_queue_size > (buffers_still_queued - buffers_processed))
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4627 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4628 is_out_of_sync = 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4629 for(k=0; k<(my_queue_size - (buffers_still_queued - buffers_processed)); k++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4630 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4631 queue_ret_flag = CircularQueueUnsignedInt_PopFront(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4632 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4633 if(0 == queue_ret_flag)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4634 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4635 fprintf(stderr, "53 Error popping queue\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4636 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4637 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4638 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4639 my_queue_size = CircularQueueUnsignedInt_Size(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4640 /* We have several possibilities we need to handle:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4641 * 1) We are in an initial state or underrun and need to do a data callback on the head.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4642 * 2) We were out of sync and need to do a new data callback on the new head.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4643 * 3) We were not out of sync but just had left over processed buffers which caused us to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4644 * fall in this block of code. (Don't do anything.)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4645 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4646 if( (0 == ALmixer_Channel_List[i].almixer_data->current_buffer) || (1 == is_out_of_sync) )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4647 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4648 if(my_queue_size > 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4649 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4650 current_buffer_id = CircularQueueUnsignedInt_Front(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4651 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4652 if(0 == current_buffer_id)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4653 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4654 fprintf(stderr, "53a Internal Error, current_buffer_id=0 when it shouldn't be 0\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4655 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4656 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4657 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4658 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4659 fprintf(stderr, "Queue in processed check, after pop\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4660 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4661 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4662 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4663 ALmixer_Channel_List[i].almixer_data->current_buffer
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4664 = (ALuint)current_buffer_id;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4665
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4666 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4667 /* Remove me...only for checking...doesn't work on Nvidia */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4668 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4669 ALuint real_id;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4670 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4671 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4672 AL_BUFFER, &real_id
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4673 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4674 alGetError();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4675 fprintf(stderr, "Callback fired on data buffer=%d, real_id shoud be=%d\n", current_buffer_id, real_id);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4676 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4677 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4678 Invoke_Streamed_Channel_Data_Callback(i, ALmixer_Channel_List[i].almixer_data, current_buffer_id);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4679 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4680 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4681 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4682 fprintf(stderr, "53b, Notice/Warning:, OpenAL queue has been depleted.\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4683 /* In this case, we might either be in an underrun or finished with playback */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4684 ALmixer_Channel_List[i].almixer_data->current_buffer = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4685 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4686 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4687 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4688 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4689
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4690
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4691
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4692 /* Just a test - remove
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4693 if( ALmixer_Channel_List[i].loops > 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4694 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4695 fprintf(stderr, ">>>>>>>>>>>>>>>Loops = %d\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4696 ALmixer_Channel_List[i].loops);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4697 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4698 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4699 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4700 fprintf(stderr, "Buffers processed = %d\n", buffers_processed);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4701 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4702 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4703 /* We've used up a buffer so we need to unqueue and replace */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4704 /* Okay, it gets more complicated here:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4705 * We need to Queue more data
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4706 * if buffers_processed > 0 or
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4707 * if num_of_buffers_in_use < NUMBER_OF_QUEUE_BUFFERS
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4708 * but we don't do this if at EOF,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4709 * except when there is looping
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4710 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4711 /* For this to work, we must rely on EVERYTHING
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4712 * else to unset the EOF if there is looping.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4713 * Remember, even Play() must do this
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4714 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4715
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4716 /* If not EOF, then we are still playing.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4717 * Inside, we might find num_of_buffers < NUM...QUEUE_BUF..
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4718 * or buffers_process > 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4719 * in which case we queue up.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4720 * We also might find no buffers we need to fill,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4721 * in which case we just keep going
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4722 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4723 if( ! ALmixer_Channel_List[i].almixer_data->eof)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4724 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4725 Uint32 bytes_returned;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4726 /* We have a priority. We first must assign
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4727 * unused buffers in reserve. If there is nothing
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4728 * left, then we may unqueue buffers. We can't
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4729 * do it the other way around because we will
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4730 * lose the pointer to the unqueued buffer
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4731 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4732 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4733 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4734 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4735 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4736 fprintf(stderr, "Getting more data in NOT_EOF and num_buffers_in_use (%d) < max_queue (%d)\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4737 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4738 ALmixer_Channel_List[i].almixer_data->max_queue_buffers);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4739 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4740 /* Going to add an unused packet.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4741 * Grab next packet */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4742 bytes_returned = GetMoreData(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4743 ALmixer_Channel_List[i].almixer_data,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4744 ALmixer_Channel_List[i].almixer_data->buffer[
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4745 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use]
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4746 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4747 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4748 /* For processed > 0 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4749 else if(buffers_processed > 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4750 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4751 /* Unqueue only 1 buffer for now.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4752 * If there are more than one,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4753 * let the next Update pass deal with it
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4754 * so we don't stall the program for too long.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4755 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4756 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4757 fprintf(stderr, "About to Unqueue, Buffers processed = %d\n", buffers_processed);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4758 fprintf(stderr, "Buffers queued= %d\n", buffers_still_queued);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4759 fprintf(stderr, "Unqueuing a buffer\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4760 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4761 alSourceUnqueueBuffers(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4762 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4763 1, &unqueued_buffer_id
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4764 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4765 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4766 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4767 fprintf(stderr, "Error with unqueue: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4768 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4769 ALmixer_SetError("Unqueue buffer failed: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4770 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4771 error_flag--;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4772 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4773 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4774 fprintf(stderr, "Right after unqueue...");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4775 PrintQueueStatus(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4776 fprintf(stderr, "Getting more data for NOT_EOF, max_buffers filled\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4777 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4778 /* Grab unqueued packet */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4779 bytes_returned = GetMoreData(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4780 ALmixer_Channel_List[i].almixer_data,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4781 unqueued_buffer_id);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4782 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4783 /* We are still streaming, but currently
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4784 * don't need to fill any buffers */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4785 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4786 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4787 /* Might want to check state */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4788 /* In case the playback stopped,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4789 * we need to resume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4790 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4791 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4792 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4793 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4794 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4795 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4796 fprintf(stderr, "54Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4797 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4798 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4799 if(AL_STOPPED == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4800 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4801 /* Resuming in not eof, but nothing to buffer */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4802 alSourcePlay(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4803 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4804 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4805 fprintf(stderr, "55Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4806 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4807 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4808 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4809 /* Let's escape to the next loop.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4810 * All code below this point is for queuing up
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4811 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4812 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4813 fprintf(stderr, "Entry: Nothing to do...continue\n\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4814 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4815 continue;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4816 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4817 /* We now know we have to fill an available
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4818 * buffer.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4819 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4820
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4821 /* In the previous branch, we just grabbed more data.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4822 * Let's check it to make sure it's okay,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4823 * and then queue it up
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4824 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4825 /* This check doesn't work anymore because it is now Uint32 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4826 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4827 if(-1 == bytes_returned)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4828 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4829 /* Problem occurred...not sure what to do */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4830 /* Go to next loop? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4831 error_flag--;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4832 /* Set the eof flag to force a quit so
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4833 * we don't get stuck in an infinite loop
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4834 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4835 ALmixer_Channel_List[i].almixer_data->eof = 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4836 continue;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4837 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4838 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4839 /* This is a special case where we've run
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4840 * out of data. We should check for loops
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4841 * and get more data. If there is no loop,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4842 * then do nothing and wait for future
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4843 * update passes to handle the EOF.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4844 * The advantage of handling the loop here
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4845 * instead of waiting for play to stop is
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4846 * that we should be able to keep the buffer
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4847 * filled.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4848 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4849 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4850 else if(0 == bytes_returned)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4851 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4852 if(0 == bytes_returned)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4853 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4854 fprintf(stderr, "We got 0 bytes from reading. Checking for loops\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4855 /* Check for loops */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4856 if( ALmixer_Channel_List[i].loops != 0 )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4857 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4858 /* We have to loop, so rewind
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4859 * and fetch more data
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4860 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4861 fprintf(stderr, "Rewinding data\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4862 if(0 == Sound_Rewind(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4863 ALmixer_Channel_List[i].almixer_data->sample))
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4864 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4865 fprintf(stderr, "Rewinding failed\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4866 ALmixer_SetError( Sound_GetError() );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4867 ALmixer_Channel_List[i].loops = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4868 error_flag--;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4869 /* We'll continue on because we do have some valid data */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4870 continue;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4871 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4872 /* Remember to reset the data->eof flag */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4873 ALmixer_Channel_List[i].almixer_data->eof = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4874 if(ALmixer_Channel_List[i].loops > 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4875 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4876 ALmixer_Channel_List[i].loops--;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4877 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4878 /* Try grabbing another packet now.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4879 * Since we may have already unqueued a
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4880 * buffer, we don't want to lose it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4881 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4882 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4883 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4884 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4885 fprintf(stderr, "We got %d bytes from reading loop. Filling unused packet\n", bytes_returned);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4886 /* Grab next packet */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4887 bytes_returned = GetMoreData(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4888 ALmixer_Channel_List[i].almixer_data,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4889 ALmixer_Channel_List[i].almixer_data->buffer[
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4890 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use]
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4891 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4892 fprintf(stderr, "We reread %d bytes into unused packet\n", bytes_returned);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4893 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4894 /* Refilling unqueued packet */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4895 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4896 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4897 fprintf(stderr, "We got %d bytes from reading loop. Filling unqueued packet\n", bytes_returned);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4898 /* Grab next packet */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4899 bytes_returned = GetMoreData(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4900 ALmixer_Channel_List[i].almixer_data,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4901 unqueued_buffer_id);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4902 fprintf(stderr, "We reread %d bytes into unqueued packet\n", bytes_returned);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4903 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4904 /* Another error check */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4905 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4906 if(bytes_returned <= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4907 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4908 if(0 == bytes_returned)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4909 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4910 fprintf(stderr, "??????????ERROR\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4911 ALmixer_SetError("Could not loop because after rewind, no data could be retrieved");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4912 /* Problem occurred...not sure what to do */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4913 /* Go to next loop? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4914 error_flag--;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4915 /* Set the eof flag to force a quit so
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4916 * we don't get stuck in an infinite loop
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4917 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4918 ALmixer_Channel_List[i].almixer_data->eof = 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4919 continue;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4920 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4921 /* We made it to the end. We still need
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4922 * to BufferData, so let this branch
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4923 * fall into the next piece of
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4924 * code below which will handle that
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4925 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4926
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4927
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4928 } /* END loop check */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4929 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4930 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4931 /* No more loops to do.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4932 * EOF flag should be set.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4933 * Just go to next loop and
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4934 * let things be handled correctly
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4935 * in future update calls
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4936 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4937 fprintf(stderr, "SHOULD BE EOF\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4938
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4939 PrintQueueStatus(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4940
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4941 continue;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4942 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4943 } /* END if bytes_returned == 0 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4944 /********* Possible trouble point. I might be queueing empty buffers on the mac.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4945 * This check doesn't say if the buffer is valid. Only the EOF assumption is a clue at this point
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4946 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4947 /* Fall here */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4948 /* Everything is normal. We aren't
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4949 * at an EOF, but need to simply
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4950 * queue more data. The data is already checked for good,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4951 * so queue it up */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4952 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4953 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4954 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4955 /* Keep count of how many buffers we have
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4956 * to queue so we can return the value
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4957 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4958 retval++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4959 fprintf(stderr, "NOT_EOF???, about to Queue more data for num_buffers (%d) < max_queue (%d)\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4960 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4961 ALmixer_Channel_List[i].almixer_data->max_queue_buffers);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4962
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4963 alSourceQueueBuffers(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4964 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4965 1,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4966 &ALmixer_Channel_List[i].almixer_data->buffer[
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4967 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use]
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4968 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4969 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4970 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4971 fprintf(stderr, "56Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4972 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4973 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4974 /* This is part of the hideous Nvidia workaround. In order to figure out
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4975 * which buffer to show during callbacks (for things like
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4976 * o-scopes), I must keep a copy of the buffers that are queued in my own
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4977 * data structure. This code will be called only if
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4978 * "access_data" was set, indicated by whether the queue is NULL.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4979 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4980 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4981 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4982 Uint32 queue_ret_flag;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4983 queue_ret_flag = CircularQueueUnsignedInt_PushBack(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4984 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4985 ALmixer_Channel_List[i].almixer_data->buffer[ALmixer_Channel_List[i].almixer_data->num_buffers_in_use]
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4986 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4987 if(0 == queue_ret_flag)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4988 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4989 fprintf(stderr, "56aSerious internal error: CircularQueue could not push into queue.\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4990 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4991 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4992 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4993 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4994 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4995 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4996 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4997 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4998 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
4999 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5000 /* for processed > 0 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5001 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5002 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5003 /* Keep count of how many buffers we have
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5004 * to queue so we can return the value
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5005 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5006 retval++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5007 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5008 fprintf(stderr, "NOT_EOF, about to Queue more data for filled max_queue (%d)\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5009 ALmixer_Channel_List[i].almixer_data->max_queue_buffers);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5010 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5011 alSourceQueueBuffers(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5012 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5013 1, &unqueued_buffer_id);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5014 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5015 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5016 ALmixer_SetError("Could not QueueBuffer: %s",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5017 aluGetErrorString(error) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5018 error_flag--;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5019 continue;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5020 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5021 /* This is part of the hideous Nvidia workaround. In order to figure out
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5022 * which buffer to show during callbacks (for things like
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5023 * o-scopes), I must keep a copy of the buffers that are queued in my own
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5024 * data structure. This code will be called only if
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5025 * "access_data" was set, indicated by whether the queue is NULL.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5026 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5027 if(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue != NULL)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5028 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5029 Uint32 queue_ret_flag;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5030 queue_ret_flag = CircularQueueUnsignedInt_PushBack(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5031 ALmixer_Channel_List[i].almixer_data->circular_buffer_queue,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5032 unqueued_buffer_id
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5033 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5034 if(0 == queue_ret_flag)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5035 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5036 fprintf(stderr, "56bSerious internal error: CircularQueue could not push into queue.\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5037 ALmixer_SetError("Serious internal error: CircularQueue failed to push into queue");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5038 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5039 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5040 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5041 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5042 CircularQueueUnsignedInt_Print(ALmixer_Channel_List[i].almixer_data->circular_buffer_queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5043 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5044 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5045 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5046 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5047 /* If we used an available buffer queue,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5048 * then we need to update the number of them in use
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5049 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5050 if(ALmixer_Channel_List[i].almixer_data->num_buffers_in_use
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5051 < ALmixer_Channel_List[i].almixer_data->max_queue_buffers)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5052 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5053 /* Increment the number of buffers in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5054 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use++;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5055 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5056 /* Might want to check state */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5057 /* In case the playback stopped,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5058 * we need to resume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5059 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5060 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5061 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5062 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5063 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5064 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5065 fprintf(stderr, "57Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5066 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5067 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5068 if(AL_STOPPED == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5069 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5070 fprintf(stderr, "Resuming in not eof\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5071 alSourcePlay(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5072 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5073 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5074 fprintf(stderr, "58Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5075 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5076 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5077 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5078 continue;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5079 } /* END if( ! eof) */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5080 /* We have hit EOF in the SDL_Sound sample and there
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5081 * are no more loops. However, there may still be
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5082 * buffers in the OpenAL queue which still need to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5083 * be played out. The following body of code will
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5084 * determine if play is still happening or
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5085 * initiate the stop/cleanup sequenece.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5086 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5087 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5088 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5089 /* Let's continue to remove the used up
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5090 * buffers as they come in. */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5091 if(buffers_processed > 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5092 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5093 Sint32 temp_count;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5094 /* Do as a for-loop because I don't want
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5095 * to have to create an array for the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5096 * unqueued_buffer_id's
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5097 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5098 for(temp_count=0; temp_count<buffers_processed; temp_count++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5099 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5100 fprintf(stderr, "unqueuing remainder, %d\n", temp_count);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5101 alSourceUnqueueBuffers(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5102 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5103 1, &unqueued_buffer_id
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5104 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5105 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5106 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5107 fprintf(stderr, "59Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5108 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5109 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5110 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5111 fprintf(stderr, "done unqueuing remainder for this loop, %d\n", temp_count);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5112
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5113 /* Need to update counts since we removed everything.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5114 * If we don't update the counts here, we end up in the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5115 * "Shouldn't be here section, but maybe it's okay due to race conditions"
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5116 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5117 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5118 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5119 AL_BUFFERS_QUEUED, &buffers_still_queued
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5120 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5121 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5122 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5123 fprintf(stderr, "5100Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5124 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5125 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5126 /* Get the number of buffers processed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5127 * so we know if we need to refill
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5128 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5129 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5130 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5131 AL_BUFFERS_PROCESSED, &buffers_processed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5132 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5133 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5134 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5135 fprintf(stderr, "5200Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5136 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5137 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5138 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5139
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5140
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5141 /* Else if buffers_processed == 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5142 * and buffers_still_queued == 0.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5143 * then we check to see if the source
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5144 * is still playing. Quit if stopped
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5145 * We shouldn't need to worry about
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5146 * looping because that should have
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5147 * been handled above.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5148 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5149 if(0 == buffers_still_queued)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5150 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5151 /* Make sure playback has stopped before
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5152 * we shutdown.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5153 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5154 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5155 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5156 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5157 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5158 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5159 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5160 fprintf(stderr, "60Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5161 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5162 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5163 if(AL_STOPPED == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5164 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5165 ALmixer_Channel_List[i].almixer_data->num_buffers_in_use = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5166 /* Playback has ended.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5167 * Loop if necessary, or launch callback
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5168 * and clear channel (or clear channel and
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5169 * then launch callback?)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5170 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5171 Clean_Channel(i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5172 /* Subtract counter */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5173 Is_Playing_global--;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5174
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5175 /* Launch callback */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5176 Invoke_Channel_Done_Callback(i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5177
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5178 /* We're done for this loop.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5179 * Go to next channel
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5180 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5181 continue;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5182 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5183 } /* End end-playback */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5184 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5185 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5186 /* Need to run out buffer */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5187 #if 1
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5188 /* Might want to check state */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5189 /* In case the playback stopped,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5190 * we need to resume */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5191 alGetSourcei(
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5192 ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5193 AL_SOURCE_STATE, &state
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5194 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5195 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5196 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5197 fprintf(stderr, "61Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5198 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5199 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5200 if(AL_STOPPED == state)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5201 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5202 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);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5203
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5204 PrintQueueStatus(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5205
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5206 /* Rather than force unqueuing the buffer, let's see if
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5207 * setting the buffer to none works (the OpenAL 1.0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5208 * Reference Annotation suggests this should work).
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5209 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5210 alSourcei(ALmixer_Channel_List[i].alsource,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5211 AL_BUFFER, AL_NONE);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5212 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5213 PrintQueueStatus(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5214 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5215 /* This doesn't work because in some cases, I think
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5216 * it causes the sound to be replayed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5217 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5218 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5219 fprintf(stderr, "Resuming in eof (trying to run out buffers\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5220 alSourcePlay(ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5221 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5222 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5223 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5224 } /* End trap section */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5225 } /* End POST-EOF use-up buffer section */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5226 } /* END Streamed section */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5227 } /* END channel in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5228 } /* END for-loop for each channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5229
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5230 #ifdef ENABLE_ALMIXER_ALC_SYNC
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5231 alcProcessContext(alcGetCurrentContext());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5232 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5233 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5234 fprintf(stderr, "62Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5235 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5236 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5237 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5238
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5239 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5240 /* Return the number of errors */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5241 if(error_flag < 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5242 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5243 return error_flag;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5244 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5245 /* Return the number of buffers that were queued */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5246 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5247 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5248
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5249 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5250 /* This is only here so we can call SDL_OpenAudio() */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5251 static void my_dummy_audio_callback(void* userdata, Uint8* stream, int len)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5252 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5253 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5254 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5255
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5256
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5257
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5258
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5259 #ifdef ENABLE_ALMIXER_THREADS
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5260 /* We might need threads. We
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5261 * must constantly poll OpenAL to find out
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5262 * if sound is being streamed, if play has
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5263 * ended, etc. Without threads, this must
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5264 * be explicitly done by the user.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5265 * We could try to do it for them if we
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5266 * finish the threads.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5267 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5268
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5269 static int Stream_Data_Thread_Callback(void* data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5270 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5271 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5272
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5273 while(ALmixer_Initialized)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5274 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5275 retval = Update_ALmixer(data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5276 /* 0 means that nothing needed updating and
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5277 * the function returned quickly
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5278 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5279 if(0 == retval)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5280 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5281 /* Let's be nice and make the thread sleep since
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5282 * little work was done in update
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5283 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5284 /* Make sure times are multiples of 10
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5285 * for optimal performance and accuracy in Linux
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5286 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5287 SDL_Delay(10);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5288 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5289 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5290 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5291 /* should I also be sleeping/yielding here? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5292 SDL_Delay(0);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5293 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5294 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5295 fprintf(stderr, "Thread is closing\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5296 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5297 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5298 #endif /* End of ENABLE_ALMIXER_THREADS */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5299
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5300
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5301 /* Using -1 on error and 0 on success to follow SDL/SDL_mixer conventions,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5302 * though I actually prefer 0/1 conventions (SDL_Sound/OpenAL/GL).
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5303 * Warning: SDL_QuitSubSystem(SDL_INIT_AUDIO) is called which
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5304 * means the SDL audio system will be disabled. It will not
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5305 * be restored (in case SDL is not actually being used) so
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5306 * the user will need to restart it if they need it after
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5307 * OpenAL shuts down.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5308 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5309 Sint32 ALmixer_Init(Uint32 frequency, Sint32 num_sources, Uint32 refresh)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5310 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5311 ALCdevice* dev;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5312 ALCcontext* context;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5313 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5314 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5315 ALuint* source;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5316
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5317 #ifdef USING_LOKI_AL_DIST
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5318 /* The Loki dist requires that I set both the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5319 * device and context frequency values separately
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5320 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5321 /* Hope this won't overflow */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5322 char device_string[256];
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5323 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5324
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5325 /* (Venting frustration) Damn it! Nobody bothered
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5326 * documenting how you're supposed to use an attribute
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5327 * list. In fact, the not even the Loki test program
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5328 * writers seem to know because they use it inconsistently.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5329 * For example, how do you terminate that attribute list?
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5330 * The Loki test code does it 3 different ways. They
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5331 * set the last value to 0, or they set it to ALC_INVALID,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5332 * or they set two final values: ALC_INVALID, 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5333 * In Loki, 0 and ALC_INVALID happen to be the same,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5334 * but with Creative Labs ALC_INVALID is -1.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5335 * So something's going to break. Loki's source
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5336 * code says to terminate with ALC_INVALID. But I
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5337 * don't know if that's really true, or it happens
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5338 * to be a coinicidence because it's defined to 0.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5339 * Creative provides no source code, so I can't look at how
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5340 * they terminate it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5341 * So this is really, really ticking me off...
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5342 * For now, I'm going to use ALC_INVALID.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5343 * (Update...after further review of the API spec,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5344 * it seems that a NULL terminated string is the correct
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5345 * termination value to use, so 0 it is.)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5346 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5347 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5348 ALint attrlist[] = {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5349 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5350 /* Don't know anything about these values.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5351 * Trust defaults? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5352 /* Supposed to be the refresh rate in Hz.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5353 * I think 15-120 are supposed to be good
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5354 * values. Though I haven't gotten any effect except
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5355 * for one strange instance on a Mac. But it was
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5356 * unrepeatable.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5357 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5358 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5359 ALC_REFRESH, 15,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5360 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5361 /* Sync requires a alcProcessContext() call
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5362 * for every cycle. By default, this is
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5363 * not used and the value is AL_FALSE
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5364 * because it will probably perform
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5365 * pretty badly for me.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5366 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5367 #ifdef ENABLE_ALMIXER_ALC_SYNC
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5368 ALC_SYNC, AL_TRUE,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5369 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5370 ALC_SYNC, AL_FALSE,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5371 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5372 /* Looking at the API spec, it implies
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5373 * that the list be a NULL terminated string
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5374 * so it's probably not safe to use ALC_INVALID
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5375 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5376 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5377 ALC_INVALID };
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5378 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5379 '\0'};
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5380 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5381 /* Redo: I'm going to allow ALC_REFRESH to be set.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5382 * However, if no value is specified, I don't
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5383 * want it in the list so I can get the OpenAL defaults
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5384 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5385 ALint attrlist[7];
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5386
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5387 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5388 /* More problems: I'm getting bit by endian/signedness issues on
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5389 * different platforms. I can find the endianess easily enough,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5390 * but I don't know how to determine what the correct signedness
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5391 * is (if such a thing exists). I do know that if I try using
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5392 * unsigned on OSX with an originally signed sample, I get
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5393 * distortion. However, I don't have any native unsigned samples
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5394 * to test. But I'm assuming that the platform must be in the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5395 * correct signedness no matter what.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5396 * I can either assume everybody is signed, or I can try to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5397 * determine the value. If I try to determine the values,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5398 * I think my only ability to figure it out will be to open
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5399 * SDL_Audio, and read what the obtained settings were.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5400 * Then shutdown everything. However, I don't even know how
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5401 * reliable this is.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5402 * Update: I think I resolved the issues...forgot to update
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5403 * these comments when it happened. I should check the revision control
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5404 * log... Anyway, I think the issue was partly related to me not
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5405 * doing something correctly with the AudioInfo or some kind
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5406 * of stupid endian bug in my code, and weirdness ensued. Looking at the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5407 * revision control, I think I might have assumed that SDL_Sound would
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5408 * do the right thing with a NULL AudioInfo, but I was incorrect,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5409 * and had to fill one out myself.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5410 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5411 SDL_AudioSpec desired;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5412 SDL_AudioSpec obtained;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5413 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5414
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5415
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5416
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5417
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5418 /* Make sure ALmixer isn't already initialized */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5419 if(ALmixer_Initialized)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5420 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5421 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5422 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5423 #ifdef USING_LOKI_AL_DIST
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5424 fprintf(stderr, "Found Loki dist\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5425 #elif defined(USING_CREATIVE_AL_DIST)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5426 fprintf(stderr, "Found Creative dist\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5427
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5428 #elif defined(USING_NVIDIA_AL_DIST)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5429 fprintf(stderr, "Found Nvidia dist\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5430 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5431
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5432 /* Set the defaults */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5433 attrlist[0] = ALC_FREQUENCY;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5434 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5435 attrlist[2] = ALC_SYNC;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5436 #ifdef ENABLE_ALMIXER_ALC_SYNC
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5437 attrlist[3] = ALC_TRUE;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5438 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5439 attrlist[3] = ALC_FALSE;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5440 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5441
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5442 /* Set frequency value if it is not 0 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5443 if(0 != frequency)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5444 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5445 attrlist[1] = (ALint)frequency;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5446 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5447
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5448 /* If the user specifies a refresh value,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5449 * make room for it
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5450 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5451 if(0 != refresh)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5452 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5453 attrlist[4] = (ALint)ALC_REFRESH;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5454 attrlist[5] = refresh;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5455 attrlist[6] = '\0';
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5456 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5457 /* Terminate the list without any refresh values */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5458 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5459 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5460 attrlist[4] = '\0';
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5461 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5462
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5463 /* It looks like OpenAL won't let us ask it what
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5464 * the set frequency is, so we need to save our
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5465 * own copy. Yuck.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5466 * Update: J. Valenzuela just updated the Loki
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5467 * dist (2003/01/02) to handle this.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5468 * The demo is in testattrib.c. However, this
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5469 * looks kind of cumbersome to parse, and I've
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5470 * already put this in my code, so I guess I'll
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5471 * leave it for now.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5472 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5473 ALmixer_Frequency_global = attrlist[1];
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5474
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5475 /* Initialize SDL_Sound */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5476 if(! Sound_Init() )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5477 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5478 ALmixer_SetError(Sound_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5479 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5480 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5481 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5482 /* Here is the paranoid check that opens
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5483 * SDL audio in an attempt to find the correct
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5484 * system values.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5485 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5486 /* Doesn't have to be the actual value I think
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5487 * (as long as it doesn't influence format, in
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5488 * which case I'm probably screwed anyway because OpenAL
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5489 * may easily choose to do something else).
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5490 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5491 desired.freq = 44100;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5492 desired.channels = 2;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5493 desired.format = AUDIO_S16SYS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5494 desired.callback = my_dummy_audio_callback;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5495 if(SDL_OpenAudio(&desired, &obtained) >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5496 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5497 SIGN_TYPE_16BIT_FORMAT = obtained.format;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5498 /* Now to get really paranoid, we should probably
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5499 * also assume that the 8bit format is also the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5500 * same sign type and set that value
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5501 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5502 if(AUDIO_S16SYS == obtained.format)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5503 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5504 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5505 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5506 /* Should be AUDIO_U16SYS */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5507 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5508 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5509 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5510 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5511 SDL_CloseAudio();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5512 fprintf(stderr, "Obtained format = %d", obtained.format);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5513 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5514 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5515 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5516 /* Well, I guess I'm in trouble. I guess it's my best guess
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5517 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5518 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5519 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5520 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5521 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5522 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5523 * causes OpenAL and SMPEG to conflict. For some reason
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5524 * if SDL_Init on audio is active, then all the SMPEG
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5525 * decoded sound comes out silent. Unfortunately,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5526 * Sound_Init() invokes SDL_Init on audio. I'm
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5527 * not sure why it actually needs it...
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5528 * But we'll attempt to disable it here after the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5529 * SDL_Sound::Init call and hope it doesn't break SDL_Sound.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5530 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5531 SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5532
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5533 /* I'm told NULL will call the default string
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5534 * and hopefully do the right thing for each platform
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5535 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5536 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5537 dev = alcOpenDevice( NULL );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5538 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5539 /* Now I'm told I need to set both the device and context
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5540 * to have the same sampling rate, so I must pass a string
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5541 * to OpenDevice(). I don't know how portable these strings are.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5542 * I don't even know if the format for strings is
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5543 * compatible
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5544 * From the testattrib.c in the Loki test section
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5545 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5546 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5547
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5548 #ifdef USING_LOKI_AL_DIST
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5549 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5550 dev = alcOpenDevice( (const ALubyte *) device_string );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5551 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5552 dev = alcOpenDevice( NULL );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5553 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5554 fprintf(stderr,"sampling-rate is %d\n", attrlist[1]);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5555 if(NULL == dev)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5556 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5557 ALmixer_SetError("Cannot open sound device for OpenAL");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5558 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5559 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5560
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5561 context = alcCreateContext(dev, attrlist);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5562 if(NULL == context)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5563 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5564 ALmixer_SetError("Cannot create a context OpenAL");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5565 alcCloseDevice(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5566 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5567 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5568 fprintf(stderr, "Context checking...\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5569
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5570
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5571 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5572 * but ALC_NO_ERROR is defined to ALC_FALSE.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5573 * According to Garin Hiebert, this is actually an inconsistency
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5574 * in the Loki version. The function should return a boolean.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5575 * instead of ALC_NO_ERROR. Garin suggested I check via
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5576 * alcGetError().
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5577 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5578 /* clear the error */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5579 alcGetError(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5580 alcMakeContextCurrent(context);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5581
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5582 error = alcGetError(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5583 if( (ALC_NO_ERROR != error) )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5584 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5585 ALmixer_SetError("Could not MakeContextCurrent");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5586 alcDestroyContext(context);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5587 alcCloseDevice(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5588 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5589 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5590
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5591
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5592 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5593 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5594 if(alcGetCurrentContext() != context)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5595 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5596 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5597 * but ALC_NO_ERROR is defined to ALC_FALSE.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5598 * I think this is a bug in the OpenAL implementation.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5599 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5600 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5601
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5602 fprintf(stderr, "Making context current\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5603 #ifndef __APPLE__
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5604 if(alcMakeContextCurrent(context) != ALC_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5605 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5606 if(!alcMakeContextCurrent(context))
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5607 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5608 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5609 ALmixer_SetError("Could not MakeContextCurrent");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5610 alcDestroyContext(context);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5611 alcCloseDevice(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5612 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5613 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5614 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5615 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5616
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5617
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5618 /* #endif */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5619 fprintf(stderr, "done Context\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5620 /* Saw this in the README with the OS X OpenAL distribution.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5621 * It looked interesting and simple, so I thought I might
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5622 * try it out.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5623 * ***** ALC_CONVERT_DATA_UPON_LOADING
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5624 * This extension allows the caller to tell OpenAL to preconvert to the native Core
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5625 * Audio format, the audio data passed to the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5626 * library with the alBufferData() call. Preconverting the audio data, reduces CPU
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5627 * usage by removing an audio data conversion
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5628 * (per source) at render timem at the expense of a larger memory footprint.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5629 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5630 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5631 * setting will be applied to all subsequent
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5632 * calls to alBufferData().
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5633 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5634 #ifdef __APPLE__
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5635 alEnable(ALC_CONVERT_DATA_UPON_LOADING);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5636 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5637
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5638
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5639
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5640
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5641 ALmixer_Initialized = 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5642
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5643 if(num_sources <= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5644 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5645 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5646 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5647 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5648 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5649 Number_of_Channels_global = num_sources;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5650 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5651 Number_of_Reserve_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5652 Is_Playing_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5653 /* Set to Null in case system quit and was reinitialized */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5654 Channel_Done_Callback = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5655 Channel_Done_Callback_Userdata = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5656 Channel_Data_Callback = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5657
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5658 /* Allocate memory for the list of channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5659 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5660 if(NULL == ALmixer_Channel_List)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5661 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5662 ALmixer_SetError("Out of Memory for Channel List");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5663 alcDestroyContext(context);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5664 alcCloseDevice(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5665 ALmixer_Initialized = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5666 Number_of_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5667 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5668 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5669
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5670 /* Allocate memory for the list of sources that map to the channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5671 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5672 if(NULL == Source_Map_List)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5673 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5674 ALmixer_SetError("Out of Memory for Source Map List");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5675 free(ALmixer_Channel_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5676 alcDestroyContext(context);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5677 alcCloseDevice(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5678 ALmixer_Initialized = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5679 Number_of_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5680 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5681 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5682
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5683 /* Create array that will hold the sources */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5684 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5685 if(NULL == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5686 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5687 ALmixer_SetError("Out of Memory for sources");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5688 free(Source_Map_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5689 free(ALmixer_Channel_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5690 alcDestroyContext(context);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5691 alcCloseDevice(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5692 ALmixer_Initialized = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5693 Number_of_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5694 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5695 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5696
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5697 /* Clear the error state */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5698 alGetError();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5699 /* Generate the OpenAL sources */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5700 alGenSources(Number_of_Channels_global, source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5701 if( (error=alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5702 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5703 ALmixer_SetError("Couldn't generate sources: %s\n", aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5704 free(ALmixer_Channel_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5705 free(Source_Map_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5706 alcDestroyContext(context);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5707 alcCloseDevice(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5708 ALmixer_Initialized = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5709 Number_of_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5710 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5711 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5712
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5713 /* Initialize each channel and associate one source to one channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5714 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5715 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5716 if(0 == source[i])
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5717 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5718 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");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5719 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5720
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5721 Init_Channel(i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5722 /* Keeping the source allocation out of the Init function
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5723 * in case I want to reuse the Init
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5724 * function for resetting data
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5725 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5726 ALmixer_Channel_List[i].alsource = source[i];
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5727 /* Now also keep a copy of the source to channel mapping
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5728 * in case we need to look up a channel from the source
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5729 * instead of a source from a channel
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5730 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5731 Source_Map_List[i].source = source[i];
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5732 Source_Map_List[i].channel = i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5733 /* Clean the channel because there are some things that need to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5734 * be done that can't happen until the source is set
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5735 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5736 Clean_Channel(i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5737 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5738
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5739 /* The Source_Map_List must be sorted by source for binary searches
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5740 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5741 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5742
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5743 fprintf(stderr, "Sorted Source_Map_List is:\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5744 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5745 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5746 fprintf(stderr, "Source: %d, Channel: %d\n", Source_Map_List[i].source, Source_Map_List[i].channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5747 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5748 fprintf(stderr, "\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5749
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5750 simple_lock = SDL_CreateMutex();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5751 if(NULL == simple_lock)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5752 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5753 /* SDL sets the error message already? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5754 free(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5755 free(ALmixer_Channel_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5756 free(Source_Map_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5757 alcDestroyContext(context);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5758 alcCloseDevice(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5759 ALmixer_Initialized = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5760 Number_of_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5761 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5762 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5763
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5764
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5765 #ifdef ENABLE_ALMIXER_THREADS
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5766 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5767 if(NULL == Stream_Thread_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5768 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5769 /* SDL sets the error message already? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5770 SDL_DestroyMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5771 free(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5772 free(ALmixer_Channel_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5773 free(Source_Map_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5774 alcDestroyContext(context);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5775 alcCloseDevice(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5776 ALmixer_Initialized = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5777 Number_of_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5778 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5779 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5780
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5781 fprintf(stderr, "Using threads\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5782 #endif /* End of ENABLE_ALMIXER_THREADS */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5783
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5784 /* We don't need this array any more because all the sources
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5785 * are connected to channels
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5786 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5787 free(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5788 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5789 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5790
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5791
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5792 Sint32 ALmixer_Init_Context(Uint32 frequency, Uint32 refresh)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5793 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5794 ALCdevice* dev;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5795 ALCcontext* context;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5796 ALCenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5797
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5798 #ifdef USING_LOKI_AL_DIST
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5799 /* The Loki dist requires that I set both the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5800 * device and context frequency values separately
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5801 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5802 /* Hope this won't overflow */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5803 char device_string[256];
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5804 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5805
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5806 /* (Venting frustration) Damn it! Nobody bothered
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5807 * documenting how you're supposed to use an attribute
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5808 * list. In fact, the not even the Loki test program
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5809 * writers seem to know because they use it inconsistently.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5810 * For example, how do you terminate that attribute list?
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5811 * The Loki test code does it 3 different ways. They
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5812 * set the last value to 0, or they set it to ALC_INVALID,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5813 * or they set two final values: ALC_INVALID, 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5814 * In Loki, 0 and ALC_INVALID happen to be the same,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5815 * but with Creative Labs ALC_INVALID is -1.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5816 * So something's going to break. Loki's source
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5817 * code says to terminate with ALC_INVALID. But I
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5818 * don't know if that's really true, or it happens
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5819 * to be a coinicidence because it's defined to 0.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5820 * Creative provides no source code, so I can't look at how
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5821 * they terminate it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5822 * So this is really, really ticking me off...
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5823 * For now, I'm going to use ALC_INVALID.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5824 * (Update...after further review of the API spec,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5825 * it seems that a NULL terminated string is the correct
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5826 * termination value to use, so 0 it is.)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5827 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5828 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5829 ALint attrlist[] = {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5830 ALC_FREQUENCY, ALMIXER_DEFAULT_FREQUENCY,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5831 /* Don't know anything about these values.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5832 * Trust defaults? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5833 /* Supposed to be the refresh rate in Hz.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5834 * I think 15-120 are supposed to be good
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5835 * values. Though I haven't gotten any effect except
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5836 * for one strange instance on a Mac. But it was
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5837 * unrepeatable.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5838 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5839 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5840 ALC_REFRESH, 15,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5841 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5842 /* Sync requires a alcProcessContext() call
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5843 * for every cycle. By default, this is
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5844 * not used and the value is AL_FALSE
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5845 * because it will probably perform
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5846 * pretty badly for me.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5847 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5848 #ifdef ENABLE_ALMIXER_ALC_SYNC
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5849 ALC_SYNC, AL_TRUE,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5850 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5851 ALC_SYNC, AL_FALSE,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5852 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5853 /* Looking at the API spec, it implies
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5854 * that the list be a NULL terminated string
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5855 * so it's probably not safe to use ALC_INVALID
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5856 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5857 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5858 ALC_INVALID };
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5859 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5860 '\0'};
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5861 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5862 /* Redo: I'm going to allow ALC_REFRESH to be set.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5863 * However, if no value is specified, I don't
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5864 * want it in the list so I can get the OpenAL defaults
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5865 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5866 ALint attrlist[7];
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5867
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5868 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5869 /* More problems: I'm getting bit by endian/signedness issues on
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5870 * different platforms. I can find the endianess easily enough,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5871 * but I don't know how to determine what the correct signedness
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5872 * is (if such a thing exists). I do know that if I try using
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5873 * unsigned on OSX with an originally signed sample, I get
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5874 * distortion. However, I don't have any native unsigned samples
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5875 * to test. But I'm assuming that the platform must be in the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5876 * correct signedness no matter what.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5877 * I can either assume everybody is signed, or I can try to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5878 * determine the value. If I try to determine the values,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5879 * I think my only ability to figure it out will be to open
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5880 * SDL_Audio, and read what the obtained settings were.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5881 * Then shutdown everything. However, I don't even know how
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5882 * reliable this is.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5883 * Update: I think I resolved the issues...forgot to update
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5884 * these comments when it happened. I should check the revision control
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5885 * log... Anyway, I think the issue was partly related to me not
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5886 * doing something correctly with the AudioInfo or some kind
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5887 * of stupid endian bug in my code, and weirdness ensued. Looking at the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5888 * revision control, I think I might have assumed that SDL_Sound would
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5889 * do the right thing with a NULL AudioInfo, but I was incorrect,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5890 * and had to fill one out myself.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5891 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5892 SDL_AudioSpec desired;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5893 SDL_AudioSpec obtained;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5894 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5895
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5896
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5897
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5898
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5899 /* Make sure ALmixer isn't already initialized */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5900 if(ALmixer_Initialized)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5901 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5902 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5903 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5904 #ifdef USING_LOKI_AL_DIST
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5905 fprintf(stderr, "Found Loki dist\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5906 #elif defined(USING_CREATIVE_AL_DIST)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5907 fprintf(stderr, "Found Creative dist\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5908
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5909 #elif defined(USING_NVIDIA_AL_DIST)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5910 fprintf(stderr, "Found Nvidia dist\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5911 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5912
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5913 /* Set the defaults */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5914 attrlist[0] = ALC_FREQUENCY;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5915 attrlist[1] = ALMIXER_DEFAULT_FREQUENCY;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5916 attrlist[2] = ALC_SYNC;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5917 #ifdef ENABLE_ALMIXER_ALC_SYNC
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5918 attrlist[3] = ALC_TRUE;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5919 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5920 attrlist[3] = ALC_FALSE;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5921 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5922
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5923 /* Set frequency value if it is not 0 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5924 if(0 != frequency)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5925 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5926 attrlist[1] = (ALint)frequency;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5927 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5928
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5929 /* If the user specifies a refresh value,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5930 * make room for it
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5931 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5932 if(0 != refresh)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5933 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5934 attrlist[4] = (ALint)ALC_REFRESH;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5935 attrlist[5] = refresh;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5936 attrlist[6] = '\0';
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5937 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5938 /* Terminate the list without any refresh values */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5939 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5940 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5941 attrlist[4] = '\0';
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5942 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5943
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5944 /* It looks like OpenAL won't let us ask it what
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5945 * the set frequency is, so we need to save our
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5946 * own copy. Yuck.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5947 * Update: J. Valenzuela just updated the Loki
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5948 * dist (2003/01/02) to handle this.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5949 * The demo is in testattrib.c. However, this
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5950 * looks kind of cumbersome to parse, and I've
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5951 * already put this in my code, so I guess I'll
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5952 * leave it for now.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5953 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5954 ALmixer_Frequency_global = attrlist[1];
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5955
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5956 /* Initialize SDL_Sound */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5957 if(! Sound_Init() )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5958 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5959 ALmixer_SetError(Sound_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5960 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5961 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5962 #ifdef ENABLE_PARANOID_SIGNEDNESS_CHECK
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5963 /* Here is the paranoid check that opens
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5964 * SDL audio in an attempt to find the correct
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5965 * system values.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5966 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5967 /* Doesn't have to be the actual value I think
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5968 * (as long as it doesn't influence format, in
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5969 * which case I'm probably screwed anyway because OpenAL
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5970 * may easily choose to do something else).
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5971 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5972 desired.freq = 44100;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5973 desired.channels = 2;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5974 desired.format = AUDIO_S16SYS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5975 desired.callback = my_dummy_audio_callback;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5976 if(SDL_OpenAudio(&desired, &obtained) >= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5977 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5978 SIGN_TYPE_16BIT_FORMAT = obtained.format;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5979 /* Now to get really paranoid, we should probably
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5980 * also assume that the 8bit format is also the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5981 * same sign type and set that value
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5982 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5983 if(AUDIO_S16SYS == obtained.format)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5984 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5985 SIGN_TYPE_8BIT_FORMAT = AUDIO_S8;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5986 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5987 /* Should be AUDIO_U16SYS */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5988 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5989 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5990 SIGN_TYPE_8BIT_FORMAT = AUDIO_U8;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5991 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5992 SDL_CloseAudio();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5993 fprintf(stderr, "Obtained format = %d", obtained.format);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5994 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5995 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5996 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5997 /* Well, I guess I'm in trouble. I guess it's my best guess
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5998 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
5999 SIGN_TYPE_16_BIT_FORMAT = AUDIO_S16SYS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6000 SIGN_TYPE_8_BIT_FORMAT = AUDIO_S8;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6001 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6002 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6003 /* Weirdness: It seems that SDL_Init(SDL_INIT_AUDIO)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6004 * causes OpenAL and SMPEG to conflict. For some reason
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6005 * if SDL_Init on audio is active, then all the SMPEG
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6006 * decoded sound comes out silent. Unfortunately,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6007 * Sound_Init() invokes SDL_Init on audio. I'm
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6008 * not sure why it actually needs it...
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6009 * But we'll attempt to disable it here after the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6010 * SDL_Sound::Init call and hope it doesn't break SDL_Sound.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6011 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6012 SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6013
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6014 /* I'm told NULL will call the default string
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6015 * and hopefully do the right thing for each platform
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6016 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6017 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6018 dev = alcOpenDevice( NULL );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6019 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6020 /* Now I'm told I need to set both the device and context
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6021 * to have the same sampling rate, so I must pass a string
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6022 * to OpenDevice(). I don't know how portable these strings are.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6023 * I don't even know if the format for strings is
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6024 * compatible
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6025 * From the testattrib.c in the Loki test section
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6026 * dev = alcOpenDevice( (const ALubyte *) "'((sampling-rate 22050))" );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6027 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6028
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6029 #ifdef USING_LOKI_AL_DIST
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6030 sprintf(device_string, "'((sampling-rate %d))", attrlist[1]);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6031 dev = alcOpenDevice( (const ALubyte *) device_string );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6032 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6033 dev = alcOpenDevice( NULL );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6034 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6035 fprintf(stderr,"sampling-rate is %d\n", attrlist[1]);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6036 if(NULL == dev)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6037 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6038 ALmixer_SetError("Cannot open sound device for OpenAL");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6039 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6040 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6041
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6042 context = alcCreateContext(dev, attrlist);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6043 if(NULL == context)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6044 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6045 ALmixer_SetError("Cannot create a context OpenAL");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6046 alcCloseDevice(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6047 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6048 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6049
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6050
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6051 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6052 * but ALC_NO_ERROR is defined to ALC_FALSE.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6053 * According to Garin Hiebert, this is actually an inconsistency
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6054 * in the Loki version. The function should return a boolean.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6055 * instead of ALC_NO_ERROR. Garin suggested I check via
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6056 * alcGetError().
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6057 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6058 /* clear the error */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6059 alcGetError(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6060 alcMakeContextCurrent(context);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6061
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6062 error = alcGetError(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6063 if( (ALC_NO_ERROR != error) )
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6064 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6065 ALmixer_SetError("Could not MakeContextCurrent");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6066 alcDestroyContext(context);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6067 alcCloseDevice(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6068 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6069 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6070
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6071
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6072 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6073 /* OSX is failing on alcMakeContextCurrent(). Try checking it first? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6074 if(alcGetCurrentContext() != context)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6075 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6076 /* Hmmm, OSX is returning 1 on alcMakeContextCurrent,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6077 * but ALC_NO_ERROR is defined to ALC_FALSE.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6078 * I think this is a bug in the OpenAL implementation.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6079 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6080 fprintf(stderr,"alcMakeContextCurrent returns %d\n", alcMakeContextCurrent(context));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6081
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6082 fprintf(stderr, "Making context current\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6083 #ifndef __APPLE__
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6084 if(alcMakeContextCurrent(context) != ALC_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6085 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6086 if(!alcMakeContextCurrent(context))
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6087 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6088 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6089 ALmixer_SetError("Could not MakeContextCurrent");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6090 alcDestroyContext(context);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6091 alcCloseDevice(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6092 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6093 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6094
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6095 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6096 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6097
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6098 fprintf(stderr, "done Context\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6099
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6100 /* Saw this in the README with the OS X OpenAL distribution.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6101 * It looked interesting and simple, so I thought I might
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6102 * try it out.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6103 * ***** ALC_CONVERT_DATA_UPON_LOADING
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6104 * This extension allows the caller to tell OpenAL to preconvert to the native Core
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6105 * Audio format, the audio data passed to the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6106 * library with the alBufferData() call. Preconverting the audio data, reduces CPU
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6107 * usage by removing an audio data conversion
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6108 * (per source) at render timem at the expense of a larger memory footprint.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6109 *
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6110 * This feature is toggled on/off by using the alDisable() & alEnable() APIs. This
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6111 * setting will be applied to all subsequent
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6112 * calls to alBufferData().
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6113 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6114 #ifdef __APPLE__
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6115 alEnable(ALC_CONVERT_DATA_UPON_LOADING);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6116 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6117
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6118 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6119 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6120
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6121
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6122 Sint32 ALmixer_Init_Mixer(Sint32 num_sources)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6123 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6124 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6125 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6126 ALuint* source;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6127
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6128
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6129 ALmixer_Initialized = 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6130
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6131 if(num_sources <= 0)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6132 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6133 Number_of_Channels_global = ALMIXER_DEFAULT_NUM_CHANNELS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6134 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6135 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6136 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6137 Number_of_Channels_global = num_sources;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6138 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6139 Number_of_Reserve_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6140 Is_Playing_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6141 /* Set to Null in case system quit and was reinitialized */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6142 Channel_Done_Callback = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6143 Channel_Done_Callback_Userdata = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6144 Channel_Data_Callback = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6145
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6146 /* Allocate memory for the list of channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6147 ALmixer_Channel_List = (struct ALmixer_Channel*) malloc(Number_of_Channels_global * sizeof(struct ALmixer_Channel));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6148 if(NULL == ALmixer_Channel_List)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6149 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6150 ALmixer_SetError("Out of Memory for Channel List");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6151 ALmixer_Initialized = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6152 Number_of_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6153 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6154 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6155
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6156 /* Allocate memory for the list of sources that map to the channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6157 Source_Map_List = (Source_Map*) malloc(Number_of_Channels_global * sizeof(Source_Map));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6158 if(NULL == Source_Map_List)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6159 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6160 ALmixer_SetError("Out of Memory for Source Map List");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6161 free(ALmixer_Channel_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6162 ALmixer_Initialized = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6163 Number_of_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6164 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6165 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6166
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6167 /* Create array that will hold the sources */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6168 source = (ALuint*)malloc(Number_of_Channels_global * sizeof(ALuint));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6169 if(NULL == source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6170 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6171 ALmixer_SetError("Out of Memory for sources");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6172 free(Source_Map_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6173 free(ALmixer_Channel_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6174 ALmixer_Initialized = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6175 Number_of_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6176 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6177 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6178
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6179 /* Clear the error state */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6180 alGetError();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6181 /* Generate the OpenAL sources */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6182 alGenSources(Number_of_Channels_global, source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6183 if( (error=alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6184 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6185 ALmixer_SetError("Couldn't generate sources: %s\n", aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6186 free(ALmixer_Channel_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6187 free(Source_Map_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6188 ALmixer_Initialized = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6189 Number_of_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6190 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6191 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6192
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6193 /* Initialize each channel and associate one source to one channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6194 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6195 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6196 Init_Channel(i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6197 /* Keeping the source allocation out of the Init function
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6198 * in case I want to reuse the Init
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6199 * function for resetting data
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6200 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6201 ALmixer_Channel_List[i].alsource = source[i];
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6202 /* Now also keep a copy of the source to channel mapping
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6203 * in case we need to look up a channel from the source
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6204 * instead of a source from a channel
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6205 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6206 Source_Map_List[i].source = source[i];
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6207 Source_Map_List[i].channel = i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6208 /* Clean the channel because there are some things that need to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6209 * be done that can't happen until the source is set
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6210 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6211 Clean_Channel(i);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6212 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6213
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6214 /* The Source_Map_List must be sorted by source for binary searches
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6215 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6216 qsort(Source_Map_List, Number_of_Channels_global, sizeof(Source_Map), Compare_Source_Map);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6217
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6218 fprintf(stderr, "Sorted Source_Map_List is:\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6219 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6220 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6221 fprintf(stderr, "Source: %d, Channel: %d\n", Source_Map_List[i].source, Source_Map_List[i].channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6222 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6223 fprintf(stderr, "\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6224
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6225 simple_lock = SDL_CreateMutex();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6226 if(NULL == simple_lock)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6227 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6228 /* SDL sets the error message already? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6229 free(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6230 free(ALmixer_Channel_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6231 free(Source_Map_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6232 ALmixer_Initialized = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6233 Number_of_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6234 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6235 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6236
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6237
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6238 #ifdef ENABLE_ALMIXER_THREADS
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6239 Stream_Thread_global = SDL_CreateThread(Stream_Data_Thread_Callback, NULL);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6240 if(NULL == Stream_Thread_global)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6241 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6242 /* SDL sets the error message already? */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6243 SDL_DestroyMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6244 free(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6245 free(ALmixer_Channel_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6246 free(Source_Map_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6247 ALmixer_Initialized = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6248 Number_of_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6249 return -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6250 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6251
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6252 fprintf(stderr, "Using threads\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6253 #endif /* End of ENABLE_ALMIXER_THREADS */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6254
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6255 /* We don't need this array any more because all the sources
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6256 * are connected to channels
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6257 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6258 free(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6259 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6260 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6261
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6262
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6263
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6264 /* Keep the return value void to allow easy use with
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6265 * atexit()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6266 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6267 void ALmixer_Quit()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6268 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6269 ALCcontext* context;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6270 ALCdevice* dev;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6271 Sint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6272
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6273 if( ! ALmixer_Initialized)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6274 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6275 return;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6276 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6277
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6278 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6279
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6280 /* Shutdown everything before closing context */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6281 fprintf(stderr, "Halting channels\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6282 Internal_HaltChannel(-1);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6283
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6284 /* This flag will cause the thread to terminate */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6285 ALmixer_Initialized = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6286 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6287 #ifdef ENABLE_ALMIXER_THREADS
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6288 fprintf(stderr, "Closing thread\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6289 SDL_WaitThread(Stream_Thread_global, NULL);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6290 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6291
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6292 fprintf(stderr, "Destroying mutex\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6293 SDL_DestroyMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6294
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6295 fprintf(stderr, "Deleting OpenAL sources\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6296 /* Delete all the OpenAL sources */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6297 for(i=0; i<Number_of_Channels_global; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6298 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6299 fprintf(stderr, "Deleting OpenAL source: %d\n", ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6300 alDeleteSources(1, &ALmixer_Channel_List[i].alsource);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6301 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6302 /* Delete all the channels */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6303 free(ALmixer_Channel_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6304 free(Source_Map_List);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6305
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6306 /* Reset the Number_of_Channels just in case somebody
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6307 * tries using a ALmixer function.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6308 * I probably should put "Initialized" checks everywhere,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6309 * but I'm too lazy at the moment.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6310 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6311 Number_of_Channels_global = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6312
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6313 context = alcGetCurrentContext();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6314 if(NULL == context)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6315 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6316 return;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6317 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6318 /* Need to get the device before I close the context */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6319 dev = alcGetContextsDevice(context);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6320 alcDestroyContext(context);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6321
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6322 if(NULL == dev)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6323 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6324 return;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6325 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6326 alcCloseDevice(dev);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6327
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6328 Sound_Quit();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6329
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6330 return;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6331 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6332
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6333 Uint8 ALmixer_IsInitialized()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6334 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6335 return ALmixer_Initialized;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6336 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6337
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6338 Uint32 ALmixer_GetFrequency()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6339 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6340 return ALmixer_Frequency_global;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6341 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6342
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6343 const SDL_version* ALmixer_Linked_Version()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6344 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6345 static SDL_version linked_mixver;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6346 ALMIXER_VERSION(&linked_mixver);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6347 return(&linked_mixver);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6348 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6349
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6350
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6351
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6352
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6353
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6354 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6355 void ALmixer_Output_Attributes()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6356 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6357 ALint num_flags = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6358 ALint* flags = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6359 int i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6360 ALCdevice* dev = alcGetContextsDevice( alcGetCurrentContext() );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6361
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6362
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6363 printf("custom context\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6364
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6365 alcGetIntegerv(dev, ALC_ATTRIBUTES_SIZE,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6366 sizeof num_flags, &num_flags );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6367
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6368 printf("Number of Flags: %d\n", num_flags);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6369
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6370 if(num_flags)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6371 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6372 flags = malloc(sizeof(num_flags) * sizeof(ALint));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6373
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6374 alcGetIntegerv(dev, ALC_ALL_ATTRIBUTES,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6375 sizeof num_flags * sizeof(ALint),
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6376 flags );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6377 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6378 for(i = 0; i < num_flags-1; i += 2)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6379 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6380 printf("key 0x%x : value %d\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6381 flags[i], flags[i+1]);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6382 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6383 free(flags);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6384 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6385 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6386
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6387
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6388 void ALmixer_Output_Decoders()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6389 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6390 Sound_Version sound_compile_version;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6391 Sound_Version sound_link_version;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6392
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6393 const Sound_DecoderInfo **rc = Sound_AvailableDecoders();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6394 const Sound_DecoderInfo **i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6395 const char **ext;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6396 FILE* stream = stdout;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6397
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6398
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6399 fprintf(stream, "SDL_sound Information:\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6400
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6401 SOUND_VERSION(&sound_compile_version);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6402 fprintf(stream, "\tCompiled with SDL_sound version: %d.%d.%d\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6403 sound_compile_version.major,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6404 sound_compile_version.minor,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6405 sound_compile_version.patch);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6406
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6407 Sound_GetLinkedVersion(&sound_link_version);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6408 fprintf(stream, "\tRunning (linked) with SDL_sound version: %d.%d.%d\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6409 sound_link_version.major,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6410 sound_link_version.minor,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6411 sound_link_version.patch);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6412
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6413 fprintf(stream, "Supported sound formats:\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6414 if (rc == NULL)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6415 fprintf(stream, " * Apparently, NONE!\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6416 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6417 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6418 for (i = rc; *i != NULL; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6419 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6420 fprintf(stream, " * %s\n", (*i)->description);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6421
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6422 for (ext = (*i)->extensions; *ext != NULL; ext++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6423 fprintf(stream, " File extension \"%s\"\n", *ext);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6424
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6425 fprintf(stream, " Written by %s.\n %s\n\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6426 (*i)->author, (*i)->url);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6427 } /* for */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6428 } /* else */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6429
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6430 fprintf(stream, "\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6431 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6432
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6433 void ALmixer_Output_OpenAL_Info()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6434 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6435 SDL_version mixer_compile_version;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6436 const SDL_version * mixer_link_version=ALmixer_Linked_Version();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6437 FILE* stream = stdout;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6438
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6439 fprintf(stream, "OpenAL Information:\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6440 fprintf(stream, "\tAL_VENDOR: %s\n", alGetString( AL_VENDOR ) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6441 fprintf(stream, "\tAL_VERSION: %s\n", alGetString( AL_VERSION ) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6442 fprintf(stream, "\tAL_RENDERER: %s\n", alGetString( AL_RENDERER ) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6443 fprintf(stream, "\tAL_EXTENSIONS: %s\n", alGetString( AL_EXTENSIONS ) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6444
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6445 ALMIXER_VERSION(&mixer_compile_version);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6446 fprintf(stream, "\nSDL_ALmixer Information:\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6447 fprintf(stream, "\tCompiled with SDL_ALmixer version: %d.%d.%d\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6448 mixer_compile_version.major,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6449 mixer_compile_version.minor,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6450 mixer_compile_version.patch);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6451
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6452 fprintf(stream, "\tRunning (linked) with SDL_ALmixer version: %d.%d.%d\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6453 mixer_link_version->major,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6454 mixer_link_version->minor,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6455 mixer_link_version->patch);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6456
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6457 fprintf(stream, "\tCompile flags: ");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6458 #ifdef ENABLE_LOKI_QUEUE_FIX_HACK
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6459 fprintf(stream, "ENABLE_LOKI_QUEUE_FIX_HACK ");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6460 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6461 #ifdef ENABLE_ALMIXER_THREADS
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6462 fprintf(stream, "ENABLE_ALMIXER_THREADS ");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6463 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6464 #ifdef ENABLE_ALC_SYNC
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6465 fprintf(stream, "ENABLE_ALC_SYNC ");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6466 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6467 fprintf(stream, "\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6468 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6469
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6470
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6471 Sint32 ALmixer_AllocateChannels(Sint32 numchans)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6472 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6473 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6474 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6475 retval = Internal_AllocateChannels(numchans);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6476 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6477 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6478 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6479
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6480
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6481 Sint32 ALmixer_ReserveChannels(Sint32 num)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6482 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6483 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6484 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6485 retval = Internal_ReserveChannels(num);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6486 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6487 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6488 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6489
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6490
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6491
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6492
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6493 static ALmixer_Data* DoLoad(Sound_Sample* sample, Uint32 buffersize, Uint8 decode_mode, Uint32 max_queue_buffers, Uint32 num_startup_buffers, Uint8 access_data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6494 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6495 Uint32 bytes_decoded;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6496 ALmixer_Data* ret_data;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6497 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6498
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6499 /* Allocate memory */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6500 ret_data = (ALmixer_Data *)malloc(sizeof(ALmixer_Data));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6501 if (NULL == ret_data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6502 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6503 ALmixer_SetError("Out of memory");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6504 return(NULL);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6505 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6506
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6507 /* Initialize the data fields */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6508
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6509 /* Set the Sound_Sample pointer */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6510 ret_data->sample = sample;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6511
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6512 /* Flag the data to note that it is not in use */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6513 ret_data->in_use = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6514
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6515 /* Initialize remaining flags */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6516 ret_data->total_time = -1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6517 ret_data->eof = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6518
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6519 /* Just initialize */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6520 ret_data->num_buffers_in_use = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6521
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6522 /* Just initialize */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6523 ret_data->total_bytes = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6524
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6525 /* Just initialize */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6526 ret_data->loaded_bytes = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6527
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6528 /* Set the max queue buffers (minimum must be 2) */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6529 if(max_queue_buffers < 2)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6530 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6531 max_queue_buffers = ALMIXER_DEFAULT_QUEUE_BUFFERS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6532 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6533 ret_data->max_queue_buffers = max_queue_buffers;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6534 /* Set up the start up buffers */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6535 if(0 == num_startup_buffers)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6536 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6537 num_startup_buffers = ALMIXER_DEFAULT_STARTUP_BUFFERS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6538 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6539 /* Make sure start up buffers is less or equal to max_queue_buffers */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6540 if(num_startup_buffers > max_queue_buffers)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6541 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6542 num_startup_buffers = max_queue_buffers;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6543 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6544 ret_data->num_startup_buffers = num_startup_buffers;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6545
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6546 ret_data->buffer_map_list = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6547 ret_data->current_buffer = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6548
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6549 ret_data->circular_buffer_queue = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6550
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6551 /* Now decode and load the data into a data chunk */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6552 /* Different cases for Streamed and Predecoded
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6553 * Streamed might turn into a predecoded if buffersize
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6554 * is large enough */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6555 if(ALMIXER_DECODE_STREAM == decode_mode)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6556 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6557 bytes_decoded = Sound_Decode(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6558 if(sample->flags & SOUND_SAMPLEFLAG_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6559 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6560 ALmixer_SetError(Sound_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6561 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6562 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6563 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6564 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6565
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6566 /* If no data, return an error */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6567 if(0 == bytes_decoded)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6568 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6569 ALmixer_SetError("File has no data");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6570 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6571 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6572 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6573 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6574
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6575 /* Note, currently, my Ogg conservative modifications
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6576 * prevent EOF from being detected in the first read
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6577 * because of the weird packet behavior of ov_read().
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6578 * The EAGAIN will get set, but not the EOF.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6579 * I don't know the best way to handle this,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6580 * so for now, Ogg's can only be explicitly
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6581 * predecoded.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6582 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6583
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6584 /* Correction: Since we no longer actually keep the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6585 * streamed data we read here (we rewind and throw
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6586 * it away, and start over on Play), it is
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6587 * safe to read another chunk to see if we've hit EOF
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6588 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6589 if(sample->flags & SOUND_SAMPLEFLAG_EAGAIN)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6590 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6591 bytes_decoded = Sound_Decode(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6592 if(sample->flags & SOUND_SAMPLEFLAG_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6593 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6594 ALmixer_SetError(Sound_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6595 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6596 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6597 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6598 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6599 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6600
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6601
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6602 /* If we found an EOF, the entire file was
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6603 * decoded, so we can treat it like one.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6604 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6605
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6606 if(sample->flags & SOUND_SAMPLEFLAG_EOF)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6607 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6608 fprintf(stderr, "We got LUCKY! File is predecoded even though STREAM was requested\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6609
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6610 ret_data->decoded_all = 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6611 /* Need to keep this information around for
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6612 * seek and rewind abilities.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6613 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6614 ret_data->total_bytes = bytes_decoded;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6615 /* For now, the loaded bytes is the same as total bytes, but
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6616 * this could change during a seek operation
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6617 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6618 ret_data->loaded_bytes = bytes_decoded;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6619
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6620 /* Let's compute the total playing time
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6621 * SDL_sound does not yet provide this (we're working on
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6622 * that at the moment...)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6623 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6624 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6625
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6626 /* Create one element in the buffer array for data for OpanAL */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6627 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6628 if(NULL == ret_data->buffer)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6629 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6630 ALmixer_SetError("Out of Memory");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6631 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6632 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6633 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6634 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6635 /* Clear the error code */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6636 alGetError();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6637 /* Now generate an OpenAL buffer using that first element */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6638 alGenBuffers(1, ret_data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6639 if( (error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6640 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6641 ALmixer_SetError("alGenBuffers failed: %s\n", aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6642 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6643 free(ret_data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6644 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6645 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6646 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6647
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6648
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6649 /* Now copy the data to the OpenAL buffer */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6650 /* We can't just set a pointer because the API needs
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6651 * its own copy to assist hardware acceleration */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6652 alBufferData(ret_data->buffer[0],
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6653 TranslateFormat(&sample->desired),
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6654 sample->buffer,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6655 bytes_decoded,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6656 sample->desired.rate
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6657 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6658 if( (error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6659 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6660 ALmixer_SetError("alBufferData failed: %s\n", aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6661 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6662 alDeleteBuffers(1, ret_data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6663 free(ret_data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6664 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6665 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6666 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6667
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6668 /* We should be done with the sample since it's all
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6669 * predecoded. So we can free the memory */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6670
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6671 /* Additional notes:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6672 * We need to keep data around in case Seek() is needed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6673 * or other Sound_AudioInfo is needed.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6674 * This can either be done by not deleting the sample,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6675 * or it can be done by dynamically recreating it
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6676 * when we need it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6677 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6678 /* Since OpenAL won't let us retrieve it
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6679 * (aka dynamically), we have to keep the Sample
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6680 * around because since the user requested
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6681 * streamed and we offered predecoded,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6682 * we don't want to mess up the user who
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6683 * was expecting seek support
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6684 * So Don't Do anything
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6685 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6686 /*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6687 if(0 == access_data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6688 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6689 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6690 ret_data->sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6691 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6692 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6693 /* Else, We keep a copy of the sample around.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6694 * so don't do anything.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6695 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6696
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6697 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6698 #if defined(DISABLE_PREDECODED_SEEK)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6699 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6700 ret_data->sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6701 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6702 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6703 ret_data->sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6704 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6705 /* We keep a copy of the sample around.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6706 * so don't do anything.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6707 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6708 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6709 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6710 /* okay we're done here */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6711
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6712 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6713 /* Else, we need to stream the data, so we'll
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6714 * create multple buffers for queuing */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6715 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6716 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6717 fprintf(stderr, "Loading streamed data (not lucky)\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6718 ret_data->decoded_all = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6719
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6720 /* This information is for predecoded.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6721 * Set to 0, since we don't know.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6722 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6723 ret_data->total_bytes = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6724
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6725 /* Create buffers for data
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6726 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6727 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) * max_queue_buffers);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6728 if(NULL == ret_data->buffer)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6729 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6730 ALmixer_SetError("Out of Memory");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6731 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6732 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6733 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6734 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6735
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6736 /* Clear the error code */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6737 alGetError();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6738 /* Now generate an OpenAL buffer using that first element */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6739 alGenBuffers(max_queue_buffers, ret_data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6740 if( (error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6741 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6742 ALmixer_SetError("alGenBuffers failed: %s\n", aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6743 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6744 free(ret_data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6745 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6746 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6747 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6748
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6749 /* Redesign: Okay, because of the unqueuing problems and such,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6750 * I've decided to redesign where and how queuing is handled.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6751 * Before, everything was queued up here. However, this
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6752 * placed a penalty on load and made performance inconsistent
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6753 * when samples had to be rewound. It did make things easier
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6754 * to queue because I could let OpenAL decide which buffer
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6755 * needed to be queued next.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6756 * Now, I'm going to push off the queuing to the actual
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6757 * Play() command. I'm going to add some book keeping,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6758 * and allow for additional buffers to be filled at later
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6759 * times.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6760 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6761
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6762
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6763 /* So first of all, because of I already decoded the sample
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6764 * for testing, I need to decide what to do with it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6765 * The best thing would be be to alBufferData() it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6766 * The problem is it may conflict with the rest of
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6767 * the system because everything now assumes buffers
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6768 * are entirely stripped (because of the unqueing
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6769 * problem).
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6770 * So it looks like I have to do the crappy thing
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6771 * and throw away the data, and rewind.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6772 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6773
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6774 if(0 == Sound_Rewind(ret_data->sample))
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6775 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6776 ALmixer_SetError("Cannot use sample for streamed data because it must be rewindable: %s", Sound_GetError() );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6777 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6778 free(ret_data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6779 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6780 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6781 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6782
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6783
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6784 /* If the user has selected access_data, we need to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6785 * keep copies of the queuing buffers around because
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6786 * OpenAL won't let us access the data.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6787 * Allocate the memory for the buffers here
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6788 * and initialize the albuffer-index map
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6789 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6790 if(access_data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6791 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6792 Uint32 j;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6793 /* Create buffers for data access
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6794 * Should be the same number as the number of queue buffers
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6795 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6796 ret_data->buffer_map_list = (Buffer_Map*)malloc( sizeof(Buffer_Map) * max_queue_buffers);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6797 if(NULL == ret_data->buffer_map_list)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6798 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6799 ALmixer_SetError("Out of Memory");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6800 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6801 free(ret_data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6802 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6803 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6804 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6805
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6806 ret_data->circular_buffer_queue = CircularQueueUnsignedInt_CreateQueue(max_queue_buffers);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6807 if(NULL == ret_data->circular_buffer_queue)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6808 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6809 ALmixer_SetError("Out of Memory");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6810 free(ret_data->buffer_map_list);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6811 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6812 free(ret_data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6813 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6814 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6815 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6816
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6817
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6818 for(j=0; j<max_queue_buffers; j++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6819 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6820 ret_data->buffer_map_list[j].albuffer = ret_data->buffer[j];
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6821 ret_data->buffer_map_list[j].index = j;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6822 ret_data->buffer_map_list[j].num_bytes = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6823 ret_data->buffer_map_list[j].data = (Uint8*)malloc( sizeof(Uint8) * buffersize);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6824 if(NULL == ret_data->buffer_map_list[j].data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6825 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6826 ALmixer_SetError("Out of Memory");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6827 break;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6828 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6829 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6830 /* If an error happened, we have to clean up the memory */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6831 if(j < max_queue_buffers)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6832 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6833 fprintf(stderr, "################## Buffer allocation failed\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6834 for( ; j>=0; j--)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6835 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6836 free(ret_data->buffer_map_list[j].data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6837 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6838 free(ret_data->buffer_map_list);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6839 CircularQueueUnsignedInt_FreeQueue(ret_data->circular_buffer_queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6840 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6841 free(ret_data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6842 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6843 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6844 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6845
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6846 /* The Buffer_Map_List must be sorted by albuffer for binary searches
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6847 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6848 qsort(ret_data->buffer_map_list, max_queue_buffers, sizeof(Buffer_Map), Compare_Buffer_Map);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6849 } /* End if access_data==true */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6850
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6851
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6852 } /* End of do stream */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6853 } /* end of DECODE_STREAM */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6854 /* User requested decode all (easy, nothing to figure out) */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6855 else if(ALMIXER_DECODE_ALL == decode_mode)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6856 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6857 bytes_decoded = Sound_DecodeAll(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6858 if(sample->flags & SOUND_SAMPLEFLAG_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6859 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6860 ALmixer_SetError(Sound_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6861 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6862 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6863 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6864 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6865
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6866 /* If no data, return an error */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6867 if(0 == bytes_decoded)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6868 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6869 ALmixer_SetError("File has no data");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6870 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6871 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6872 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6873 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6874
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6875
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6876 ret_data->decoded_all = 1;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6877 /* Need to keep this information around for
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6878 * seek and rewind abilities.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6879 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6880 ret_data->total_bytes = bytes_decoded;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6881 /* For now, the loaded bytes is the same as total bytes, but
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6882 * this could change during a seek operation
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6883 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6884 ret_data->loaded_bytes = bytes_decoded;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6885
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6886 /* Let's compute the total playing time
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6887 * SDL_sound does not yet provide this (we're working on
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6888 * that at the moment...)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6889 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6890 ret_data->total_time = Compute_Total_Time(&sample->desired, bytes_decoded);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6891
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6892 /* Create one element in the buffer array for data for OpanAL */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6893 ret_data->buffer = (ALuint*)malloc( sizeof(ALuint) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6894 if(NULL == ret_data->buffer)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6895 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6896 ALmixer_SetError("Out of Memory");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6897 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6898 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6899 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6900 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6901 /* Clear the error code */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6902 alGetError();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6903 /* Now generate an OpenAL buffer using that first element */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6904 alGenBuffers(1, ret_data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6905 if( (error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6906 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6907 ALmixer_SetError("alGenBuffers failed: %s\n", aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6908 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6909 free(ret_data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6910 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6911 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6912 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6913 fprintf(stderr, "Actual rate=%d, desired=%d\n", sample->actual.rate, sample->desired.rate);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6914
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6915 /* Now copy the data to the OpenAL buffer */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6916 /* We can't just set a pointer because the API needs
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6917 * its own copy to assist hardware acceleration */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6918 alBufferData(ret_data->buffer[0],
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6919 TranslateFormat(&sample->desired),
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6920 sample->buffer,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6921 bytes_decoded,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6922 sample->desired.rate
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6923 );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6924 if( (error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6925 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6926 ALmixer_SetError("alBufferData failed: %s\n", aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6927 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6928 alDeleteBuffers(1, ret_data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6929 free(ret_data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6930 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6931 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6932 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6933
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6934 /* We should be done with the sample since it's all
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6935 * predecoded. So we can free the memory */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6936 /* Need to keep around because Seek() needs it */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6937
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6938 /* Additional notes:
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6939 * We need to keep data around in case Seek() is needed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6940 * or other Sound_AudioInfo is needed.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6941 * This can either be done by not deleting the sample,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6942 * or it can be done by dynamically recreating it
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6943 * when we need it.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6944 * Update: I think now it's up to the user by passing the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6945 * access_data flag. If they set the flag, then they get
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6946 * data callbacks and seek support. If not, then they can
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6947 * get all that stuff at the expense of keeping extra memory
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6948 * around.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6949 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6950 if(0 == access_data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6951 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6952 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6953 ret_data->sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6954 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6955
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6956 /* Else, We keep a copy of the sample around.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6957 * so don't do anything.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6958 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6959 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6960 #if defined(DISABLE_PREDECODED_SEEK)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6961 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6962 ret_data->sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6963 #elif !defined(DISABLE_SEEK_MEMORY_OPTIMIZATION)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6964 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6965 ret_data->sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6966 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6967 /* We keep a copy of the sample around.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6968 * so don't do anything.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6969 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6970 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6971 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6972
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6973 fprintf(stderr, "Made it\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6974 /* okay we're done here */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6975 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6976 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6977 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6978 /* Shouldn't get here */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6979 ALmixer_SetError("Unknown decode mode");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6980 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6981 free(ret_data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6982 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6983 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6984
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6985 fprintf(stderr, "Returning data\n");
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6986 return ret_data;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6987 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6988
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6989
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6990 /* This will load a sample for us. Most of the uglyness is
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6991 * error checking and the fact that streamed/predecoded files
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6992 * must be treated differently.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6993 * I don't like the AudioInfo parameter. I removed it once,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6994 * but the system will fail on RAW samples because the user
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6995 * must specify it, so I had to bring it back.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6996 * Remember I must close the rwops if there is an error before NewSample()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6997 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6998 ALmixer_Data* ALmixer_LoadSample_RW(SDL_RWops* rwops, const char* fileext, Uint32 buffersize, Uint8 decode_mode, Uint32 max_queue_buffers, Uint32 num_startup_buffers, Uint8 access_data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
6999 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7000 Sound_Sample* sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7001 Sound_AudioInfo target;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7002
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7003 /* Initialize target values to defaults
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7004 * 0 tells SDL_sound to use the "actual" values
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7005 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7006 target.channels = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7007 target.rate = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7008 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7009 /* This requires my new additions to SDL_sound. It will
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7010 * convert the sample to the proper endian order.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7011 * If the actual is 8-bit, it will do unsigned, if
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7012 * the actual is 16-bit, it will do signed.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7013 * I'm told by Ryan Gordon that OpenAL prefers the signedness
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7014 * in this way.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7015 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7016 target.format = AUDIO_U8S16SYS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7017 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7018 target.format = AUDIO_S16SYS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7019 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7020
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7021 /* Set a default buffersize if needed */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7022 if(0 == buffersize)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7023 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7024 buffersize = ALMIXER_DEFAULT_BUFFERSIZE;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7025 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7026
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7027 sample = Sound_NewSample(rwops, fileext, &target, buffersize);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7028 if(NULL == sample)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7029 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7030 ALmixer_SetError(Sound_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7031 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7032 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7033
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7034 return( DoLoad(sample, buffersize, decode_mode, max_queue_buffers, num_startup_buffers, access_data));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7035 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7036
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7037
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7038
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7039 /* This will load a sample for us from
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7040 * a file (instead of RWops). Most of the uglyness is
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7041 * error checking and the fact that streamed/predecoded files
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7042 * must be treated differently.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7043 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7044 ALmixer_Data* ALmixer_LoadSample(const char* filename, Uint32 buffersize, Uint8 decode_mode, Uint32 max_queue_buffers, Uint32 num_startup_buffers, Uint8 access_data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7045 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7046 Sound_Sample* sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7047 Sound_AudioInfo target;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7048
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7049 /* Initialize target values to defaults
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7050 * 0 tells SDL_sound to use the "actual" values
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7051 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7052 target.channels = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7053 target.rate = 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7054
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7055 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7056 /* This requires my new additions to SDL_sound. It will
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7057 * convert the sample to the proper endian order.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7058 * If the actual is 8-bit, it will do unsigned, if
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7059 * the actual is 16-bit, it will do signed.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7060 * I'm told by Ryan Gordon that OpenAL prefers the signedness
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7061 * in this way.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7062 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7063 target.format = AUDIO_U8S16SYS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7064 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7065 target.format = AUDIO_S16SYS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7066 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7067
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7068 #if 0
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7069 /* Okay, here's a messy hack. The problem is that we need
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7070 * to convert the sample to have the correct bitdepth,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7071 * endian order, and signedness values.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7072 * The bit depth is 8 or 16.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7073 * The endian order is the native order of the system.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7074 * The signedness depends on what the original value
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7075 * of the sample. Unfortunately, we can't specify these
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7076 * values until we after we already know what the original
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7077 * values were for bitdepth and signedness.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7078 * So we must open the file once to get the values,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7079 * then close it, and then reopen it with the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7080 * correct desired target values.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7081 * I tried changing the sample->desired field after
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7082 * the NewSample call, but it had no effect, so
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7083 * it looks like it must be set on open.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7084 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7085 /* Pick a small buffersize for the first open to not
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7086 * waste much time allocating memory */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7087 sample = Sound_NewSampleFromFile(filename, NULL, 512);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7088 if(NULL == sample)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7089 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7090 ALmixer_SetError(Sound_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7091 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7092 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7093
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7094 bit_depth = GetBitDepth(sample->actual.format);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7095 signedness_value = GetSignednessValue(sample->actual.format);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7096 if(8 == bit_depth)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7097 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7098 /* If 8 bit, then we don't have to worry about
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7099 * endian issues. We can just use the actual format
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7100 * value and it should do the right thing
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7101 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7102 target.format = sample->actual.format;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7103 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7104 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7105 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7106 /* We'll assume it's 16-bit, and if it's not
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7107 * hopefully SDL_sound will return an error,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7108 * or let us convert to 16-bit
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7109 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7110 /* Now we need to get the correct signedness */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7111 if(ALMIXER_UNSIGNED_VALUE == signedness_value)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7112 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7113 /* Set to Unsigned 16-bit, system endian order */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7114 target.format = AUDIO_U16SYS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7115 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7116 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7117 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7118 /* Again, we'll assume it's Signed 16-bit system order
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7119 * or force the conversion and hope it works out
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7120 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7121 target.format = AUDIO_S16SYS;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7122 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7123 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7124
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7125 /* Now we have the correct info. We need to close and reopen */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7126 Sound_FreeSample(sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7127 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7128
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7129 sample = Sound_NewSampleFromFile(filename, &target, buffersize);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7130 if(NULL == sample)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7131 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7132 ALmixer_SetError(Sound_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7133 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7134 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7135
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7136 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);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7137
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7138 return( DoLoad(sample, buffersize, decode_mode, max_queue_buffers, num_startup_buffers, access_data));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7139 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7140
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7141
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7142 /* This is a back door for RAW samples or if you need the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7143 * AudioInfo field. Use at your own risk.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7144 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7145 ALmixer_Data* ALmixer_LoadSample_RAW_RW(SDL_RWops* rwops, const char* fileext, Sound_AudioInfo* desired, Uint32 buffersize, Uint8 decode_mode, Uint32 max_queue_buffers, Uint32 num_startup_buffers, Uint8 access_data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7146 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7147 Sound_Sample* sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7148 sample = Sound_NewSample(rwops, fileext, desired, buffersize);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7149 if(NULL == sample)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7150 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7151 ALmixer_SetError(Sound_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7152 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7153 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7154 return( DoLoad(sample, buffersize, decode_mode, max_queue_buffers, num_startup_buffers, access_data));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7155 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7156
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7157
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7158
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7159
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7160 /* This is a back door for RAW samples or if you need the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7161 * AudioInfo field. Use at your own risk.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7162 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7163 ALmixer_Data* ALmixer_LoadSample_RAW(const char* filename, Sound_AudioInfo* desired, Uint32 buffersize, Uint8 decode_mode, Uint32 max_queue_buffers, Uint32 num_startup_buffers, Uint8 access_data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7164 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7165 Sound_Sample* sample = NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7166 sample = Sound_NewSampleFromFile(filename, desired, buffersize);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7167 if(NULL == sample)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7168 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7169 ALmixer_SetError(Sound_GetError());
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7170 return NULL;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7171 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7172 return( DoLoad(sample, buffersize, decode_mode, max_queue_buffers, num_startup_buffers, access_data));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7173 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7174
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7175
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7176
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7177
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7178 void ALmixer_FreeData(ALmixer_Data* data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7179 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7180 ALenum error;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7181 if(NULL == data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7182 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7183 return;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7184 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7185
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7186 if(data->decoded_all)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7187 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7188 /* If access_data was enabled, then the Sound_Sample*
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7189 * still exists. We need to free it
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7190 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7191 if(data->sample != NULL)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7192 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7193 Sound_FreeSample(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7194 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7195 alDeleteBuffers(1, data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7196 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7197 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7198 fprintf(stderr, "70Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7199 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7200 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7201
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7202 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7203 else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7204 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7205 Uint32 i;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7206
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7207 /* Delete buffer copies if access_data was enabled */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7208 if(data->buffer_map_list != NULL)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7209 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7210 for(i=0; i<data->max_queue_buffers; i++)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7211 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7212 free(data->buffer_map_list[i].data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7213 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7214 free(data->buffer_map_list);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7215 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7216 if(data->circular_buffer_queue != NULL)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7217 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7218 CircularQueueUnsignedInt_FreeQueue(data->circular_buffer_queue);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7219 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7220
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7221 Sound_FreeSample(data->sample);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7222 alDeleteBuffers(data->max_queue_buffers, data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7223 if((error = alGetError()) != AL_NO_ERROR)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7224 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7225 fprintf(stderr, "71Testing error: %s\n",
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7226 aluGetErrorString(error));
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7227 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7228 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7229 free(data->buffer);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7230 free(data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7231 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7232
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7233 Sint32 ALmixer_GetTotalTime(ALmixer_Data* data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7234 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7235 return data->total_time;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7236 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7237
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7238 /* This function will look up the source for the corresponding channel */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7239 /* Must return 0 on error instead of -1 because of unsigned int */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7240 ALuint ALmixer_GetSource(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7241 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7242 ALuint retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7243 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7244 retval = Internal_GetSource(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7245 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7246 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7247 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7248
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7249 /* This function will look up the channel for the corresponding source */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7250 Sint32 ALmixer_GetChannel(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7251 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7252 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7253 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7254 retval = Internal_GetChannel(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7255 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7256 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7257 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7258
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7259 Sint32 ALmixer_FindFreeChannel(Sint32 start_channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7260 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7261 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7262 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7263 retval = Internal_FindFreeChannel(start_channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7264 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7265 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7266 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7267
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7268
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7269
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7270 /* API update function.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7271 * It should return the number of buffers that were
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7272 * queued during the call. The value might be
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7273 * used to guage how long you might wait to
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7274 * call the next update loop in case you are worried
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7275 * about preserving CPU cycles. The idea is that
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7276 * when a buffer is queued, there was probably some
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7277 * CPU intensive looping which took awhile.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7278 * It's mainly provided as a convenience.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7279 * Timing the call with SDL_GetTicks() would produce
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7280 * more accurate information.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7281 * Returns a negative value if there was an error,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7282 * the value being the number of errors.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7283 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7284 Sint32 ALmixer_Update()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7285 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7286 #ifdef ENABLE_ALMIXER_THREADS
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7287 /* The thread will handle all updates by itself.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7288 * Don't allow the user to explicitly call update.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7289 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7290 return 0;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7291 #else
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7292 return( Update_ALmixer(NULL) );
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7293 #endif
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7294 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7295
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7296
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7297
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7298 void ALmixer_ChannelFinished(void (*channel_finished)(Sint32 channel, void* userdata), void* userdata)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7299 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7300 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7301 Channel_Done_Callback = channel_finished;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7302 Channel_Done_Callback_Userdata = userdata;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7303 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7304 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7305
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7306
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7307 void ALmixer_ChannelData(void (*channel_data)(Sint32 which_chan, Uint8* data, Uint32 num_bytes, Uint32 frequency, Uint8 channels, Uint8 bitdepth, Uint16 format, Uint8 decode_mode))
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7308 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7309 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7310 Channel_Data_Callback = channel_data;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7311 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7312 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7313
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7314
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7315
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7316
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7317
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7318 Sint32 ALmixer_PlayChannelTimed(Sint32 channel, ALmixer_Data* data, Sint32 loops, Sint32 ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7319 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7320 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7321 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7322 retval = Internal_PlayChannelTimed(channel, data, loops, ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7323 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7324 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7325 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7326
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7327
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7328 /* In case the user wants to specify a source instead of a channel,
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7329 * they may use this function. This function will look up the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7330 * source-to-channel map, and convert the call into a
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7331 * PlayChannelTimed() function call.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7332 * Returns the channel it's being played on.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7333 * Note: If you are prefer this method, then you need to be careful
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7334 * about using PlayChannel, particularly if you request the
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7335 * first available channels because source and channels have
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7336 * a one-to-one mapping in this API. It is quite easy for
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7337 * a channel/source to already be in use because of this.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7338 * In this event, an error message will be returned to you.
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7339 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7340 ALuint ALmixer_PlaySourceTimed(ALuint source, ALmixer_Data* data, Sint32 loops, Sint32 ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7341 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7342 ALuint retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7343 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7344 retval = Internal_PlaySourceTimed(source, data, loops, ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7345 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7346 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7347 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7348
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7349
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7350 /* Will return the number of channels halted
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7351 * or 0 for error
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7352 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7353 Sint32 ALmixer_HaltChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7354 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7355 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7356 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7357 retval = Internal_HaltChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7358 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7359 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7360 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7361
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7362 /* Will return the number of channels halted
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7363 * or 0 for error
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7364 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7365 Sint32 ALmixer_HaltSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7366 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7367 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7368 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7369 retval = Internal_HaltSource(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7370 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7371 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7372 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7373
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7374
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7375 /* This will rewind the SDL_Sound sample for streamed
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7376 * samples and start buffering up the data for the next
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7377 * playback. This may require samples to be halted
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7378 */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7379 Sint32 ALmixer_RewindData(ALmixer_Data* data)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7380 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7381 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7382 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7383 retval = Internal_RewindData(data);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7384 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7385 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7386 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7387
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7388 Sint32 ALmixer_RewindChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7389 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7390 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7391 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7392 retval = Internal_RewindChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7393 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7394 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7395 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7396
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7397 Sint32 ALmixer_RewindSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7398 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7399 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7400 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7401 retval = Internal_RewindSource(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7402 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7403 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7404 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7405
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7406 Sint32 ALmixer_PauseChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7407 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7408 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7409 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7410 retval = Internal_PauseChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7411 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7412 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7413 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7414
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7415 Sint32 ALmixer_PauseSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7416 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7417 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7418 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7419 retval = Internal_PauseSource(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7420 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7421 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7422 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7423
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7424 Sint32 ALmixer_ResumeChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7425 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7426 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7427 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7428 retval = Internal_ResumeChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7429 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7430 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7431 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7432
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7433 Sint32 ALmixer_ResumeSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7434 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7435 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7436 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7437 retval = Internal_ResumeSource(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7438 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7439 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7440 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7441
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7442 /* Might consider setting eof to 0 as a "feature"
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7443 * This will allow seek to end to stay there because
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7444 * Play automatically rewinds if at the end */
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7445 Sint32 ALmixer_Seek(ALmixer_Data* data, Uint32 msec)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7446 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7447 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7448 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7449 retval = Internal_Seek(data, msec);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7450 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7451 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7452 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7453
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7454 Sint32 ALmixer_FadeInChannelTimed(Sint32 channel, ALmixer_Data* data, Sint32 loops, Uint32 fade_ticks, Sint32 expire_ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7455 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7456 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7457 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7458 retval = Internal_FadeInChannelTimed(channel, data, loops, fade_ticks, expire_ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7459 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7460 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7461 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7462
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7463 ALuint ALmixer_FadeInSourceTimed(ALuint source, ALmixer_Data* data, Sint32 loops, Uint32 fade_ticks, Sint32 expire_ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7464 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7465 ALuint retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7466 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7467 retval = Internal_FadeInSourceTimed(source, data, loops, fade_ticks, expire_ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7468 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7469 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7470 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7471
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7472 Sint32 ALmixer_FadeOutChannel(Sint32 channel, Uint32 ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7473 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7474 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7475 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7476 retval = Internal_FadeOutChannel(channel, ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7477 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7478 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7479 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7480
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7481 Sint32 ALmixer_FadeOutSource(ALuint source, Uint32 ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7482 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7483 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7484 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7485 retval = Internal_FadeOutSource(source, ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7486 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7487 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7488 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7489
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7490 Sint32 ALmixer_FadeChannel(Sint32 channel, Uint32 ticks, ALfloat volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7491 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7492 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7493 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7494 retval = Internal_FadeChannel(channel, ticks, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7495 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7496 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7497 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7498
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7499 Sint32 ALmixer_FadeSource(ALuint source, Uint32 ticks, ALfloat volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7500 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7501 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7502 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7503 retval = Internal_FadeSource(source, ticks, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7504 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7505 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7506 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7507
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7508 Sint32 ALmixer_SetMaxVolumeChannel(Sint32 channel, ALfloat volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7509 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7510 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7511 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7512 retval = Internal_SetMaxVolumeChannel(channel, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7513 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7514 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7515 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7516
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7517 Sint32 ALmixer_SetMaxVolumeSource(ALuint source, ALfloat volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7518 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7519 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7520 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7521 retval = Internal_SetMaxVolumeSource(source, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7522 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7523 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7524 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7525
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7526 ALfloat ALmixer_GetMaxVolumeChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7527 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7528 ALfloat retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7529 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7530 retval = Internal_GetMaxVolumeChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7531 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7532 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7533 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7534
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7535 ALfloat ALmixer_GetMaxVolumeSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7536 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7537 ALfloat retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7538 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7539 retval = Internal_GetMaxVolumeSource(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7540 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7541 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7542 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7543
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7544
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7545 Sint32 ALmixer_SetMinVolumeChannel(Sint32 channel, ALfloat volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7546 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7547 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7548 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7549 retval = Internal_SetMinVolumeChannel(channel, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7550 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7551 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7552 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7553
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7554 Sint32 ALmixer_SetMinVolumeSource(ALuint source, ALfloat volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7555 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7556 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7557 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7558 retval = Internal_SetMinVolumeSource(source, volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7559 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7560 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7561 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7562
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7563 ALfloat ALmixer_GetMinVolumeChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7564 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7565 ALfloat retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7566 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7567 retval = Internal_GetMinVolumeChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7568 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7569 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7570 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7571
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7572 ALfloat ALmixer_GetMinVolumeSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7573 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7574 ALfloat retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7575 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7576 retval = Internal_GetMinVolumeSource(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7577 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7578 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7579 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7580
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7581
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7582
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7583 Sint32 ALmixer_SetMasterVolume(ALfloat volume)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7584 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7585 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7586 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7587 retval = Internal_SetMasterVolume(volume);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7588 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7589 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7590 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7591
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7592 ALfloat ALmixer_GetMasterVolume()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7593 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7594 ALfloat retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7595 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7596 retval = Internal_GetMasterVolume();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7597 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7598 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7599 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7600
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7601 Sint32 ALmixer_ExpireChannel(Sint32 channel, Sint32 ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7602 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7603 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7604 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7605 retval = Internal_ExpireChannel(channel, ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7606 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7607 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7608 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7609
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7610 Sint32 ALmixer_ExpireSource(ALuint source, Sint32 ticks)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7611 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7612 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7613 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7614 retval = Internal_ExpireSource(source, ticks);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7615 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7616 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7617 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7618
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7619 Sint32 ALmixer_QueryChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7620 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7621 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7622 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7623 retval = Internal_QueryChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7624 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7625 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7626 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7627
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7628 Sint32 ALmixer_QuerySource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7629 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7630 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7631 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7632 retval = Internal_QuerySource(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7633 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7634 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7635 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7636
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7637
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7638 Sint32 ALmixer_PlayingChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7639 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7640 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7641 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7642 retval = Internal_PlayingChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7643 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7644 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7645 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7646
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7647 Sint32 ALmixer_PlayingSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7648 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7649 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7650 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7651 retval = Internal_PlayingSource(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7652 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7653 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7654 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7655
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7656
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7657 Sint32 ALmixer_PausedChannel(Sint32 channel)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7658 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7659 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7660 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7661 retval = Internal_PausedChannel(channel);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7662 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7663 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7664 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7665
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7666 Sint32 ALmixer_PausedSource(ALuint source)
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7667 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7668 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7669 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7670 retval = Internal_PausedSource(source);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7671 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7672 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7673 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7674
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7675
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7676 Sint32 ALmixer_CountAllFreeChannels()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7677 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7678 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7679 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7680 retval = Internal_CountAllFreeChannels();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7681 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7682 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7683 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7684
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7685 Sint32 ALmixer_CountUnreservedFreeChannels()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7686 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7687 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7688 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7689 retval = Internal_CountUnreservedFreeChannels();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7690 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7691 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7692 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7693
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7694 Sint32 ALmixer_CountAllUsedChannels()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7695 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7696 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7697 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7698 retval = Internal_CountAllUsedChannels();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7699 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7700 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7701 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7702
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7703 Sint32 ALmixer_CountUnreservedUsedChannels()
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7704 {
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7705 Sint32 retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7706 SDL_LockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7707 retval = Internal_CountUnreservedUsedChannels();
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7708 SDL_UnlockMutex(simple_lock);
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7709 return retval;
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7710 }
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7711
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7712
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7713
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7714
|
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff
changeset
|
7715
|