70 float final_gain = gain;
77 float ref = ref_distance;
79 final_gain *= (distance <= 0) ? 1.
f :
float(ref / (ref + rolloff * distance));
87 if (sounds[sound].
buffer == (ALuint) 0)
89 sounds[sound].pos = pos;
90 sounds[sound].vel = vel;
92 float mag = t.Dot( t );
93 if ( pos ==
Vector( 0, 0, 0 ) ) {
99 if ( !(mag < max_cutoff*max_cutoff) )
102 if ( ( !unusedsrcs.empty() ) &&
playingbuffers[hashed].
size() < maxallowedsingle )
return 1;
108 float min_gain = est_gain;
110 for (
size_t target = 0; target <
playingbuffers[hashed].size(); ++target) {
113 if ( sounds[target1].pos ==
Vector( 0, 0, 0 ) )
116 if (sounds[target1].buffer == sounds[sound].buffer) {
117 float target_est_gain;
118 if (sounds[target1].pos ==
Vector(0,0,0)) {
120 target_est_gain = sounds[target1].gain;
123 target_est_gain =
EstimateGain(sounds[target1].pos,sounds[target1].gain);
125 if (target_est_gain <= min_gain) {
127 min_gain = target_est_gain;
131 if (min_index >= 0) {
132 int target = min_index;
135 ALuint tmpsrc = sounds[target1].source;
137 sounds[target1].source = sounds[sound].source;
138 sounds[sound].source = tmpsrc;
160 if (sounds[sound].
buffer != (ALuint) 0) {
162 if (sounds[sound].source == 0)
177 static unsigned int i = 0;
186 alSourcei( sounds[
playingbuffers[i][
j].soundname].source, AL_BUFFER, 0 );
196 static unsigned int j = 0;
217 alListener3f( AL_POSITION, scalepos*pos.i, scalepos*pos.j, scalepos*pos.k );
219 alListener3f( AL_VELOCITY, scalevel*vel.i, scalevel*vel.j, scalevel*vel.k );
238 ALfloat orient[] = {r.i, r.j, r.k, q.i, q.j, q.k};
241 alListenerfv( AL_ORIENTATION, orient );
248 if ( sound >= 0 && sound < (
int) sounds.size() ) {
249 sounds[sound].music = music;
251 if (sounds[sound].source)
252 alSourcef( sounds[sound].source, AL_GAIN, val <= 1./16384 ? 0 : val );
253 sounds[sound].gain = gain;
263 if (gain <= 0) gain = 1./16384;
265 for (
unsigned int i = 0, ie = sounds.size();
i < ie; ++
i)
266 if (!sounds[
i].music)
269 alListenerf( AL_GAIN, 1.0 );