30 if (numClips
>=clipsSize
) {
31 clips
= realloc(clips
,clipsSize
*2*sizeof(clip
));
39 void removeClip(int pos
) {
40 free(clips
[pos
].fileName
);
41 for (;pos
<numClips
;pos
++)
42 clips
[pos
]=clips
[pos
+1];
44 if (numClips
>0&&numClips
<clipsSize
/4) {
45 clips
= realloc(clips
,clipsSize
/4*sizeof(clip
));
50 int findClipstr(char * name
) {
53 if (strcmp(name
,clips
[i
].fileName
)==0)
58 int findClipi(int id
) {
61 if (clips
[i
].bufId
==id
)
66 int addSource(ALuint id
) {
67 if (numSources
>=sourcesSize
) {
68 sources
= realloc(sources
,sizeof(ALuint
)*sourcesSize
*2);
71 sources
[numSources
]=id
;
76 void removeSource(int pos
) {
77 for (;pos
<numSources
;pos
++)
78 sources
[pos
]=sources
[pos
+1];
79 if (numSources
>0&&numSources
<sourcesSize
/4) {
80 sources
= realloc(sources
,sizeof(ALuint
)*sourcesSize
/4);
85 int findSource(int id
) {
87 for (i
= 0; i
< numSources
;i
++)
93 DECLSPEC
void init3dAudio() {
95 attrlist
[0] = ALC_FREQUENCY
;
98 device
= alcOpenDevice(NULL
);
99 context
= alcCreateContext(device
, attrlist
);
100 alcMakeContextCurrent(context
);
103 clips
= malloc(sizeof(clip
)*clipsSize
);
104 sources
= malloc(sizeof(ALuint
)*sourcesSize
);
107 DECLSPEC
void terminate3dAudio() {
109 alDeleteSources(numSources
,sources
);
110 for (i
= 0; i
< numClips
;i
++) {
111 free(clips
[i
].fileName
);
112 alDeleteBuffers(1,&clips
[i
].bufId
);
116 alcDestroyContext(context
);
117 alcCloseDevice(device
);
120 DECLSPEC
int load3dSound(char * file
) {
121 int pos
= findClipstr(file
);
131 alGenBuffers(1,&bufid);
132 alutLoadWAVFile((ALbyte*)file, &format, &wave, &size, &freq, 0);
133 alBufferData(bufid,format,wave,size,freq);
136 bufid
= alureCreateBufferFromFile(file
);
137 clip c
= {strdup(file
),bufid
,0};
141 bufid
= clips
[pos
].bufId
;
143 alGenSources(1, &soundid
);
144 alSourcei(soundid
, AL_BUFFER
, bufid
);
150 DECLSPEC
void unload3dSound(int sound
) {
152 alGetSourcei(sound
,AL_BUFFER
,&id
);
155 alDeleteSources(1, &sound
);
157 if (clips
[pos
].count
==0)
161 DECLSPEC
void set3dSoundPosition(int sound
, float x
, float y
, float z
) {
162 alSource3f(sound
,AL_POSITION
,x
,y
,z
);
165 DECLSPEC
void set3dSoundPitch(int sound
, float pitch
) {
166 alSourcef(sound
,AL_PITCH
,pitch
);
169 DECLSPEC
void play3dSound(int sound
) {
170 alSourcei(sound
,AL_LOOPING
,AL_FALSE
);
174 DECLSPEC
void loop3dSound(int sound
) {
175 alSourcei(sound
,AL_LOOPING
,AL_TRUE
);
179 DECLSPEC
void stop3dSound(int sound
) {