author | unc0rr |
Sat, 17 Oct 2009 09:31:37 +0000 | |
changeset 2519 | 78956afbd311 |
parent 2501 | 51ebab1b446d |
child 2529 | 51e5df1c8462 |
permissions | -rw-r--r-- |
2191 | 1 |
/* |
2 |
* OpenAL Bridge - a simple portable library for OpenAL interface |
|
2494 | 3 |
* Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com> |
2191 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
2257
7eb31efcfb9b
updates licence and fix a memory leak (which was consuming iphone memory)
koda
parents:
2220
diff
changeset
|
6 |
* it under the terms of the GNU Lesser General Public License as published by |
2191 | 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 |
|
2257
7eb31efcfb9b
updates licence and fix a memory leak (which was consuming iphone memory)
koda
parents:
2220
diff
changeset
|
12 |
* GNU Lesser General Public License for more details. |
2191 | 13 |
* |
2257
7eb31efcfb9b
updates licence and fix a memory leak (which was consuming iphone memory)
koda
parents:
2220
diff
changeset
|
14 |
* You should have received a copy of the GNU Lesser General Public License |
2191 | 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 |
||
2326
0ddf641fddee
rename dpr -> pas, restores ammos on two columns, minor fixes to openalbridge
koda
parents:
2261
diff
changeset
|
19 |
#include "openalbridge.h" |
2418 | 20 |
|
2494 | 21 |
char oalbReady = 0; |
22 |
int iNumSounds = 0; |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
23 |
char *prog; |
2494 | 24 |
/*Sources are points emitting sound*/ |
25 |
ALuint Sources[MAX_SOURCES]; |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
26 |
|
2494 | 27 |
/*structure that holds information about sounds*/ |
28 |
SSound_t *theSounds; |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
29 |
|
2494 | 30 |
ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; /*Position of the source sound*/ |
31 |
ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; /*Velocity of the source sound*/ |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
32 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
33 |
/** |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
34 |
* const char oalb_init (const char* programname, const char usehardware) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
35 |
* |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
36 |
* ARGUMENTS |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
37 |
* programname [const char*]: name of the program invoking OpenAL |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
38 |
* usehardware [const char] : flag to enable audio hardware acceleration |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
39 |
* DESCRIPTION |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
40 |
* |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
41 |
* RETURN |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
42 |
* 1 success |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
43 |
* 2 error |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
44 |
*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
45 |
|
2494 | 46 |
const char oalb_init (const char* programname, const char usehardware) { |
47 |
/*Initialize an OpenAL contex and allocate memory space for data and buffers*/ |
|
48 |
ALCcontext *context; |
|
49 |
ALCdevice *device; |
|
50 |
const ALCchar *default_device; |
|
51 |
int i; |
|
52 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
53 |
prog = (char *) programname; |
2259 | 54 |
|
2494 | 55 |
/*Position of the listener*/ |
56 |
ALfloat ListenerPos[] = {0.0, 0.0, 0.0}; |
|
57 |
/*Velocity of the listener*/ |
|
58 |
ALfloat ListenerVel[] = {0.0, 0.0, 0.0}; |
|
59 |
/*Orientation of the listener. (first 3 elements are "at", second 3 are "up")*/ |
|
60 |
ALfloat ListenerOri[] = {0.0, 0.0, -1.0, 0.0, 1.0, 0.0}; |
|
61 |
||
62 |
if (oalbReady == 1) { |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
63 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
64 |
err_ret("(%s) WARN - OpenAL already initialized", prog); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
65 |
return AL_FALSE; |
2419 | 66 |
} |
2259 | 67 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
68 |
#ifdef _WIN32 |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
69 |
/* Hardware acceleration is broken on some windows card*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
70 |
if (usehardware != 0) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
71 |
device = alcOpenDevice(NULL); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
72 |
else |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
73 |
{ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
74 |
device = alcOpenDevice("Generic Software"); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
75 |
if(!device) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
76 |
{ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
77 |
err_msg("(%s) WARN - Failed to open software device", prog); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
78 |
device = alcOpenDevice(NULL); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
79 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
80 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
81 |
#else |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
82 |
/*always hardware for UNIX systems*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
83 |
device = alcOpenDevice(NULL); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
84 |
#endif |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
85 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
86 |
if (device == NULL) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
87 |
errno = ENODEV; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
88 |
err_ret("(%s) WARN - Failed to open sound device", prog); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
89 |
return AL_FALSE; |
2259 | 90 |
} |
2494 | 91 |
err_msg("(%s) INFO - Output device: %s", prog, alcGetString(device, ALC_DEVICE_SPECIFIER)); |
2259 | 92 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
93 |
context = alcCreateContext(device, NULL); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
94 |
alcMakeContextCurrent(context); |
2494 | 95 |
alcProcessContext(context); |
2259 | 96 |
|
2494 | 97 |
if (AlGetError("(%s) ERROR - Failed to create a new contex") != AL_TRUE) |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
98 |
return AL_FALSE; |
2259 | 99 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
100 |
/*set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation*/ |
2494 | 101 |
alListenerf (AL_GAIN, 1.0f ); |
102 |
alListenerfv(AL_POSITION, ListenerPos); |
|
103 |
alListenerfv(AL_VELOCITY, ListenerVel); |
|
104 |
alListenerfv(AL_ORIENTATION, ListenerOri); |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
105 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
106 |
if (AlGetError("(%s) WARN - Failed to set Listener properties") != AL_TRUE) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
107 |
return AL_FALSE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
108 |
|
2494 | 109 |
theSounds = (SSound_t*) Malloc(sizeof(SSound_t)*MAX_SOUNDS); |
110 |
for (i = 0; i < MAX_SOUNDS; i++) { |
|
111 |
theSounds->isLoaded = 0; |
|
112 |
theSounds->sourceIndex = -1; |
|
113 |
} |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
114 |
|
2494 | 115 |
alGenSources(MAX_SOURCES, Sources); |
116 |
oalbReady = 1; |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
117 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
118 |
alGetError(); /* clear any AL errors beforehand */ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
119 |
return AL_TRUE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
120 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
121 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
122 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
123 |
/** |
2444 | 124 |
* void oalb_close (void) |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
125 |
* |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
126 |
* ARGUMENTS |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
127 |
* - |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
128 |
* DESCRIPTION |
2444 | 129 |
* Stop all sounds, deallocate all memory and close OpenAL |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
130 |
* RETURN |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
131 |
* - |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
132 |
*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
133 |
|
2444 | 134 |
void oalb_close (void) { |
2494 | 135 |
/*Stop all sounds, deallocate all memory and close OpenAL */ |
136 |
ALCcontext *context; |
|
137 |
ALCdevice *device; |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
138 |
int i; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
139 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
140 |
if (oalbReady == 0) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
141 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
142 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
143 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
144 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
145 |
|
2494 | 146 |
alSourceStopv (MAX_SOURCES, Sources); |
147 |
alDeleteSources (MAX_SOURCES, Sources); |
|
148 |
||
149 |
for (i = 0; i < MAX_SOUNDS; i++) { |
|
150 |
free(theSounds[i].filename); |
|
151 |
alDeleteBuffers (1, &theSounds[i].Buffer); |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
152 |
} |
2494 | 153 |
free(theSounds); |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
154 |
|
2494 | 155 |
context = alcGetCurrentContext(); |
156 |
device = alcGetContextsDevice(context); |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
157 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
158 |
alcMakeContextCurrent(NULL); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
159 |
alcDestroyContext(context); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
160 |
alcCloseDevice(device); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
161 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
162 |
oalbReady = 0; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
163 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
164 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
165 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
166 |
|
2444 | 167 |
/** |
168 |
* char oalb_ready (void) |
|
169 |
* |
|
170 |
* ARGUMENTS |
|
171 |
* - |
|
172 |
* DESCRIPTION |
|
173 |
* |
|
174 |
* RETURN |
|
175 |
* - |
|
176 |
*/ |
|
177 |
||
178 |
char oalb_ready (void) { |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
179 |
return oalbReady; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
180 |
} |
2494 | 181 |
/* |
182 |
ALboolean helper_realloc (void) { |
|
183 |
expands allocated memory when loading more sound files than expected |
|
184 |
int oldsize = globalsize; |
|
185 |
globalsize += increment; |
|
186 |
||
187 |
#ifdef DEBUG |
|
188 |
err_msg("(%s) INFO - Realloc in process from %d to %d\n", prog, oldsize, globalsize); |
|
189 |
#endif |
|
190 |
||
191 |
Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize); |
|
192 |
Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize); |
|
193 |
||
194 |
return AL_TRUE; |
|
195 |
}*/ |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
196 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
197 |
/** |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
198 |
* const int32_t oalb_loadfile (const char *filename) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
199 |
* |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
200 |
* ARGUMENTS |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
201 |
* - |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
202 |
* DESCRIPTION |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
203 |
* |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
204 |
* RETURN |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
205 |
* - |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
206 |
*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
207 |
|
2494 | 208 |
const int32_t oalb_loadfile (const char *filename){ |
209 |
/*Open a file, load into memory and allocate the Source buffer for playing*/ |
|
210 |
||
211 |
ALenum format, error; |
|
212 |
ALsizei bitsize, freq; |
|
213 |
char *data; |
|
214 |
int namelength, i; |
|
215 |
uint32_t magic; |
|
216 |
FILE *fp; |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
217 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
218 |
if (oalbReady == 0) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
219 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
220 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
221 |
return -1; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
222 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
223 |
|
2494 | 224 |
/*when the buffers are all used, we can expand memory to accept new files*/ |
225 |
// if (globalindex == globalsize) |
|
226 |
// helper_realloc(); |
|
227 |
||
228 |
namelength=strlen(filename); |
|
229 |
/*if this sound is already loaded return the index from theSounds*/ |
|
230 |
for (i = 0; i < iNumSounds; i++){ |
|
231 |
if (theSounds[iNumSounds].isLoaded == 1) { |
|
232 |
if (strncmp(theSounds[iNumSounds].filename, filename, namelength) == 0) |
|
233 |
return i; |
|
234 |
} |
|
235 |
} |
|
236 |
||
237 |
/*else load it and store it into a theSounds cell*/ |
|
238 |
||
239 |
/*detect the file format, as written in the first 4 bytes of the header*/ |
|
240 |
fp = Fopen (filename, "rb"); |
|
241 |
||
242 |
if (fp == NULL) |
|
243 |
return -1; |
|
244 |
||
245 |
error = fread (&magic, sizeof(uint32_t), 1, fp); |
|
246 |
fclose (fp); |
|
247 |
||
248 |
if (error < 0) { |
|
249 |
errno = EIO; |
|
250 |
err_ret("(%s) ERROR - File %s is too short", prog, filename); |
|
251 |
return -2; |
|
2259 | 252 |
} |
253 |
||
2494 | 254 |
switch (ENDIAN_BIG_32(magic)) { |
255 |
case OGG_FILE_FORMAT: |
|
256 |
error = load_oggvorbis (filename, &format, &data, &bitsize, &freq); |
|
257 |
break; |
|
258 |
case WAV_FILE_FORMAT: |
|
259 |
error = load_wavpcm (filename, &format, &data, &bitsize, &freq); |
|
260 |
break; |
|
261 |
default: |
|
262 |
errno = EINVAL; |
|
263 |
err_ret ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(magic)); |
|
264 |
return -5; |
|
265 |
break; |
|
266 |
} |
|
2259 | 267 |
|
2494 | 268 |
theSounds[iNumSounds].filename = (char*) Malloc(sizeof(char) * namelength); |
269 |
strncpy(theSounds[iNumSounds].filename, filename, namelength); |
|
270 |
theSounds[iNumSounds].isLoaded = 1; |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
271 |
|
2494 | 272 |
/*prepare the buffer to receive data*/ |
273 |
alGenBuffers(1, &theSounds[iNumSounds].Buffer); |
|
274 |
||
275 |
if (AlGetError("(%s) ERROR - Failed to allocate memory for buffers") != AL_TRUE) |
|
276 |
return -3; |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
277 |
|
2494 | 278 |
/*copy pcm data in one buffer*/ |
279 |
alBufferData(theSounds[iNumSounds].Buffer, format, data, bitsize, freq); |
|
280 |
/*deallocate data to save memory*/ |
|
281 |
free(data); |
|
282 |
||
283 |
if (AlGetError("(%s) ERROR - Failed to write data to buffers") != AL_TRUE) |
|
284 |
return -6; |
|
285 |
||
286 |
alGetError(); /* clear any AL errors beforehand */ |
|
287 |
||
288 |
/*returns the index of the source you just loaded, increments it and exits*/ |
|
289 |
return iNumSounds++; |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
290 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
291 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
292 |
|
2494 | 293 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
294 |
void oalb_setvolume (const uint32_t iIndex, const char cPercentage) { |
2494 | 295 |
float percentage; |
296 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
297 |
if (oalbReady == 0) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
298 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
299 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
300 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
301 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
302 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
303 |
/*Set volume for sound number index*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
304 |
if(iIndex < 0 || iIndex >= iNumSounds) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
305 |
errno = EINVAL; |
2446 | 306 |
err_ret("(%s) ERROR - Index (%d) out of bounds", prog, iIndex); |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
307 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
308 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
309 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
310 |
if(cPercentage > 100) |
2494 | 311 |
percentage = 1.0f; |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
312 |
else |
2494 | 313 |
percentage = cPercentage / 100.0f; |
314 |
||
315 |
alSourcef(Sources[theSounds[iIndex].sourceIndex], AL_GAIN, percentage); |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
316 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
317 |
if (AlGetError2("(%s) ERROR - Failed to set volume for sound %d\n", iIndex) != AL_TRUE) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
318 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
319 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
320 |
alGetError(); /* clear any AL errors beforehand */ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
321 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
322 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
323 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
324 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
325 |
|
2494 | 326 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
327 |
void oalb_setglobalvolume (const char cPercentage) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
328 |
if (oalbReady == 0) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
329 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
330 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
331 |
return; |
2419 | 332 |
} |
333 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
334 |
/*Set volume for all sounds*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
335 |
if(cPercentage > 100) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
336 |
alListenerf (AL_GAIN, 1.0f); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
337 |
else |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
338 |
alListenerf (AL_GAIN, cPercentage / 100.0f); |
2259 | 339 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
340 |
if (AlGetError("(%s) ERROR - Failed to set global volume") != AL_TRUE) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
341 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
342 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
343 |
alGetError(); /* clear any AL errors beforehand */ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
344 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
345 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
346 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
347 |
|
2444 | 348 |
void oalb_togglemute (void) { |
349 |
/*Mute or unmute sound*/ |
|
350 |
ALfloat mute; |
|
351 |
||
352 |
if (oalbReady == AL_FALSE) { |
|
353 |
errno = EPERM; |
|
354 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
355 |
return; |
|
356 |
} |
|
357 |
||
358 |
alGetListenerf (AL_GAIN, &mute); |
|
359 |
if (mute > 0) |
|
360 |
mute = 0; |
|
361 |
else |
|
362 |
mute = 1.0; |
|
363 |
||
364 |
alListenerf (AL_GAIN, mute); |
|
365 |
||
366 |
if (AlGetError("(%s) ERROR - Failed to set mute property") != AL_TRUE) |
|
367 |
return; |
|
368 |
||
369 |
alGetError(); /* clear any AL errors beforehand */ |
|
370 |
||
371 |
return; |
|
372 |
} |
|
2494 | 373 |
|
374 |
||
375 |
void oalb_fade (uint32_t iIndex, uint16_t quantity, ALboolean direction) { |
|
376 |
/*Fade in or out by calling a helper thread*/ |
|
377 |
#ifndef _WIN32 |
|
378 |
pthread_t thread; |
|
379 |
#else |
|
380 |
HANDLE Thread; |
|
381 |
DWORD threadID; |
|
382 |
#endif |
|
383 |
fade_t *fade; |
|
384 |
||
385 |
if (oalbReady == 0) { |
|
386 |
errno = EPERM; |
|
387 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
388 |
return ; |
|
389 |
} |
|
390 |
||
391 |
fade = (fade_t*) Malloc(sizeof(fade_t)); |
|
2501 | 392 |
fade->index = theSounds[iIndex].sourceIndex; |
2494 | 393 |
fade->quantity = quantity; |
394 |
||
395 |
if(iIndex < 0 || iIndex >= iNumSounds) { |
|
396 |
errno = EINVAL; |
|
397 |
err_ret("(%s) ERROR - Index (%d) out of bounds", prog, iIndex); |
|
398 |
return; |
|
399 |
} |
|
400 |
||
401 |
switch (direction) { |
|
402 |
case FADE_IN: |
|
403 |
#ifndef _WIN32 |
|
404 |
pthread_create(&thread, NULL, helper_fadein, (void*) fade); |
|
405 |
#else |
|
406 |
Thread = _beginthread(&helper_fadein, 0, (void*) fade); |
|
407 |
#endif |
|
408 |
break; |
|
409 |
case FADE_OUT: |
|
410 |
#ifndef _WIN32 |
|
411 |
pthread_create(&thread, NULL, helper_fadeout, (void*) fade); |
|
412 |
#else |
|
413 |
Thread = _beginthread(&helper_fadeout, 0, (void*) fade); |
|
414 |
#endif |
|
415 |
break; |
|
416 |
default: |
|
417 |
errno = EINVAL; |
|
2496 | 418 |
err_ret("(%s) ERROR - Unknown direction for fading", prog, iIndex); |
2494 | 419 |
free(fade); |
420 |
return; |
|
421 |
break; |
|
422 |
} |
|
423 |
||
424 |
#ifndef _WIN32 |
|
425 |
pthread_detach(thread); |
|
426 |
#endif |
|
427 |
||
428 |
alGetError(); /* clear any AL errors beforehand */ |
|
429 |
||
430 |
return; |
|
431 |
} |
|
432 |
||
433 |
||
434 |
void oalb_fadeout (uint32_t index, uint16_t quantity) { |
|
435 |
/*wrapper for fadeout*/ |
|
436 |
oalb_fade(index, quantity, FADE_OUT); |
|
437 |
return; |
|
438 |
} |
|
439 |
||
440 |
||
441 |
void oalb_fadein (uint32_t index, uint16_t quantity) { |
|
442 |
/*wrapper for fadein*/ |
|
443 |
oalb_fade(index, quantity, FADE_IN); |
|
444 |
return; |
|
445 |
} |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
446 |
|
2494 | 447 |
|
448 |
/* ALboolean openal_setposition (uint32_t index, float x, float y, float z) { |
|
449 |
if (openalReady == AL_FALSE) { |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
450 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
451 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
452 |
return AL_FALSE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
453 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
454 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
455 |
if (index >= globalsize) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
456 |
errno = EINVAL; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
457 |
err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
458 |
return AL_FALSE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
459 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
460 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
461 |
alSource3f(Sources[index], AL_POSITION, x, y, z); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
462 |
if (AlGetError2("(%s) ERROR - Failed to set position for sound %d)", index) != AL_TRUE) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
463 |
return AL_FALSE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
464 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
465 |
return AL_TRUE; |
2494 | 466 |
}*/ |
467 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
468 |
|
2494 | 469 |
void oalb_playsound (const uint32_t iIndex, const char bLoop){ |
470 |
int findNewSource; |
|
471 |
int i, j, state; |
|
472 |
||
473 |
if (oalbReady == 0) { |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
474 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
475 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
476 |
return; |
2419 | 477 |
} |
478 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
479 |
/*Play sound number index*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
480 |
if(iIndex < 0 || iIndex >= iNumSounds) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
481 |
errno = EINVAL; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
482 |
err_ret("(%s) ERROR - Index (%d) out of bounds", prog, iIndex); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
483 |
return; |
2419 | 484 |
} |
2494 | 485 |
|
486 |
/*check if sound has already a source*/ |
|
487 |
if (theSounds[iIndex].sourceIndex == -1) { |
|
488 |
/*needs a new source*/ |
|
489 |
findNewSource = 1; |
|
490 |
} else { |
|
491 |
/*already has a source -- check it's not playing*/ |
|
492 |
alGetSourcei(Sources[theSounds[iIndex].sourceIndex], AL_SOURCE_STATE, &state); |
|
493 |
if(state == AL_PLAYING || state == AL_PAUSED) { |
|
494 |
/*it is being played, so we have to allocate a new source*/ |
|
495 |
findNewSource = 1; |
|
496 |
} else { |
|
497 |
/*it is not being played, so we can use it safely*/ |
|
498 |
findNewSource = 0; |
|
499 |
} |
|
500 |
} |
|
2259 | 501 |
|
2494 | 502 |
if (findNewSource == 1) { |
503 |
#ifdef DEBUG |
|
504 |
err_msg("(%s) DEBUG - Looking for a source for sound %d", prog, iIndex); |
|
505 |
#endif |
|
506 |
for (i = 0; i < MAX_SOURCES; i++) { |
|
507 |
alGetSourcei(Sources[i], AL_SOURCE_STATE, &state); |
|
508 |
if(state != AL_PLAYING && state != AL_PAUSED) { |
|
509 |
// alSourceStop(Sources[i]); |
|
510 |
// alGetError(); |
|
511 |
for(j = 0; j < iNumSounds; j++) |
|
512 |
if(theSounds[j].isLoaded && theSounds[j].sourceIndex == i) |
|
513 |
theSounds[j].sourceIndex = -1; |
|
514 |
break; |
|
515 |
} else { |
|
516 |
//TODO: what happens when all 16 sources are busy? |
|
517 |
} |
|
518 |
} |
|
519 |
theSounds[iIndex].sourceIndex = i; |
|
520 |
} |
|
2259 | 521 |
|
2494 | 522 |
alSourcei (Sources[theSounds[iIndex].sourceIndex], AL_BUFFER, theSounds[iIndex].Buffer); |
523 |
alSourcef (Sources[theSounds[iIndex].sourceIndex], AL_PITCH, 1.0f ); |
|
524 |
alSourcef (Sources[theSounds[iIndex].sourceIndex], AL_GAIN, 1.0f ); |
|
525 |
alSourcefv(Sources[theSounds[iIndex].sourceIndex], AL_POSITION, SourcePos ); |
|
526 |
alSourcefv(Sources[theSounds[iIndex].sourceIndex], AL_VELOCITY, SourceVel ); |
|
527 |
alSourcei (Sources[theSounds[iIndex].sourceIndex], AL_LOOPING, bLoop ); |
|
528 |
if (AlGetError("(%s) ERROR - Failed to set Source properties") != AL_TRUE) |
|
529 |
return; |
|
530 |
||
531 |
alSourcePlay(Sources[theSounds[iIndex].sourceIndex]); |
|
532 |
if (AlGetError2("(%s) ERROR - Failed to play sound %d)", iIndex) != AL_TRUE) |
|
533 |
return; |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
534 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
535 |
alGetError(); /* clear any AL errors beforehand */ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
536 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
537 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
538 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
539 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
540 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
541 |
void oalb_pausesound (const uint32_t iIndex) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
542 |
if (oalbReady == AL_FALSE) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
543 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
544 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
545 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
546 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
547 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
548 |
/*Pause sound number index*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
549 |
if(iIndex < 0 || iIndex >= iNumSounds) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
550 |
errno = EINVAL; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
551 |
err_ret("(%s) ERROR - Index (%d) out of bounds", prog, iIndex); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
552 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
553 |
} |
2494 | 554 |
alSourcePause(Sources[theSounds[iIndex].sourceIndex]); |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
555 |
if (AlGetError2("(%s) ERROR - Failed to pause sound %d)", iIndex) != AL_TRUE) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
556 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
557 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
558 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
559 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
560 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
561 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
562 |
void oalb_stopsound (const uint32_t iIndex) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
563 |
if (oalbReady == AL_FALSE) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
564 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
565 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
566 |
return; |
2419 | 567 |
} |
2259 | 568 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
569 |
/*Stop sound number index*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
570 |
if(iIndex < 0 || iIndex >= iNumSounds) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
571 |
errno = EINVAL; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
572 |
err_ret("(%s) ERROR - Index (%d) out of bounds", prog, iIndex); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
573 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
574 |
} |
2494 | 575 |
alSourceStop(Sources[theSounds[iIndex].sourceIndex]); |
2415 | 576 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
577 |
if (AlGetError2("(%s) ERROR - Failed to stop sound %d)", iIndex) != AL_TRUE) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
578 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
579 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
580 |
alGetError(); /* clear any AL errors beforehand */ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
581 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
582 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
583 |
} |