32 if (numClips
>=clipsSize
) {
33 clips
= realloc(clips
,clipsSize
*2*sizeof(clip
));
41 void removeClip(int pos
) {
42 for (;pos
<numClips
;pos
++)
43 clips
[pos
]=clips
[pos
+1];
45 if (numClips
>0&&numClips
<clipsSize
/4) {
46 clips
= realloc(clips
,clipsSize
/4*sizeof(clip
));
51 int findClipstr(char * name
) {
54 if (strcmp(name
,clips
[i
].fileName
)==0)
59 int findClipi(int id
) {
62 if (clips
[i
].bufId
==id
)
67 int addSource(ALuint id
) {
68 if (numSources
>=sourcesSize
) {
69 sources
= realloc(sources
,sizeof(ALuint
)*sourcesSize
*2);
72 sources
[numSources
]=id
;
77 void removeSource(int pos
) {
78 for (;pos
<numSources
;pos
++)
79 sources
[pos
]=sources
[pos
+1];
80 if (numSources
>0&&numSources
<sourcesSize
/4) {
81 sources
= realloc(sources
,sizeof(ALuint
)*sourcesSize
/4);
86 int findSource(int id
) {
88 for (i
= 0; i
< numSources
;i
++)
94 void sourcecall(void *data
, ALuint source
) {
97 int timercall(int ms
, void * data
) {
105 DECLSPEC
void initAudio() {
107 attrlist
[0] = ALC_FREQUENCY
;
110 alureInitDevice(NULL
,attrlist
);
113 clips
= malloc(sizeof(clip
)*clipsSize
);
114 sources
= malloc(sizeof(ALuint
)*sourcesSize
);
115 updater
= addTimer(10,timercall
,NULL
);
117 alGenFilters(1,&lowpass
);
118 alFilteri(lowpass
,AL_FILTER_TYPE
,AL_FILTER_LOWPASS
);
119 alFilterf(lowpass
,AL_LOWPASS_GAINHF
,0.5f
);
122 DECLSPEC
void terminateAudio() {
123 cancelTimer(updater
);
125 alDeleteSources(numSources
,sources
);
126 for (i
= 0; i
< numClips
;i
++) {
127 free(clips
[i
].fileName
);
128 if (clips
[i
].stream
==NULL
)
129 alDeleteBuffers(1,&clips
[i
].bufId
);
131 alureDestroyStream(clips
[i
].stream
,4096,&clips
[i
].bufId
);
135 alDeleteFilters(1,&lowpass
);
136 alureShutdownDevice();
139 void playsource(int sound
,int loop
) {
141 alGetSourcei(sound
, AL_BUFFER
, &bufid
);
142 int pos
= findClipi(bufid
);
145 if (clips
[pos
].stream
==NULL
)
148 alurePlaySourceStream(sound
,clips
[pos
].stream
,4,loop
,sourcecall
,NULL
);
152 DECLSPEC
int loadSound(char * file
) {
153 int pos
= findClipstr(file
);
156 bufid
= alureCreateBufferFromFile(file
);
157 clip c
= {strdup(file
),bufid
,0,NULL
};
161 bufid
= clips
[pos
].bufId
;
163 alGenSources(1, &soundid
);
164 alSourcei(soundid
, AL_BUFFER
, bufid
);
170 DECLSPEC
int streamSound(char * file
) {
171 int pos
= findClipstr(file
);
174 alureStream
* s
= alureCreateStreamFromFile(file
,4096,1,&bufid
);
175 clip c
= {strdup(file
),bufid
,0,s
};
179 bufid
= clips
[pos
].bufId
;
181 alGenSources(1, &soundid
);
182 alSourcei(soundid
, AL_BUFFER
, bufid
);
188 DECLSPEC
void unloadSound(int sound
) {
190 alGetSourcei(sound
,AL_BUFFER
,&id
);
193 alDeleteSources(1, &sound
);
195 if (clips
[pos
].count
==0) {
196 free(clips
[pos
].fileName
);
197 if (clips
[pos
].stream
==NULL
)
198 alDeleteBuffers(1,&clips
[pos
].bufId
);
200 alureDestroyStream(clips
[pos
].stream
,4096,&clips
[pos
].bufId
);
205 DECLSPEC
void setSoundPosition(int sound
, float x
, float y
, float z
) {
206 alSource3f(sound
,AL_POSITION
,x
,y
,z
);
209 DECLSPEC
void setSoundPitch(int sound
, float pitch
) {
210 alSourcef(sound
,AL_PITCH
,pitch
);
213 DECLSPEC
void playSound(int sound
) {
214 alSourcei(sound
,AL_LOOPING
,AL_FALSE
);
218 DECLSPEC
void loopSound(int sound
) {
219 alSourcei(sound
,AL_LOOPING
,AL_TRUE
);
220 playsource(sound
,-1);
223 DECLSPEC
void stopSound(int sound
) {
224 alureStopSource(sound
,0);
228 DECLSPEC
void setListenerPosition(float x
, float y
, float z
) {
229 alListener3f(AL_POSITION
, x
, y
, z
);
232 DECLSPEC
void setSoundLowpass(int sound
, int lp
) {
234 alSourcei(sound
,AL_DIRECT_FILTER
,lowpass
);
236 alSourcei(sound
,AL_DIRECT_FILTER
,AL_FILTER_NULL
);
239 DECLSPEC
int getSoundLowpass(int sound
) {
241 alGetSourcei(sound
,AL_DIRECT_FILTER
,&ret
);
245 DECLSPEC
int isPlaying(int sound
) {
247 alGetSourcei(sound
,AL_SOURCE_STATE
,&ret
);
248 return ret
==AL_PLAYING
;
251 DECLSPEC
void setSoundGain(int sound
, float gain
) {
252 alSourcef(sound
,AL_GAIN
,gain
);