+ vol = intensity * sqrt(angle_factor);
+ ch->listener_volume[0] = (int)bound(0, vol, 65536);
+ vol = intensity * sqrt(1 - angle_factor);
+ ch->listener_volume[1] = (int)bound(0, vol, 65536);
+ for (i = 2;i < SND_LISTENERS;i++)
+ ch->listener_volume[i] = 0;
+ }
+ else
+ {
+ for (i = 0;i < SND_LISTENERS;i++)
+ {
+ Matrix4x4_Transform(&listener_matrix[i], ch->origin, source_vec);
+ VectorNormalize(source_vec);
+
+ switch(spatialmethod)
+ {
+ case SPATIAL_LOG:
+ if(dist == 0)
+ f = spatialmin + spatialdiff * (spatialfactor < 0); // avoid log(0), but do the right thing
+ else
+ f = spatialmin + spatialdiff * bound(0, (log(dist) - spatialoffset) * spatialfactor, 1);
+ VectorScale(source_vec, f, source_vec);
+ break;
+ case SPATIAL_POW:
+ f = (pow(dist, spatialpower) - spatialoffset) * spatialfactor;
+ f = spatialmin + spatialdiff * bound(0, f, 1);
+ VectorScale(source_vec, f, source_vec);
+ break;
+ case SPATIAL_THRESH:
+ f = spatialmin + spatialdiff * (dist < spatialoffset);
+ VectorScale(source_vec, f, source_vec);
+ break;
+ case SPATIAL_NONE:
+ default:
+ break;
+ }
+
+ vol = intensity * max(0, source_vec[0] * snd_speakerlayout.listeners[i].dotscale + snd_speakerlayout.listeners[i].dotbias);
+
+ ch->listener_volume[i] = (int)bound(0, vol, 65536);
+ }