author | koda |
Wed, 14 Oct 2009 22:12:02 +0000 | |
changeset 2443 | fececcbc2189 |
parent 2437 | 10e4b5fc0d93 |
child 2444 | ace11b7d8eab |
permissions | -rw-r--r-- |
2191 | 1 |
/* |
2 |
* OpenAL Bridge - a simple portable library for OpenAL interface |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
3 |
* Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>, |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
4 |
* Mario Liebisch <mario.liebisch+hw@googlemail.com> |
2191 | 5 |
* |
6 |
* 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
|
7 |
* it under the terms of the GNU Lesser General Public License as published by |
2191 | 8 |
* the Free Software Foundation; version 2 of the License |
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* 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
|
13 |
* GNU Lesser General Public License for more details. |
2191 | 14 |
* |
2257
7eb31efcfb9b
updates licence and fix a memory leak (which was consuming iphone memory)
koda
parents:
2220
diff
changeset
|
15 |
* You should have received a copy of the GNU Lesser General Public License |
2191 | 16 |
* along with this program; if not, write to the Free Software |
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
18 |
*/ |
|
19 |
||
2326
0ddf641fddee
rename dpr -> pas, restores ammos on two columns, minor fixes to openalbridge
koda
parents:
2261
diff
changeset
|
20 |
#include "openalbridge.h" |
2418 | 21 |
|
2191 | 22 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
23 |
char *prog; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
24 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
25 |
/*Buffers hold sound data*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
26 |
ALuint *Buffers; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
27 |
/*index for Sources and Buffers*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
28 |
ALuint globalindex, globalsize, increment; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
29 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
30 |
//null vector |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
31 |
const ALfloat NV[] = {0.0f, 0.0f, 0.0f}; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
32 |
//listener orientation |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
33 |
const ALfloat LO[] = {0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f}; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
34 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
35 |
SSound_t aSounds[MAX_SOUNDS]; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
36 |
int iNumSounds = 0; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
37 |
char oalbReady = 0; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
38 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
39 |
ALCcontext *context; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
40 |
ALCdevice *device; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
41 |
ALuint sources[MAX_SOURCES]; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
42 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
43 |
|
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 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
46 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
47 |
/** |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
48 |
* 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
|
49 |
* |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
50 |
* ARGUMENTS |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
51 |
* 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
|
52 |
* 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
|
53 |
* DESCRIPTION |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
54 |
* |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
55 |
* RETURN |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
56 |
* 1 success |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
57 |
* 2 error |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
58 |
*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
59 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
60 |
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
|
61 |
prog = (char *) programname; |
2259 | 62 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
63 |
if (oalbReady == AL_TRUE) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
64 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
65 |
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
|
66 |
return AL_FALSE; |
2419 | 67 |
} |
2259 | 68 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
69 |
#ifdef _WIN32 |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
70 |
/* 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
|
71 |
if (usehardware != 0) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
72 |
device = alcOpenDevice(NULL); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
73 |
else |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
74 |
{ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
75 |
device = alcOpenDevice("Generic Software"); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
76 |
if(!device) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
77 |
{ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
78 |
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
|
79 |
device = alcOpenDevice(NULL); |
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 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
82 |
#else |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
83 |
/*always hardware for UNIX systems*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
84 |
device = alcOpenDevice(NULL); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
85 |
#endif |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
86 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
87 |
if (device == NULL) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
88 |
errno = ENODEV; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
89 |
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
|
90 |
return AL_FALSE; |
2259 | 91 |
} |
92 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
93 |
err_msg("(%s) INFO - Using OpenAL device: %s", prog, alcGetString(device, ALC_DEVICE_SPECIFIER)); |
2259 | 94 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
95 |
context = alcCreateContext(device, NULL); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
96 |
alcMakeContextCurrent(context); |
2259 | 97 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
98 |
if (AlGetError("(%s) WARN - Failed to create a new contex") != AL_TRUE) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
99 |
return AL_FALSE; |
2259 | 100 |
|
101 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
102 |
/*set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
103 |
alListenerf (AL_GAIN, 1.0f); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
104 |
alListenerfv(AL_POSITION, NV); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
105 |
alListenerfv(AL_VELOCITY, NV); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
106 |
alListenerfv(AL_ORIENTATION, LO); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
107 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
108 |
alcProcessContext(context); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
109 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
110 |
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
|
111 |
return AL_FALSE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
112 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
113 |
alGenSources(MAX_SOURCES, sources); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
114 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
115 |
oalbReady = AL_TRUE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
116 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
117 |
alGetError(); /* clear any AL errors beforehand */ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
118 |
return AL_TRUE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
119 |
} |
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 |
* void oalb_close(void) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
124 |
* |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
125 |
* ARGUMENTS |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
126 |
* - |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
127 |
* DESCRIPTION |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
128 |
* |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
129 |
* RETURN |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
130 |
* - |
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 |
void oalb_close(void) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
134 |
/*Stop all sounds, deallocate all memory and close OpenAL */ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
135 |
int i; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
136 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
137 |
if (oalbReady == 0) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
138 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
139 |
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
|
140 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
141 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
142 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
143 |
for(i = 0; i < iNumSounds; i++) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
144 |
SSound_stop(&aSounds[i]); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
145 |
SSound_close(&aSounds[i]); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
146 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
147 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
148 |
alSourceStopv (MAX_SOURCES, sources); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
149 |
alDeleteSources (MAX_SOURCES, sources); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
150 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
151 |
alcMakeContextCurrent(NULL); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
152 |
alcDestroyContext(context); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
153 |
alcCloseDevice(device); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
154 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
155 |
oalbReady = 0; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
156 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
157 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
158 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
159 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
160 |
char oalb_ready(void) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
161 |
return oalbReady; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
162 |
} |
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 |
/** |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
165 |
* 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
|
166 |
* |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
167 |
* ARGUMENTS |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
168 |
* - |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
169 |
* DESCRIPTION |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
170 |
* |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
171 |
* RETURN |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
172 |
* - |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
173 |
*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
174 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
175 |
int32_t oalb_loadfile (const char *filename) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
176 |
int i; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
177 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
178 |
if (oalbReady == 0) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
179 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
180 |
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
|
181 |
return -1; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
182 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
183 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
184 |
if(iNumSounds == MAX_SOUNDS) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
185 |
err_msg("(%s) WARN - Maximum number of sound samples reached", prog); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
186 |
return -3; |
2259 | 187 |
} |
188 |
||
189 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
190 |
for(i = 0; i < iNumSounds; i++) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
191 |
if(strcmp(aSounds[i].Filename, filename) == 0) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
192 |
return i; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
193 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
194 |
if(SSound_load(&aSounds[iNumSounds], filename)) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
195 |
return iNumSounds++; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
196 |
else |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
197 |
return -2; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
198 |
|
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 |
|
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 |
ALboolean openal_toggleloop (uint32_t index){ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
203 |
/*Set or unset looping mode |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
204 |
ALint loop; |
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 |
if (oalbReady == AL_FALSE) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
207 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
208 |
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
|
209 |
return AL_FALSE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
210 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
211 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
212 |
if (index >= globalsize) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
213 |
errno = EINVAL; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
214 |
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
|
215 |
return AL_FALSE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
216 |
} |
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 |
alGetSourcei (Sources[index], AL_LOOPING, &loop); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
219 |
alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
220 |
if (AlGetError("(%s) ERROR - Failed to get or set loop property") != AL_TRUE) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
221 |
return AL_FALSE; |
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 |
alGetError(); /* clear any AL errors beforehand |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
224 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
225 |
return AL_TRUE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
226 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
227 |
*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
228 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
229 |
void oalb_setvolume (const uint32_t iIndex, const char cPercentage) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
230 |
if (oalbReady == 0) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
231 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
232 |
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
|
233 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
234 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
235 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
236 |
/*Set volume for sound number index*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
237 |
if(iIndex < 0 || iIndex >= iNumSounds) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
238 |
errno = EINVAL; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
239 |
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
|
240 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
241 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
242 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
243 |
if(cPercentage > 100) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
244 |
SSound_volume(&aSounds[iIndex], 1.0f); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
245 |
else |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
246 |
SSound_volume(&aSounds[iIndex], cPercentage / 100.0f); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
247 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
248 |
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
|
249 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
250 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
251 |
alGetError(); /* clear any AL errors beforehand */ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
252 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
253 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
254 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
255 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
256 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
257 |
void oalb_setglobalvolume (const char cPercentage) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
258 |
if (oalbReady == 0) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
259 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
260 |
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
|
261 |
return; |
2419 | 262 |
} |
263 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
264 |
/*Set volume for all sounds*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
265 |
if(cPercentage > 100) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
266 |
alListenerf (AL_GAIN, 1.0f); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
267 |
else |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
268 |
alListenerf (AL_GAIN, cPercentage / 100.0f); |
2259 | 269 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
270 |
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
|
271 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
272 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
273 |
alGetError(); /* clear any AL errors beforehand */ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
274 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
275 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
276 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
277 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
278 |
/* |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
279 |
ALboolean openal_togglemute () { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
280 |
/*Mute or unmute sound |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
281 |
ALfloat mute; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
282 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
283 |
if (oalbReady == AL_FALSE) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
284 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
285 |
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
|
286 |
return AL_FALSE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
287 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
288 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
289 |
alGetListenerf (AL_GAIN, &mute); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
290 |
if (mute > 0) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
291 |
mute = 0; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
292 |
else |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
293 |
mute = 1.0; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
294 |
alListenerf (AL_GAIN, mute); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
295 |
if (AlGetError("(%s) ERROR - Failed to set mute property") != AL_TRUE) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
296 |
return AL_FALSE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
297 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
298 |
alGetError(); /* clear any AL errors beforehand |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
299 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
300 |
return AL_TRUE; |
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 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
304 |
ALboolean openal_fade (uint32_t index, uint16_t quantity, ALboolean direction) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
305 |
/*Fade in or out by calling a helper thread |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
306 |
#ifndef _WIN32 |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
307 |
pthread_t thread; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
308 |
#else |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
309 |
HANDLE Thread; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
310 |
DWORD threadID; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
311 |
#endif |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
312 |
fade_t *fade; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
313 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
314 |
if (oalbReady == AL_FALSE) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
315 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
316 |
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
|
317 |
return AL_FALSE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
318 |
} |
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 |
fade = (fade_t*) Malloc(sizeof(fade_t)); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
321 |
fade->index = index; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
322 |
fade->quantity = quantity; |
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 |
if (index >= globalsize) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
325 |
errno = EINVAL; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
326 |
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
|
327 |
return AL_FALSE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
328 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
329 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
330 |
switch (direction) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
331 |
case FADE_IN: |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
332 |
#ifndef _WIN32 |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
333 |
pthread_create(&thread, NULL, helper_fadein, (void*) fade); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
334 |
#else |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
335 |
Thread = _beginthread(&helper_fadein, 0, (void*) fade); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
336 |
#endif |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
337 |
break; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
338 |
case FADE_OUT: |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
339 |
#ifndef _WIN32 |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
340 |
pthread_create(&thread, NULL, helper_fadeout, (void*) fade); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
341 |
#else |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
342 |
Thread = _beginthread(&helper_fadeout, 0, (void*) fade); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
343 |
#endif |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
344 |
break; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
345 |
default: |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
346 |
errno = EINVAL; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
347 |
err_ret("(%s) ERROR - Unknown direction for fading", prog, index, globalindex); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
348 |
free(fade); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
349 |
return AL_FALSE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
350 |
break; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
351 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
352 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
353 |
#ifndef _WIN32 |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
354 |
pthread_detach(thread); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
355 |
#endif |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
356 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
357 |
alGetError(); /* clear any AL errors beforehand |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
358 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
359 |
return AL_TRUE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
360 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
361 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
362 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
363 |
ALboolean openal_fadeout (uint32_t index, uint16_t quantity) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
364 |
/*wrapper for fadeout |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
365 |
return openal_fade(index, quantity, FADE_OUT); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
366 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
367 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
368 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
369 |
ALboolean openal_fadein (uint32_t index, uint16_t quantity) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
370 |
/*wrapper for fadein |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
371 |
return openal_fade(index, quantity, FADE_IN); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
372 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
373 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
374 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
375 |
ALboolean openal_setposition (uint32_t index, float x, float y, float z) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
376 |
if (oalbReady == AL_FALSE) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
377 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
378 |
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
|
379 |
return AL_FALSE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
380 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
381 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
382 |
if (index >= globalsize) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
383 |
errno = EINVAL; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
384 |
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
|
385 |
return AL_FALSE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
386 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
387 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
388 |
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
|
389 |
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
|
390 |
return AL_FALSE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
391 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
392 |
return AL_TRUE; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
393 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
394 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
395 |
*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
396 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
397 |
void oalb_playsound (const uint32_t iIndex, const char bLoop) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
398 |
if (oalbReady == AL_FALSE) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
399 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
400 |
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
|
401 |
return; |
2419 | 402 |
} |
403 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
404 |
/*Play sound number index*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
405 |
if(iIndex < 0 || iIndex >= iNumSounds) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
406 |
errno = EINVAL; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
407 |
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
|
408 |
return; |
2419 | 409 |
} |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
410 |
SSound_play(&aSounds[iIndex], bLoop); |
2259 | 411 |
|
412 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
413 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
414 |
alGetError(); /* clear any AL errors beforehand */ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
415 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
416 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
417 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
418 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
419 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
420 |
void oalb_pausesound (const uint32_t iIndex) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
421 |
if (oalbReady == AL_FALSE) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
422 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
423 |
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
|
424 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
425 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
426 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
427 |
/*Pause sound number index*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
428 |
if(iIndex < 0 || iIndex >= iNumSounds) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
429 |
errno = EINVAL; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
430 |
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
|
431 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
432 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
433 |
SSound_pause(&aSounds[iIndex]); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
434 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
435 |
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
|
436 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
437 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
438 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
439 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
440 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
441 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
442 |
void oalb_stopsound (const uint32_t iIndex) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
443 |
if (oalbReady == AL_FALSE) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
444 |
errno = EPERM; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
445 |
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
|
446 |
return; |
2419 | 447 |
} |
2259 | 448 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
449 |
/*Stop sound number index*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
450 |
if(iIndex < 0 || iIndex >= iNumSounds) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
451 |
errno = EINVAL; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
452 |
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
|
453 |
return; |
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 |
SSound_stop(&aSounds[iIndex]); |
2415 | 456 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
457 |
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
|
458 |
return; |
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 |
alGetError(); /* clear any AL errors beforehand */ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
461 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
462 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
463 |
} |
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 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
466 |
/*SSOUND STUFF HERE*/ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
467 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
468 |
char SSound_load (SSound_t* pSound, const char* cFilename) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
469 |
uint32_t magic; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
470 |
ALenum format; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
471 |
ALsizei bitsize, freq; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
472 |
char *data; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
473 |
FILE* fp; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
474 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
475 |
snprintf(pSound->Filename, 256, "%s", cFilename); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
476 |
pSound->source = -1; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
477 |
alGenBuffers(1, &pSound->Buffer); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
478 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
479 |
if(alGetError() != AL_NO_ERROR) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
480 |
fprintf(stderr, "CSound: Couldn't create buffer.\n"); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
481 |
return 0; |
2419 | 482 |
} |
483 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
484 |
fp = fopen(pSound->Filename, "rb"); |
2419 | 485 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
486 |
if(!fp) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
487 |
fprintf(stderr, "CSound: Couldn't open file for reading.\n"); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
488 |
return 0; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
489 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
490 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
491 |
if(fread(&magic, sizeof(uint32_t), 1, fp) < 1) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
492 |
{ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
493 |
fclose(fp); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
494 |
fprintf(stderr, "CSound: Couldn't read file header.\n"); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
495 |
return 0; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
496 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
497 |
fclose(fp); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
498 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
499 |
switch (ENDIAN_BIG_32(magic)) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
500 |
case OGG_FILE_FORMAT: |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
501 |
load_oggvorbis (pSound->Filename, &format, &data, &bitsize, &freq); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
502 |
break; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
503 |
case WAV_FILE_FORMAT: |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
504 |
load_wavpcm (pSound->Filename, &format, &data, &bitsize, &freq); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
505 |
break; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
506 |
default: |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
507 |
errno = EINVAL; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
508 |
err_ret ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(magic)); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
509 |
return 0; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
510 |
break; |
2259 | 511 |
} |
512 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
513 |
alBufferData(pSound->Buffer, format, data, bitsize, freq); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
514 |
if(alGetError() != AL_NO_ERROR) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
515 |
{ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
516 |
fprintf(stderr, "CSound: Couldn't write buffer data.\n"); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
517 |
return 0; |
2419 | 518 |
} |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
519 |
free(data); |
2259 | 520 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
521 |
return 1; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
522 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
523 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
524 |
void SSound_close(SSound_t* pSound) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
525 |
{ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
526 |
SSound_stop(pSound); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
527 |
alDeleteBuffers(1, &pSound->Buffer); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
528 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
529 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
530 |
void SSound_play(SSound_t* pSound, const char bLoop) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
531 |
int i; |
2259 | 532 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
533 |
if(pSound->source == -1) // need a new source |
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 |
int i; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
536 |
for(i = 0; i < MAX_SOURCES; i++) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
537 |
{ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
538 |
ALint state; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
539 |
alGetSourcei(sources[i], AL_SOURCE_STATE, &state); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
540 |
if(state != AL_PLAYING && state != AL_PAUSED) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
541 |
{ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
542 |
#ifdef DEBUG |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
543 |
printf("using source %d (state 0x%x) for buffer.\n", i, state); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
544 |
#endif |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
545 |
alSourceStop(sources[pSound->source]); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
546 |
alGetError(); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
547 |
break; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
548 |
} |
2419 | 549 |
} |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
550 |
if(i == MAX_SOURCES) // no available source found; skip |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
551 |
{ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
552 |
#ifdef DEBUG |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
553 |
printf("no source to play buffer %d!\n", i); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
554 |
#endif |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
555 |
return; |
2419 | 556 |
} |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
557 |
pSound->source = i; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
558 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
559 |
else // reuse already playing source |
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 |
alSourceStop(sources[pSound->source]); |
2259 | 562 |
} |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
563 |
alSourcei (sources[pSound->source], AL_BUFFER, pSound->Buffer); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
564 |
alSourcef (sources[pSound->source], AL_PITCH, 1.0f); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
565 |
alSourcef (sources[pSound->source], AL_GAIN, 1.0f); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
566 |
alSourcefv(sources[pSound->source], AL_POSITION, NV ); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
567 |
alSourcefv(sources[pSound->source], AL_VELOCITY, NV ); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
568 |
alSourcei (sources[pSound->source], AL_LOOPING, bLoop ); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
569 |
alSourcePlay(sources[pSound->source]); |
2259 | 570 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
571 |
if((i = alGetError()) != AL_NO_ERROR) |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
572 |
{ |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
573 |
fprintf(stderr, "CSound: SourcePlay error 0x%4x in source %d\n", i, pSound->source); |
2419 | 574 |
} |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
575 |
#ifdef DEBUG |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
576 |
fprintf(stderr, "play %s%s [%d]\n", pSound->Filename, bLoop ? " forever" : " once", pSound->source); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
577 |
#endif |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
578 |
} |
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 |
void SSound_pause(const SSound_t* pSound) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
581 |
if(pSound->source == -1) // not playing |
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 |
alSourcePause(sources[pSound->source]); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
584 |
#ifdef DEBUG |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
585 |
fprintf(stderr, "pause %s\n", pSound->Filename); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
586 |
#endif |
2191 | 587 |
} |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
588 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
589 |
void SSound_continue(const SSound_t* pSound) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
590 |
if(pSound->source == -1) // not playing |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
591 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
592 |
alSourcePlay(sources[pSound->source]); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
593 |
#ifdef DEBUG |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
594 |
fprintf(stderr, "pause %s\n", pSound->Filename); |
2191 | 595 |
#endif |
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
596 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
597 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
598 |
void SSound_stop(SSound_t* pSound) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
599 |
if(pSound->source == -1) // not playing |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
600 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
601 |
alSourceStop(sources[pSound->source]); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
602 |
pSound->source = -1; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
603 |
#ifdef DEBUG |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
604 |
fprintf(stderr, "stop %s\n", pSound->Filename); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
605 |
#endif |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
606 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
607 |
|
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
608 |
void SSound_volume(const SSound_t* pSound, const float fPercentage) { |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
609 |
if(pSound->source == -1) // not playing |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
610 |
return; |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
611 |
alSourcef(sources[pSound->source], AL_GAIN, fPercentage); |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
612 |
} |
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2437
diff
changeset
|
613 |