author | nemo |
Fri, 16 Oct 2009 03:34:00 +0000 | |
changeset 2476 | 4e9c3c9ece3e |
parent 2444 | ace11b7d8eab |
child 2494 | 1e10a47cabea |
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 |
|
2444 | 23 |
//extern ALint *Sources; |
24 |
||
25 |
void *Malloc (size_t nbytes) { |
|
26 |
void *aptr; |
|
2418 | 27 |
|
2444 | 28 |
if ((aptr = malloc(nbytes)) == NULL) |
29 |
err_dump("(%s) FATAL - not enough memory"); |
|
2259 | 30 |
|
2444 | 31 |
return aptr; |
32 |
} |
|
33 |
||
34 |
||
35 |
void *Realloc (void *aptr, size_t nbytes) { |
|
36 |
aptr = realloc(aptr, nbytes); |
|
2418 | 37 |
|
2444 | 38 |
if (aptr == NULL) |
39 |
err_dump("(%s) FATAL - not enough memory"); |
|
2418 | 40 |
|
2444 | 41 |
return aptr; |
42 |
} |
|
43 |
||
44 |
||
45 |
FILE *Fopen (const char *fname, char *mode) { |
|
46 |
FILE *fp; |
|
2259 | 47 |
|
2444 | 48 |
fp = fopen(fname,mode); |
49 |
if (fp == NULL) |
|
50 |
err_ret("(%s) ERROR - can't open file %s in mode '%s'", prog, fname, mode); |
|
51 |
||
52 |
return fp; |
|
53 |
} |
|
54 |
||
55 |
/*TODO make a proper error reporting routine*/ |
|
56 |
ALint AlGetError (const char *str) { |
|
57 |
ALenum error; |
|
2259 | 58 |
|
2444 | 59 |
error = alGetError(); |
60 |
if (error != AL_NO_ERROR) { |
|
61 |
err_msg(str, prog); |
|
62 |
return error; |
|
63 |
} else |
|
64 |
return AL_TRUE; |
|
65 |
} |
|
66 |
||
67 |
ALint AlGetError2 (const char *str, int num) { |
|
68 |
ALenum error; |
|
2259 | 69 |
|
2444 | 70 |
error = alGetError(); |
71 |
if (error != AL_NO_ERROR) { |
|
72 |
err_msg(str, prog, num); |
|
73 |
return error; |
|
74 |
} else |
|
75 |
return AL_TRUE; |
|
76 |
} |
|
77 |
||
78 |
/* void *helper_fadein(void *tmp) { |
|
2418 | 79 |
ALfloat gain; |
80 |
ALfloat target_gain; |
|
81 |
fade_t *fade; |
|
82 |
uint32_t index; |
|
83 |
uint16_t quantity; |
|
84 |
||
85 |
fade = tmp; |
|
86 |
index = fade->index; |
|
87 |
quantity = fade->quantity; |
|
88 |
free (fade); |
|
89 |
||
90 |
#ifdef DEBUG |
|
91 |
err_msg("(%s) INFO - Fade-in in progress [index %d quantity %d]", prog, index, quantity); |
|
2210 | 92 |
#endif |
2418 | 93 |
|
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2419
diff
changeset
|
94 |
/*save the volume desired after the fade |
2418 | 95 |
alGetSourcef(Sources[index], AL_GAIN, &target_gain); |
96 |
if (target_gain > 1.0f || target_gain <= 0.0f) |
|
97 |
target_gain = 1.0f; |
|
98 |
||
99 |
alSourcePlay(Sources[index]); |
|
100 |
||
101 |
for (gain = 0.0f ; gain <= target_gain; gain += (float) quantity/10000) { |
|
102 |
#ifdef TRACE |
|
103 |
err_msg("(%s) DEBUG - Fade-in set gain to %f", gain); |
|
2259 | 104 |
#endif |
2418 | 105 |
alSourcef(Sources[index], AL_GAIN, gain); |
106 |
usleep(10000); |
|
107 |
} |
|
108 |
||
109 |
AlGetError("(%s) WARN - Failed to set fade-in volume level"); |
|
110 |
||
111 |
#ifndef _WIN32 |
|
112 |
pthread_exit(NULL); |
|
113 |
#else |
|
114 |
_endthread(); |
|
2210 | 115 |
#endif |
2418 | 116 |
return 0; |
2259 | 117 |
} |
118 |
||
2418 | 119 |
void *helper_fadeout(void *tmp) { |
120 |
ALfloat gain; |
|
121 |
ALfloat old_gain; |
|
122 |
fade_t *fade; |
|
123 |
uint32_t index; |
|
124 |
uint16_t quantity; |
|
125 |
||
126 |
fade = tmp; |
|
127 |
index = fade->index; |
|
128 |
quantity = fade->quantity; |
|
129 |
free(fade); |
|
130 |
||
131 |
#ifdef DEBUG |
|
132 |
err_msg("(%s) INFO - Fade-out in progress [index %d quantity %d]", prog, index, quantity); |
|
133 |
#endif |
|
134 |
||
135 |
alGetSourcef(Sources[index], AL_GAIN, &old_gain); |
|
136 |
||
137 |
for (gain = old_gain; gain >= 0.00f; gain -= (float) quantity/10000) { |
|
138 |
#ifdef TRACE |
|
139 |
err_msg("(%s) DEBUG - Fade-out set gain to %f", gain); |
|
140 |
#endif |
|
141 |
alSourcef(Sources[index], AL_GAIN, gain); |
|
142 |
usleep(10000); |
|
143 |
} |
|
144 |
||
145 |
AlGetError("(%s) WARN - Failed to set fade-out volume level"); |
|
146 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2419
diff
changeset
|
147 |
/*stop that sound and reset its volume |
2418 | 148 |
alSourceStop (Sources[index]); |
149 |
alSourcef (Sources[index], AL_GAIN, old_gain); |
|
150 |
||
2210 | 151 |
#ifndef _WIN32 |
2418 | 152 |
pthread_exit(NULL); |
2210 | 153 |
#else |
2418 | 154 |
_endthread(); |
2210 | 155 |
#endif |
2418 | 156 |
return 0; |
157 |
} |
|
158 |
||
2443
fececcbc2189
Smaxx patch for fixing all sound related issues on any system
koda
parents:
2419
diff
changeset
|
159 |
*/ |