author | koda |
Wed, 14 Oct 2009 22:12:02 +0000 | |
changeset 2443 | fececcbc2189 |
parent 2419 | dbaaba09146d |
child 2444 | ace11b7d8eab |
permissions | -rw-r--r-- |
2191 | 1 |
/* |
2 |
* OpenAL Bridge - a simple portable library for OpenAL interface |
|
3 |
* Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
2257
7eb31efcfb9b
updates licence and fix a memory leak (which was consuming iphone memory)
koda
parents:
2218
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:
2218
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:
2218
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 |
||
19 |
#include "wrappers.h" |
|
20 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2419
diff
changeset
|
21 |
extern char *prog; |
2418 | 22 |
|
2191 | 23 |
#ifdef __CPLUSPLUS |
24 |
extern "C" { |
|
25 |
#endif |
|
2418 | 26 |
|
27 |
extern ALint *Sources; |
|
2259 | 28 |
|
2418 | 29 |
void *Malloc (size_t nbytes) { |
30 |
void *aptr; |
|
31 |
||
32 |
if ((aptr = malloc(nbytes)) == NULL) |
|
33 |
err_dump("(%s) FATAL - not enough memory"); |
|
34 |
||
35 |
return aptr; |
|
2259 | 36 |
} |
2418 | 37 |
|
38 |
||
39 |
void *Realloc (void *aptr, size_t nbytes) { |
|
40 |
aptr = realloc(aptr, nbytes); |
|
41 |
||
42 |
if (aptr == NULL) |
|
43 |
err_dump("(%s) FATAL - not enough memory"); |
|
44 |
||
45 |
return aptr; |
|
46 |
} |
|
47 |
||
2259 | 48 |
|
2418 | 49 |
FILE *Fopen (const char *fname, char *mode) { |
50 |
FILE *fp; |
|
51 |
||
52 |
fp = fopen(fname,mode); |
|
53 |
if (fp == NULL) |
|
54 |
err_ret("(%s) ERROR - can't open file %s in mode '%s'", prog, fname, mode); |
|
2419 | 55 |
|
2418 | 56 |
return fp; |
57 |
} |
|
2259 | 58 |
|
2418 | 59 |
/*TODO make a proper error reporting routine*/ |
60 |
ALint AlGetError (const char *str) { |
|
61 |
ALenum error; |
|
62 |
||
63 |
error = alGetError(); |
|
64 |
if (error != AL_NO_ERROR) { |
|
65 |
err_msg(str, prog); |
|
66 |
return error; |
|
67 |
} else |
|
68 |
return AL_TRUE; |
|
69 |
} |
|
2259 | 70 |
|
2418 | 71 |
ALint AlGetError2 (const char *str, int num) { |
72 |
ALenum error; |
|
73 |
||
74 |
error = alGetError(); |
|
75 |
if (error != AL_NO_ERROR) { |
|
2419 | 76 |
err_msg(str, prog, num); |
77 |
return error; |
|
2418 | 78 |
} else |
79 |
return AL_TRUE; |
|
2259 | 80 |
} |
81 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2419
diff
changeset
|
82 |
/* void *helper_fadein(void *tmp) { |
2418 | 83 |
ALfloat gain; |
84 |
ALfloat target_gain; |
|
85 |
fade_t *fade; |
|
86 |
uint32_t index; |
|
87 |
uint16_t quantity; |
|
88 |
||
89 |
fade = tmp; |
|
90 |
index = fade->index; |
|
91 |
quantity = fade->quantity; |
|
92 |
free (fade); |
|
93 |
||
94 |
#ifdef DEBUG |
|
95 |
err_msg("(%s) INFO - Fade-in in progress [index %d quantity %d]", prog, index, quantity); |
|
2210 | 96 |
#endif |
2418 | 97 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2419
diff
changeset
|
98 |
/*save the volume desired after the fade |
2418 | 99 |
alGetSourcef(Sources[index], AL_GAIN, &target_gain); |
100 |
if (target_gain > 1.0f || target_gain <= 0.0f) |
|
101 |
target_gain = 1.0f; |
|
102 |
||
103 |
alSourcePlay(Sources[index]); |
|
104 |
||
105 |
for (gain = 0.0f ; gain <= target_gain; gain += (float) quantity/10000) { |
|
106 |
#ifdef TRACE |
|
107 |
err_msg("(%s) DEBUG - Fade-in set gain to %f", gain); |
|
2259 | 108 |
#endif |
2418 | 109 |
alSourcef(Sources[index], AL_GAIN, gain); |
110 |
usleep(10000); |
|
111 |
} |
|
112 |
||
113 |
AlGetError("(%s) WARN - Failed to set fade-in volume level"); |
|
114 |
||
115 |
#ifndef _WIN32 |
|
116 |
pthread_exit(NULL); |
|
117 |
#else |
|
118 |
_endthread(); |
|
2210 | 119 |
#endif |
2418 | 120 |
return 0; |
2259 | 121 |
} |
122 |
||
2418 | 123 |
void *helper_fadeout(void *tmp) { |
124 |
ALfloat gain; |
|
125 |
ALfloat old_gain; |
|
126 |
fade_t *fade; |
|
127 |
uint32_t index; |
|
128 |
uint16_t quantity; |
|
129 |
||
130 |
fade = tmp; |
|
131 |
index = fade->index; |
|
132 |
quantity = fade->quantity; |
|
133 |
free(fade); |
|
134 |
||
135 |
#ifdef DEBUG |
|
136 |
err_msg("(%s) INFO - Fade-out in progress [index %d quantity %d]", prog, index, quantity); |
|
137 |
#endif |
|
138 |
||
139 |
alGetSourcef(Sources[index], AL_GAIN, &old_gain); |
|
140 |
||
141 |
for (gain = old_gain; gain >= 0.00f; gain -= (float) quantity/10000) { |
|
142 |
#ifdef TRACE |
|
143 |
err_msg("(%s) DEBUG - Fade-out set gain to %f", gain); |
|
144 |
#endif |
|
145 |
alSourcef(Sources[index], AL_GAIN, gain); |
|
146 |
usleep(10000); |
|
147 |
} |
|
148 |
||
149 |
AlGetError("(%s) WARN - Failed to set fade-out volume level"); |
|
150 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2419
diff
changeset
|
151 |
/*stop that sound and reset its volume |
2418 | 152 |
alSourceStop (Sources[index]); |
153 |
alSourcef (Sources[index], AL_GAIN, old_gain); |
|
154 |
||
2210 | 155 |
#ifndef _WIN32 |
2418 | 156 |
pthread_exit(NULL); |
2210 | 157 |
#else |
2418 | 158 |
_endthread(); |
2210 | 159 |
#endif |
2418 | 160 |
return 0; |
161 |
} |
|
162 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2419
diff
changeset
|
163 |
*/ |
2191 | 164 |
#ifdef __CPLUSPLUS |
165 |
} |
|
2216
82e7da49c26a
-Smaxx' patch: checks for initialized openal + disables sound options if openal init fails
koda
parents:
2213
diff
changeset
|
166 |
#endif |