/* * Performance stereo spatialization * of a channel in the frontends * sense. */ static void AL_Spatialize(channel_t *ch) { vec3_t origin; /* anything coming from the view entity will always be full volume. no attenuation = no spatialization */ if ((ch->entnum == -1) || (ch->entnum == cl.playernum + 1) || !ch->dist_mult) { VectorCopy(listener_origin, origin); } else if (ch->fixed_origin) { VectorCopy(ch->origin, origin); } else { CL_GetEntitySoundOrigin(ch->entnum, origin); } qalSource3f(ch->srcnum, AL_POSITION, AL_UnpackVector(origin)); }
/* ================== S_AddLoopSounds Entities with a ->sound field will generated looped sounds that are automatically started, stopped, and merged together as the entities are sent to the client ================== */ static void S_AddLoopSounds (void) { int i, j; int sounds[MAX_EDICTS]; int left, right, left_total, right_total; channel_t *ch; sfx_t *sfx; sfxcache_t *sc; int num; entity_state_t *ent; vec3_t origin; if (cl_paused->integer || cls.state != ca_active || !cl.sound_prepped) return; for (i=0 ; i<cl.frame.num_entities ; i++) { num = (cl.frame.parse_entities + i) & PARSE_ENTITIES_MASK; ent = &cl_parse_entities[num]; sounds[i] = ent->sound; } for (i=0 ; i<cl.frame.num_entities ; i++) { if (!sounds[i]) continue; sfx = cl.sound_precache[sounds[i]]; if (!sfx) continue; // bad sound effect sc = sfx->cache; if (!sc || sc->length <= 0) continue; num = (cl.frame.parse_entities + i) & PARSE_ENTITIES_MASK; ent = &cl_parse_entities[num]; CL_GetEntitySoundOrigin (ent->number, origin); // find the total contribution of all sounds of this type S_SpatializeOrigin (origin, 255.0f, SOUND_LOOPATTENUATE, &left_total, &right_total); for (j=i+1 ; j<cl.frame.num_entities ; j++) { if (sounds[j] != sounds[i]) continue; sounds[j] = 0; // don't check this again later num = (cl.frame.parse_entities + j) & PARSE_ENTITIES_MASK; ent = &cl_parse_entities[num]; S_SpatializeOrigin (ent->origin, 255.0f, SOUND_LOOPATTENUATE, &left, &right); left_total += left; right_total += right; } if (left_total == 0 && right_total == 0) continue; // not audible // allocate a channel ch = S_PickChannel(0, 0); if (!ch) return; if (left_total > 255) left_total = 255; if (right_total > 255) right_total = 255; ch->leftvol = left_total; ch->rightvol = right_total; ch->autosound = true; // remove next frame ch->sfx = sfx; ch->pos = paintedtime % sc->length; ch->end = paintedtime + sc->length - ch->pos; } }