106 alGetError(); /* clear any AL errors beforehand */ |
106 alGetError(); /* clear any AL errors beforehand */ |
107 return AL_TRUE; |
107 return AL_TRUE; |
108 } |
108 } |
109 |
109 |
110 |
110 |
111 int helper_realloc (void) { |
111 uint8_t helper_realloc (void) { |
112 /*expands allocated memory when loading more sound files than expected*/ |
112 /*expands allocated memory when loading more sound files than expected*/ |
113 globalsize += increment; |
113 globalsize += increment; |
114 #ifdef DEBUG |
114 #ifdef DEBUG |
115 fprintf(stderr, "OpenAL: Realloc in process %d\n", globalsize); |
115 fprintf(stderr, "OpenAL: Realloc in process %d\n", globalsize); |
116 #endif |
116 #endif |
119 |
119 |
120 return 0; |
120 return 0; |
121 } |
121 } |
122 |
122 |
123 |
123 |
124 int openal_loadfile (const char *filename){ |
124 uint32_t openal_loadfile (const char *filename){ |
125 /*Open a file, load into memory and allocate the Source buffer for playing*/ |
125 /*Open a file, load into memory and allocate the Source buffer for playing*/ |
126 ALenum format; |
126 ALenum format; |
127 ALsizei bitsize; |
127 ALsizei bitsize; |
128 ALsizei freq; |
128 ALsizei freq; |
129 char *data; |
129 char *data; |
130 uint32_t fileformat; |
130 uint32_t fileformat; |
131 int error; |
131 ALenum error; |
132 FILE *fp; |
132 FILE *fp; |
133 |
133 |
134 |
134 |
135 /*when the buffers are all used, we can expand memory to accept new files*/ |
135 /*when the buffers are all used, we can expand memory to accept new files*/ |
136 if (globalindex == globalsize) |
136 if (globalindex == globalsize) |
195 /*returns the index of the source you just loaded, increments it and exits*/ |
195 /*returns the index of the source you just loaded, increments it and exits*/ |
196 return globalindex++; |
196 return globalindex++; |
197 } |
197 } |
198 |
198 |
199 |
199 |
200 ALint openal_toggleloop (int index){ |
200 ALint openal_toggleloop (uint32_t index){ |
201 /*Set or unset looping mode*/ |
201 /*Set or unset looping mode*/ |
202 ALint loop; |
202 ALint loop; |
203 |
203 |
204 if (index >= globalsize) { |
204 if (index >= globalsize) { |
205 fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
205 fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
215 |
215 |
216 return AL_TRUE; |
216 return AL_TRUE; |
217 } |
217 } |
218 |
218 |
219 |
219 |
220 ALint openal_setvolume (int index, unsigned char percentage) { |
220 ALint openal_setvolume (uint32_t index, uint8_t percentage) { |
221 /*Set volume for sound number index*/ |
221 /*Set volume for sound number index*/ |
222 if (index >= globalindex) { |
222 if (index >= globalindex) { |
223 fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
223 fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
224 return AL_FALSE; |
224 return AL_FALSE; |
225 } |
225 } |
234 |
234 |
235 return AL_TRUE; |
235 return AL_TRUE; |
236 } |
236 } |
237 |
237 |
238 |
238 |
239 ALint openal_setglobalvolume (unsigned char percentage) { |
239 ALint openal_setglobalvolume (uint8_t percentage) { |
240 /*Set volume for all sounds*/ |
240 /*Set volume for all sounds*/ |
241 if (percentage > 100) |
241 if (percentage > 100) |
242 percentage = 100; |
242 percentage = 100; |
243 alListenerf (AL_GAIN, (float) percentage/100.0f); |
243 alListenerf (AL_GAIN, (float) percentage/100.0f); |
244 if (AlGetError("ERROR %d: Setting global volume\n") != AL_TRUE) |
244 if (AlGetError("ERROR %d: Setting global volume\n") != AL_TRUE) |
316 |
316 |
317 return AL_TRUE; |
317 return AL_TRUE; |
318 } |
318 } |
319 |
319 |
320 |
320 |
321 ALint openal_fadeout(int index, unsigned int quantity) { |
321 ALint openal_fadeout(uint32_t index, uint16_t quantity) { |
322 /*wrapper for fadeout*/ |
322 /*wrapper for fadeout*/ |
323 return openal_fade(index, quantity, FADE_OUT); |
323 return openal_fade(index, quantity, FADE_OUT); |
324 } |
324 } |
325 |
325 |
326 |
326 |
327 ALint openal_fadein(int index, unsigned int quantity) { |
327 ALint openal_fadein(uint32_t index, uint16_t quantity) { |
328 /*wrapper for fadein*/ |
328 /*wrapper for fadein*/ |
329 return openal_fade(index, quantity, FADE_IN); |
329 return openal_fade(index, quantity, FADE_IN); |
330 } |
330 } |
331 |
331 |
332 |
332 |
333 ALint openal_playsound(int index){ |
333 ALint openal_playsound(uint32_t index){ |
334 /*Play sound number index*/ |
334 /*Play sound number index*/ |
335 if (index >= globalindex) { |
335 if (index >= globalindex) { |
336 fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
336 fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
337 return AL_FALSE; |
337 return AL_FALSE; |
338 } |
338 } |
344 |
344 |
345 return AL_TRUE; |
345 return AL_TRUE; |
346 } |
346 } |
347 |
347 |
348 |
348 |
349 ALint openal_pausesound(int index){ |
349 ALint openal_pausesound(uint32_t index){ |
350 /*Pause sound number index*/ |
350 /*Pause sound number index*/ |
351 if (index >= globalindex) { |
351 if (index >= globalindex) { |
352 fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
352 fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
353 return AL_FALSE; |
353 return AL_FALSE; |
354 } |
354 } |
358 |
358 |
359 return AL_TRUE; |
359 return AL_TRUE; |
360 } |
360 } |
361 |
361 |
362 |
362 |
363 ALint openal_stopsound(int index){ |
363 ALint openal_stopsound(uint32_t index){ |
364 /*Stop sound number index*/ |
364 /*Stop sound number index*/ |
365 if (index >= globalindex) { |
365 if (index >= globalindex) { |
366 fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
366 fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
367 return AL_FALSE; |
367 return AL_FALSE; |
368 } |
368 } |