void S_Update_(void) { unsigned endtime; int samps; static float lastTime = 0.0f; float ma, op; float thisTime, sane; static int ot = -1; if ( !s_soundStarted || s_soundMuted ) { return; } thisTime = Com_Milliseconds(); // Updates s_soundtime S_GetSoundtime(); if (s_soundtime == ot) { return; } ot = s_soundtime; // clear any sound effects that end before the current time, // and start any new sounds S_ScanChannelStarts(); sane = thisTime - lastTime; if (sane<11) { sane = 11; // 85hz } ma = s_mixahead->value * dma.speed; op = s_mixPreStep->value + sane*dma.speed*0.01; if (op < ma) { ma = op; } // mix ahead of current position endtime = s_soundtime + ma; // mix to an even submission block size endtime = (endtime + dma.submission_chunk-1) & ~(dma.submission_chunk-1); // never mix more than the complete buffer samps = dma.samples >> (dma.channels-1); if (endtime - s_soundtime > samps) endtime = s_soundtime + samps; SNDDMA_BeginPainting (); S_PaintChannels (endtime); SNDDMA_Submit (); lastTime = thisTime; }
void S_Update_(void) { unsigned endtime; int samps; static float lastTime = 0.0f; float ma, op; float thisTime, sane; static int ot = -1; if (!s_soundStarted || s_soundMuted) { return; } thisTime = Sys_Milliseconds(); // Updates s_soundtime S_GetSoundtime(); if (s_soundtime == ot) { return; } ot = s_soundtime; // clear any sound effects that end before the current time, // and start any new sounds S_ScanChannelStarts(); sane = thisTime - lastTime; if (sane < 11) { sane = 11; // 85hz } ma = s_mixahead->value * dma.speed; op = s_mixPreStep->value + sane * dma.speed * 0.01; if (op < ma) { ma = op; } // mix ahead of current position endtime = s_soundtime + ma; // mix to an even submission block size endtime = (endtime + dma.submission_chunk - 1) & ~(dma.submission_chunk - 1); // never mix more than the complete buffer samps = dma.samples >> (dma.channels - 1); if (endtime - s_soundtime > samps) { endtime = s_soundtime + samps; } // global volume fading // endtime or s_paintedtime or s_soundtime... if (s_soundtime < s_volTime2) // still has fading to do { if (s_soundtime > s_volTime1) // has started fading { s_volFadeFrac = ((float)(s_soundtime - s_volTime1) / (float)(s_volTime2 - s_volTime1)); s_volCurrent = ((1.0f - s_volFadeFrac) * s_volStart + s_volFadeFrac * s_volTarget); } else { s_volCurrent = s_volStart; } } else { s_volCurrent = s_volTarget; if (s_stopSounds) { // stop playing any sounds if they are all faded out S_StopAllSounds(); s_stopSounds = qfalse; } } SNDDMA_BeginPainting(); S_PaintChannels(endtime); SNDDMA_Submit(); lastTime = thisTime; }