Ejemplo n.º 1
0
/*
 * S_Frame
 */
void S_Frame(void) {
	s_channel_t *ch;
	int i, j;

	if (!s_env.initialized)
		return;

	S_FrameMusic();

	if (cls.state != CL_ACTIVE) {
		if (Mix_Playing(-1) > 0)
			S_Stop();
		return;
	}

	if (s_reverse->modified) { // update reverse stereo
		Mix_SetReverseStereo(MIX_CHANNEL_POST, s_reverse->integer);
		s_reverse->modified = false;
	}

	// update spatialization for current sounds
	ch = s_env.channels;

	for (i = 0; i < MAX_CHANNELS; i++, ch++) {

		if (!ch->sample)
			continue;

		// reset channel's count for loop samples
		ch->count = 0;

		S_SpatializeChannel(ch);
	}

	// add new dynamic sounds
	for (i = 0; i < cl.frame.num_entities; i++) {

		const int e = (cl.frame.entity_state + i) & ENTITY_STATE_MASK;
		const entity_state_t *ent = &cl.entity_states[e];

		if (!ent->sound)
			continue;

		for (j = 0; j < MAX_CHANNELS; j++) {
			if (s_env.channels[j].ent_num == ent->number)
				break;
		}

		if (j == MAX_CHANNELS)
			S_PlaySample(NULL, ent->number, cl.sound_precache[ent->sound],
					ATTN_NORM);
	}

	if (cl.underwater) // add under water sample if appropriate
		S_LoopSample(r_view.origin, S_LoadSample("world/under_water"));

	// reset the update flag
	s_env.update = false;
}
Ejemplo n.º 2
0
/**
 * @sa CL_Frame
 */
void S_Frame (void)
{
    if (snd_init && snd_init->modified) {
        S_Restart_f();
        snd_init->modified = false;
    }

    if (!s_env.initialized)
        return;

    M_Frame();

    if (CL_OnBattlescape()) {
        int i;
        s_channel_t *ch;
        le_t *le;

        /* update right angle for stereo panning */
        VectorCopy(cl.cam.axis[AXIS_RIGHT], s_env.right);
        S_MumbleUpdate(cl.cam.camorg, cl.cam.axis[AXIS_FORWARD], cl.cam.axis[AXIS_RIGHT], cl.cam.axis[AXIS_UP]);

        /* update spatialization for current sounds */
        ch = s_env.channels;

        for (i = 0; i < MAX_CHANNELS; i++, ch++) {
            if (!ch->sample)
                continue;

            /* reset channel's count for loop samples */
            ch->count = 0;

            S_SpatializeChannel(ch);
        }

        /* ambient sounds */
        le = NULL;
        while ((le = LE_GetNextInUse(le))) {
            if (le->type == ET_SOUND) {
                s_sample_t *sample = S_GetSample(le->sampleIdx);
                int j;
                for (j = 0; j < MAX_CHANNELS; j++) {
                    if (s_env.channels[j].sample == sample)
                        break;
                }

                if (j == MAX_CHANNELS)
                    S_LoopSample(le->origin, sample, le->volume, le->attenuation);
            }
        }
    }
}