// Called once each time through the main loop void S_Update(const CVec3 &origin, const CVec3 &right) { int i; if (!sound_started) return; // rebuild scale tables if volume is modified if (s_volume->modified) S_InitScaletable(); listener_origin = origin; listener_right = right; // update spatialization for dynamic sounds channel_t *ch = channels; for (i = 0; i < MAX_CHANNELS; i++, ch++) { if (!ch->sfx) continue; if (ch->autosound) { // autosounds are regenerated fresh each frame memset(ch, 0, sizeof(*ch)); continue; } S_Spatialize(ch); // respatialize channel if (!ch->leftvol && !ch->rightvol) { memset(ch, 0, sizeof(*ch)); continue; } } // add loopsounds AddLoopSounds(); // debugging output if (s_show->integer == 2) { int total = 0; for (i = 0, ch = channels; i < MAX_CHANNELS; i++, ch++) if (ch->sfx && (ch->leftvol || ch->rightvol) ) { appPrintf("%3i %3i %s\n", ch->leftvol, ch->rightvol, *ch->sfx->Name); total++; } appPrintf("----(%i)---- painted: %i\n", total, paintedtime); } // mix some sound S_Update_(); }
/* =============== S_IssuePlaysound Take the next playsound and begin it on the channel This is never called directly by S_Play*, but only by the update loop. =============== */ void S_IssuePlaysound (playsound_t *ps) { channel_t *ch; sfxcache_t *sc; if (s_show->integer) Com_Printf ("Issue %i\n", ps->begin); // pick a channel to play on ch = S_PickChannel(ps->entnum, ps->entchannel); if (!ch) { S_FreePlaysound(ps); return; } sc = S_LoadSound(ps->sfx); if (!sc || sc->length <= 0) { S_FreePlaysound(ps); return; } // spatialize if (ps->attenuation == ATTN_STATIC) ch->dist_mult = ps->attenuation * 0.001f; else ch->dist_mult = ps->attenuation * 0.0005f; ch->master_vol = ps->volume; ch->entnum = ps->entnum; ch->entchannel = ps->entchannel; ch->sfx = ps->sfx; VectorCopy (ps->origin, ch->origin); ch->fixed_origin = ps->fixed_origin; S_Spatialize(ch); ch->pos = 0; ch->end = paintedtime + sc->length; // free the playsound S_FreePlaysound(ps); }
/* =============== S_IssuePlaysound Take the next playsound and begin it on the channel This is never called directly by S_Play*, but only by the update loop. =============== */ void S_IssuePlaysound(playsound_t *ps) { channel_t *ch; sfxcache_t *sc; if (s_show->integer) appPrintf("Sound: %s begin:%d ent:%d chn:%d\n", *ps->sfx->Name, ps->begin, ps->entnum, ps->entchannel); // pick a channel to play on ch = S_PickChannel(ps->entnum, ps->entchannel); if (!ch) { S_FreePlaysound(ps); return; } // spatialize if (ps->attenuation == ATTN_STATIC) ch->dist_mult = ps->attenuation * 0.001f; // will be fixed value: 0.003f else ch->dist_mult = ps->attenuation * 0.0005f; ch->master_vol = ps->volume; ch->entnum = ps->entnum; ch->entchannel = ps->entchannel; ch->sfx = ps->sfx; ch->origin = ps->origin; ch->fixed_origin = ps->fixed_origin; S_Spatialize(ch); ch->pos = 0; sc = S_LoadSound(ch->sfx); ch->end = paintedtime + sc->length; // free the playsound S_FreePlaysound(ps); }
/* ============ S_Update Called once each time through the main loop ============ */ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up) { int i; int total; channel_t *ch; channel_t *combine; if (!sound_started) return; // if the laoding plaque is up, clear everything // out to make sure we aren't looping a dirty // dma buffer while loading if (cls.disable_screen) { S_ClearBuffer (); return; } // rebuild scale tables if volume is modified if (s_volume->modified) S_InitScaletable (); VectorCopy(origin, listener_origin); VectorCopy(forward, listener_forward); VectorCopy(right, listener_right); VectorCopy(up, listener_up); combine = NULL; // update spatialization for dynamic sounds ch = channels; for (i=0 ; i<MAX_CHANNELS; i++, ch++) { if (!ch->sfx) continue; if (ch->autosound) { // autosounds are regenerated fresh each frame memset (ch, 0, sizeof(*ch)); continue; } S_Spatialize(ch); // respatialize channel if (!ch->leftvol && !ch->rightvol) { memset (ch, 0, sizeof(*ch)); continue; } } // add loopsounds S_AddLoopSounds (); // // debugging output // if (s_show->value) { total = 0; ch = channels; for (i=0 ; i<MAX_CHANNELS; i++, ch++) if (ch->sfx && (ch->leftvol || ch->rightvol) ) { Com_Printf ("%3i %3i %s\n", ch->leftvol, ch->rightvol, ch->sfx->name); total++; } Com_Printf ("----(%i)---- painted: %i\n", total, paintedtime); } #ifdef OGG_SUPPORT // Com_DPrintf ("S_Update: calling S_UpdateBackgroundTrack\n"); // debug S_UpdateBackgroundTrack (); // Knightmare added #endif // mix some sound S_Update_(); }