author | koda |
Tue, 30 Jun 2009 12:31:32 +0000 | |
changeset 2213 | bd51bbf06033 |
parent 2212 | 6b5da1a2765a |
child 2215 | 1d78579e06c2 |
permissions | -rw-r--r-- |
2191 | 1 |
/* |
2 |
* OpenAL Bridge - a simple portable library for OpenAL interface |
|
3 |
* Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
2213 | 19 |
#include "globals.h" |
20 |
#include "wrappers.h" |
|
21 |
#include "alc.h" |
|
22 |
#include "loaders.h" |
|
23 |
#include "endianness.h" |
|
2191 | 24 |
|
25 |
#ifdef __CPLUSPLUS |
|
26 |
extern "C" { |
|
27 |
#endif |
|
28 |
||
2212 | 29 |
/*Sources are points emitting sound*/ |
2191 | 30 |
ALuint *Sources; |
2212 | 31 |
/*Buffers hold sound data*/ |
2191 | 32 |
ALuint *Buffers; |
2212 | 33 |
/*index for Sources and Buffers*/ |
2213 | 34 |
ALuint globalindex, globalsize, increment; |
2212 | 35 |
/*Position of the source sound*/ |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
36 |
ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; |
2212 | 37 |
/*Velocity of the source sound*/ |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
38 |
ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; |
2191 | 39 |
|
40 |
||
41 |
ALint openal_close(void) { |
|
2213 | 42 |
/*Stop all sounds, deallocate all memory and close OpenAL */ |
2191 | 43 |
ALCcontext *context; |
44 |
ALCdevice *device; |
|
45 |
||
46 |
alSourceStopv (globalsize, Sources); |
|
47 |
alDeleteSources (globalsize, Sources); |
|
48 |
alDeleteBuffers (globalsize, Buffers); |
|
49 |
||
50 |
free(Sources); |
|
51 |
free(Buffers); |
|
52 |
||
53 |
context = alcGetCurrentContext(); |
|
54 |
device = alcGetContextsDevice(context); |
|
55 |
||
56 |
alcMakeContextCurrent(NULL); |
|
57 |
alcDestroyContext(context); |
|
58 |
alcCloseDevice(device); |
|
59 |
return AL_TRUE; |
|
60 |
} |
|
61 |
||
62 |
||
63 |
ALint openal_init(int memorysize) { |
|
2213 | 64 |
/*Initialize an OpenAL contex and allocate memory space for data and buffers*/ |
2191 | 65 |
ALCcontext *context; |
66 |
ALCdevice *device; |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
67 |
const ALCchar *default_device; |
2191 | 68 |
|
2212 | 69 |
/*Position of the listener*/ |
2191 | 70 |
ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 }; |
2212 | 71 |
/*Velocity of the listener*/ |
2191 | 72 |
ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 }; |
2212 | 73 |
/*Orientation of the listener. (first 3 elements are "at", second 3 are "up")*/ |
2191 | 74 |
ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 }; |
75 |
||
76 |
default_device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); |
|
77 |
fprintf(stderr, "Using default device: %s\n", default_device); |
|
78 |
||
79 |
if ((device = alcOpenDevice(default_device)) == NULL) { |
|
2200
8192be6e3aef
koda/Smaxx changes to openal for crossplatform building
nemo
parents:
2194
diff
changeset
|
80 |
fprintf(stderr, "ERROR: Failed to open sound device\n"); |
2191 | 81 |
return AL_FALSE; |
82 |
} |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
83 |
|
2191 | 84 |
context = alcCreateContext(device, NULL); |
85 |
alcMakeContextCurrent(context); |
|
86 |
alcProcessContext(context); |
|
87 |
||
88 |
if (AlGetError("ERROR %d: Creating a new contex\n") != AL_TRUE) |
|
89 |
return AL_FALSE; |
|
90 |
||
2212 | 91 |
/*allocate memory space for buffers and sources*/ |
2191 | 92 |
globalsize = memorysize; |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
93 |
increment = memorysize; |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
94 |
Buffers = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
95 |
Sources = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
2191 | 96 |
|
2212 | 97 |
/*set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation*/ |
2191 | 98 |
alListenerf (AL_GAIN, 1.0f ); |
99 |
alListenerfv(AL_POSITION, ListenerPos); |
|
100 |
alListenerfv(AL_VELOCITY, ListenerVel); |
|
101 |
alListenerfv(AL_ORIENTATION, ListenerOri); |
|
102 |
||
103 |
if (AlGetError("ERROR %d: Setting Listener properties\n") != AL_TRUE) |
|
104 |
return AL_FALSE; |
|
105 |
||
106 |
alGetError(); /* clear any AL errors beforehand */ |
|
107 |
return AL_TRUE; |
|
108 |
} |
|
109 |
||
2213 | 110 |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
111 |
int helper_realloc (void) { |
2213 | 112 |
/*expands allocated memory when loading more sound files than expected*/ |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
113 |
globalsize += increment; |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
114 |
#ifdef DEBUG |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
115 |
fprintf(stderr, "OpenAL: Realloc in process %d\n", globalsize); |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
116 |
#endif |
2213 | 117 |
Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize); |
118 |
Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize); |
|
119 |
||
120 |
return 0; |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
121 |
} |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
122 |
|
2191 | 123 |
|
124 |
int openal_loadfile (const char *filename){ |
|
2213 | 125 |
/*Open a file, load into memory and allocate the Source buffer for playing*/ |
2191 | 126 |
ALenum format; |
127 |
ALsizei bitsize; |
|
128 |
ALsizei freq; |
|
2213 | 129 |
char *data; |
2191 | 130 |
uint32_t fileformat; |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
131 |
int error; |
2191 | 132 |
FILE *fp; |
133 |
||
134 |
||
2213 | 135 |
/*when the buffers are all used, we can expand memory to accept new files*/ |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
136 |
if (globalindex == globalsize) |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
137 |
helper_realloc(); |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
138 |
|
2191 | 139 |
/*detect the file format, as written in the first 4 bytes of the header*/ |
140 |
fp = Fopen (filename, "rb"); |
|
141 |
if (fp == NULL) |
|
142 |
return -1; |
|
143 |
error = fread (&fileformat, sizeof(uint32_t), 1, fp); |
|
144 |
fclose (fp); |
|
145 |
||
146 |
if (error < 0) { |
|
147 |
fprintf(stderr, "ERROR: file %s is too short \n", filename); |
|
148 |
return -2; |
|
149 |
} |
|
150 |
||
2212 | 151 |
/*prepare the buffer to receive data*/ |
2191 | 152 |
alGenBuffers(1, &Buffers[globalindex]); |
153 |
||
154 |
if (AlGetError("ERROR %d: Allocating memory for buffers\n") != AL_TRUE) |
|
155 |
return -3; |
|
156 |
||
2212 | 157 |
/*prepare the source to emit sound*/ |
2191 | 158 |
alGenSources(1, &Sources[globalindex]); |
159 |
||
160 |
if (AlGetError("ERROR %d: Allocating memory for sources\n") != AL_TRUE) |
|
161 |
return -4; |
|
162 |
||
163 |
||
2212 | 164 |
if (fileformat == 0x5367674F) /*check if ogg*/ |
2191 | 165 |
error = load_OggVorbis (filename, &format, &data, &bitsize, &freq); |
166 |
else { |
|
2212 | 167 |
if (fileformat == 0x46464952) /*check if wav*/ |
2191 | 168 |
error = load_WavPcm (filename, &format, &data, &bitsize, &freq); |
169 |
else { |
|
170 |
fprintf(stderr, "ERROR: File format (%08X) not supported!\n", invert_endianness(fileformat)); |
|
171 |
return -5; |
|
172 |
} |
|
173 |
} |
|
174 |
||
2212 | 175 |
/*copy pcm data in one buffer*/ |
2191 | 176 |
alBufferData(Buffers[globalindex], format, data, bitsize, freq); |
2212 | 177 |
free(data); /*deallocate data to save memory*/ |
2191 | 178 |
|
179 |
if (AlGetError("ERROR %d: Writing data to buffer\n") != AL_TRUE) |
|
2210 | 180 |
return -6; |
2191 | 181 |
|
2212 | 182 |
/*set source properties that it will use when it's in playback*/ |
2191 | 183 |
alSourcei (Sources[globalindex], AL_BUFFER, Buffers[globalindex] ); |
184 |
alSourcef (Sources[globalindex], AL_PITCH, 1.0f ); |
|
185 |
alSourcef (Sources[globalindex], AL_GAIN, 1.0f ); |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
186 |
alSourcefv(Sources[globalindex], AL_POSITION, SourcePos ); |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
187 |
alSourcefv(Sources[globalindex], AL_VELOCITY, SourceVel ); |
2191 | 188 |
alSourcei (Sources[globalindex], AL_LOOPING, 0 ); |
189 |
||
190 |
if (AlGetError("ERROR %d: Setting source properties\n") != AL_TRUE) |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
191 |
return -7; |
2191 | 192 |
|
193 |
alGetError(); /* clear any AL errors beforehand */ |
|
194 |
||
2212 | 195 |
/*returns the index of the source you just loaded, increments it and exits*/ |
2191 | 196 |
return globalindex++; |
197 |
} |
|
198 |
||
199 |
||
200 |
ALint openal_toggleloop (int index){ |
|
201 |
/*Set or unset looping mode*/ |
|
202 |
ALint loop; |
|
203 |
||
204 |
if (index >= globalsize) { |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
205 |
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
2191 | 206 |
return AL_FALSE; |
207 |
} |
|
208 |
||
209 |
alGetSourcei (Sources[index], AL_LOOPING, &loop); |
|
210 |
alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001); |
|
211 |
if (AlGetError("ERROR %d: Getting or setting loop property\n") != AL_TRUE) |
|
212 |
return AL_FALSE; |
|
213 |
||
214 |
alGetError(); /* clear any AL errors beforehand */ |
|
215 |
||
216 |
return AL_TRUE; |
|
217 |
} |
|
218 |
||
219 |
||
220 |
ALint openal_setvolume (int index, unsigned char percentage) { |
|
221 |
/*Set volume for sound number index*/ |
|
222 |
if (index >= globalindex) { |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
223 |
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
2191 | 224 |
return AL_FALSE; |
225 |
} |
|
226 |
||
227 |
if (percentage > 100) |
|
228 |
percentage = 100; |
|
2213 | 229 |
alSourcef (Sources[index], AL_GAIN, (float) percentage/100.0f); |
2191 | 230 |
if (AlGetError("ERROR %d: Setting volume for last sound\n") != AL_TRUE) |
231 |
return AL_FALSE; |
|
232 |
||
233 |
alGetError(); /* clear any AL errors beforehand */ |
|
234 |
||
235 |
return AL_TRUE; |
|
236 |
} |
|
237 |
||
238 |
||
239 |
ALint openal_setglobalvolume (unsigned char percentage) { |
|
240 |
/*Set volume for all sounds*/ |
|
241 |
if (percentage > 100) |
|
242 |
percentage = 100; |
|
2213 | 243 |
alListenerf (AL_GAIN, (float) percentage/100.0f); |
2191 | 244 |
if (AlGetError("ERROR %d: Setting global volume\n") != AL_TRUE) |
245 |
return AL_FALSE; |
|
246 |
||
247 |
alGetError(); /* clear any AL errors beforehand */ |
|
248 |
||
249 |
return AL_TRUE; |
|
250 |
} |
|
251 |
||
252 |
||
253 |
ALint openal_togglemute () { |
|
254 |
/*Mute or unmute sound*/ |
|
255 |
ALfloat mute; |
|
256 |
||
257 |
alGetListenerf (AL_GAIN, &mute); |
|
258 |
if (mute > 0) |
|
259 |
mute = 0; |
|
260 |
else |
|
261 |
mute = 1.0; |
|
262 |
alListenerf (AL_GAIN, mute); |
|
263 |
if (AlGetError("ERROR %d: Setting mute property\n") != AL_TRUE) |
|
264 |
return AL_FALSE; |
|
265 |
||
266 |
alGetError(); /* clear any AL errors beforehand */ |
|
267 |
||
268 |
return AL_TRUE; |
|
269 |
} |
|
270 |
||
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
271 |
|
2213 | 272 |
ALint openal_fade(int index, unsigned int quantity, char direction) { |
273 |
/*Fade in or out by calling a helper thread*/ |
|
2194
1597710c6118
koda adds threading for fadein/out. Untested under windows, but works beautifully under Linux (and presumably OSX, right koda?)
nemo
parents:
2191
diff
changeset
|
274 |
#ifndef _WIN32 |
1597710c6118
koda adds threading for fadein/out. Untested under windows, but works beautifully under Linux (and presumably OSX, right koda?)
nemo
parents:
2191
diff
changeset
|
275 |
pthread_t thread; |
1597710c6118
koda adds threading for fadein/out. Untested under windows, but works beautifully under Linux (and presumably OSX, right koda?)
nemo
parents:
2191
diff
changeset
|
276 |
#else |
1597710c6118
koda adds threading for fadein/out. Untested under windows, but works beautifully under Linux (and presumably OSX, right koda?)
nemo
parents:
2191
diff
changeset
|
277 |
HANDLE Thread; |
1597710c6118
koda adds threading for fadein/out. Untested under windows, but works beautifully under Linux (and presumably OSX, right koda?)
nemo
parents:
2191
diff
changeset
|
278 |
DWORD threadID; |
2209 | 279 |
#endif |
280 |
fade_t *fade; |
|
281 |
||
282 |
fade = (fade_t*) Malloc(sizeof(fade_t)); |
|
2200
8192be6e3aef
koda/Smaxx changes to openal for crossplatform building
nemo
parents:
2194
diff
changeset
|
283 |
fade->index = index; |
8192be6e3aef
koda/Smaxx changes to openal for crossplatform building
nemo
parents:
2194
diff
changeset
|
284 |
fade->quantity = quantity; |
2191 | 285 |
|
286 |
if (index >= globalindex) { |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
287 |
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
2191 | 288 |
return AL_FALSE; |
289 |
} |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
290 |
|
2213 | 291 |
if (direction == FADE_IN) |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
292 |
#ifndef _WIN32 |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
293 |
pthread_create(&thread, NULL, helper_fadein, (void*) fade); |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
294 |
#else |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
295 |
Thread = _beginthread(&helper_fadein, 0, (void*) fade); |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
296 |
#endif |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
297 |
else { |
2213 | 298 |
if (direction == FADE_OUT) |
2194
1597710c6118
koda adds threading for fadein/out. Untested under windows, but works beautifully under Linux (and presumably OSX, right koda?)
nemo
parents:
2191
diff
changeset
|
299 |
#ifndef _WIN32 |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
300 |
pthread_create(&thread, NULL, helper_fadeout, (void*) fade); |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
301 |
#else |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
302 |
Thread = _beginthread(&helper_fadeout, 0, (void*) fade); |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
303 |
#endif |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
304 |
else { |
2213 | 305 |
fprintf(stderr, "ERROR: unknown direction for fade (%d)\n", direction); |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
306 |
free(fade); |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
307 |
return AL_FALSE; |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
308 |
} |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
309 |
} |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
310 |
|
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
311 |
#ifndef _WIN32 |
2194
1597710c6118
koda adds threading for fadein/out. Untested under windows, but works beautifully under Linux (and presumably OSX, right koda?)
nemo
parents:
2191
diff
changeset
|
312 |
pthread_detach(thread); |
2191 | 313 |
#endif |
314 |
||
315 |
alGetError(); /* clear any AL errors beforehand */ |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
316 |
|
2191 | 317 |
return AL_TRUE; |
318 |
} |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
319 |
|
2191 | 320 |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
321 |
ALint openal_fadeout(int index, unsigned int quantity) { |
2213 | 322 |
/*wrapper for fadeout*/ |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
323 |
return openal_fade(index, quantity, FADE_OUT); |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
324 |
} |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
325 |
|
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
326 |
|
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
327 |
ALint openal_fadein(int index, unsigned int quantity) { |
2213 | 328 |
/*wrapper for fadein*/ |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
329 |
return openal_fade(index, quantity, FADE_IN); |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
330 |
} |
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
331 |
|
2191 | 332 |
|
333 |
ALint openal_playsound(int index){ |
|
334 |
/*Play sound number index*/ |
|
335 |
if (index >= globalindex) { |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
336 |
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
2191 | 337 |
return AL_FALSE; |
338 |
} |
|
339 |
alSourcePlay(Sources[index]); |
|
340 |
if (AlGetError("ERROR %d: Playing last sound\n") != AL_TRUE) |
|
341 |
return AL_FALSE; |
|
342 |
||
343 |
alGetError(); /* clear any AL errors beforehand */ |
|
344 |
||
345 |
return AL_TRUE; |
|
346 |
} |
|
347 |
||
348 |
||
349 |
ALint openal_pausesound(int index){ |
|
350 |
/*Pause sound number index*/ |
|
351 |
if (index >= globalindex) { |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
352 |
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
2191 | 353 |
return AL_FALSE; |
354 |
} |
|
355 |
alSourcePause(Sources[index]); |
|
356 |
if (AlGetError("ERROR %d: Pausing last sound\n") != AL_TRUE) |
|
357 |
return AL_FALSE; |
|
358 |
||
359 |
return AL_TRUE; |
|
360 |
} |
|
361 |
||
362 |
||
363 |
ALint openal_stopsound(int index){ |
|
364 |
/*Stop sound number index*/ |
|
365 |
if (index >= globalindex) { |
|
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
366 |
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
2191 | 367 |
return AL_FALSE; |
368 |
} |
|
369 |
alSourceStop(Sources[index]); |
|
370 |
if (AlGetError("ERROR %d: Stopping last sound\n") != AL_TRUE) |
|
371 |
return AL_FALSE; |
|
372 |
||
373 |
alGetError(); /* clear any AL errors beforehand */ |
|
374 |
||
375 |
return AL_TRUE; |
|
376 |
} |
|
377 |
||
378 |
#ifdef __CPLUSPLUS |
|
379 |
} |
|
380 |
#endif |