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