/* =============== SNDDMA_AudioCallback =============== */ static void SNDDMA_AudioCallback(void *userdata, Uint8 *stream, int len) { int pos = (dmapos * (dma.samplebits/8)); if (pos >= dmasize) { //Com_Printf("pos (%d) > dmasize (%d)\n", pos, dmasize); dmapos = pos = 0; } if (!snd_inited) /* shouldn't happen, but just in case... */ { memset(stream, '\0', len); return; } else { int tobufend = dmasize - pos; /* bytes to buffer's end. */ int len1 = len; int len2 = 0; if (len1 > tobufend) { len1 = tobufend; len2 = len - len1; } if (CL_VideoRecording(&afdMain) && (cl_aviNoAudioHWOutput->integer || (cl_freezeDemo->integer && cl_freezeDemoPauseVideoRecording->integer))) { memset(stream, 0, len1); } else { memcpy(stream, dma.buffer + pos, len1); } if (len2 <= 0) { //Com_Printf("len2 <= 0 %d\n", len2); dmapos += (len1 / (dma.samplebits/8)); } else { /* wraparound? */ //Com_Printf("wrap len2 %d\n", len2); if (CL_VideoRecording(&afdMain) && (cl_aviNoAudioHWOutput->integer || (cl_freezeDemo->integer && cl_freezeDemoPauseVideoRecording->integer))) { memset(stream + len1, 0, len2); } else { memcpy(stream+len1, dma.buffer, len2); } dmapos = (len2 / (dma.samplebits/8)); } } if (dmapos >= dmasize) { //Com_Printf("dmapos >= dmasize %d > %d\n", dmapos, dmasize); dmapos = 0; } }
/* ================= CL_DemoCompleted ================= */ void CL_DemoCompleted(void) { #if NEW_DEMOFUNC CL_FreeDemoPoints(); #endif if (cl_timedemo && cl_timedemo->integer) { int time; time = Sys_Milliseconds() - clc.timeDemoStart; if (time > 0) { Com_FuncPrinf("%i frames, %3.1f seconds: %3.1f fps\n", clc.timeDemoFrames, time / 1000.0, clc.timeDemoFrames * 1000.0 / time); } } if (CL_VideoRecording()) { Cmd_ExecuteString("stopvideo"); } if (clc.waverecording) { CL_WriteWaveClose(); clc.waverecording = qfalse; } CL_Disconnect(qtrue); CL_NextDemo(); }
void GetSoundtime (void) { int samplepos; static int buffers; static int oldsamplepos; int fullsamples; fullsamples = dma.samples / dma.channels; if(CL_VideoRecording()) { soundtime += (int)(0.5 + cls.frametime * dma.speed); return; } // it is possible to miscount buffers if it has wrapped twice between // calls to S_Update. Oh well. samplepos = SNDDMA_GetDMAPos(); if (samplepos < oldsamplepos) { buffers++; // buffer wrapped if (paintedtime > 0x40000000) { // time to chop things off to avoid 32 bit limits buffers = 0; paintedtime = fullsamples; S_StopAllSounds (true); } } oldsamplepos = samplepos; soundtime = buffers*fullsamples + samplepos/dma.channels; }
void S_GetSoundtime( void ) { int samplepos; static int buffers; static int oldsamplepos; int fullsamples; fullsamples = dma.samples / dma.channels; if ( CL_VideoRecording() ) { s_soundtime += ( int ) ceil( dma.speed / cl_aviFrameRate->value ); return; } // it is possible to miscount buffers if it has wrapped twice between // calls to S_Update. Oh well. samplepos = SNDDMA_GetDMAPos(); if ( samplepos < oldsamplepos ) { buffers++; // buffer wrapped if ( s_paintedtime > 0x40000000 ) { // time to chop things off to avoid 32 bit limits buffers = 0; s_paintedtime = fullsamples; SOrig_StopAllSounds(); } } oldsamplepos = samplepos; s_soundtime = buffers * fullsamples + samplepos / dma.channels; #if 0 // check to make sure that we haven't overshot if ( s_paintedtime < s_soundtime ) { Com_DPrintf( "S_Update_ : overflow\n" ); s_paintedtime = s_soundtime; } #endif if ( dma.submission_chunk < 256 ) { s_paintedtime = s_soundtime + s_mixPreStep->value * dma.speed; } else { s_paintedtime = s_soundtime + dma.submission_chunk; } }
void S_GetSoundtime(void) { int samplepos; static int buffers; static int oldsamplepos; int fullsamples = dma.samples / dma.channels; if (CL_VideoRecording()) { float fps = MIN(cl_avidemo->integer, 1000.0f); float frameDuration = MAX(dma.speed / fps, 1.0f);// +clc.aviSoundFrameRemainder; int msec = (int)frameDuration; s_soundtime += msec; //clc.aviSoundFrameRemainder = frameDuration - msec; return; } // it is possible to miscount buffers if it has wrapped twice between // calls to S_Update. Oh well. samplepos = SNDDMA_GetDMAPos(); if (samplepos < oldsamplepos) { buffers++; // buffer wrapped if (s_paintedtime > 0x40000000) // time to chop things off to avoid 32 bit limits { buffers = 0; s_paintedtime = fullsamples; S_Base_StopAllSounds(); } } oldsamplepos = samplepos; s_soundtime = buffers * fullsamples + samplepos / dma.channels; #if 0 // check to make sure that we haven't overshot if (s_paintedtime < s_soundtime) { Com_DPrintf("S_Update_ : overflow\n"); s_paintedtime = s_soundtime; } #endif if (dma.submission_chunk < 256) { s_paintedtime = s_soundtime + s_mixPreStep->value * dma.speed; } else { s_paintedtime = s_soundtime + dma.submission_chunk; } }
/* ================= CL_Changing_f Just sent as a hint to the client that they should drop to full console ================= */ void CL_Changing_f (void) { cl.intermission = 0; if (cls.download) // don't change when downloading return; // stop recording any video if(CL_VideoRecording()) CL_CloseAVI(); S_StopAllSounds (true); cls.state = ca_connected; // not active anymore, but not disconnected // some mods expect aliases to persist across map changes // Cmd_RemoveStuffedAliases (); Com_Printf ("\nChanging map...\n"); }
static void S_GetSoundtime(void) { int samplepos; static int buffers; static int oldsamplepos; int fullsamples; int blurFrames; double msec; fullsamples = dma.samples / dma.channels; //if (CL_VideoRecording(&afdMain) && !(cl_freezeDemoPauseVideoRecording->integer && cl_freezeDemo->integer)) if (CL_VideoRecording(&afdMain)) { //FIXME why no msec check like video? blurFrames = Cvar_VariableIntegerValue("mme_blurFrames"); if (blurFrames == 0 || blurFrames == 1) { //msec = (int)ceil( (1000.0f / cl_aviFrameRate->value) * com_timescale->value ); //s_soundtime += (int)ceil( dma.speed / cl_aviFrameRate->value ); //msec = (int)ceil( dma.speed / cl_aviFrameRate->value ); //msec = ceil( (float)dma.speed / (float)cl_aviFrameRate->value ); msec = ( (double)dma.speed / (double)cl_aviFrameRate->value ); } else { //msec = (int)ceil((1000.0f / (cl_aviFrameRate->value * (float)blurFrames)) * com_timescale->value); //s_soundtime += (int)ceil( dma.speed / (cl_aviFrameRate->value * (float)blurFrames)); //msec = (int)ceil( dma.speed / (cl_aviFrameRate->value * (float)blurFrames)); //msec = ceil( (float)dma.speed / ((float)cl_aviFrameRate->value * (float)blurFrames)); msec = ( (double)dma.speed / ((double)cl_aviFrameRate->value * (double)blurFrames)); } //overf += ceil(msec) - msec; overf += msec - floor(msec); //s_soundtime += (int)ceil(msec); s_soundtime += (int)floor(msec); if (overf > 1.0) { //s_soundtime -= (int)floor(overf); s_soundtime += (int)floor(overf); overf -= floor(overf); } //Com_Printf("sound msec: %lf %d overf: %f\n", msec, (int)ceil(msec), overf); return; } else { if (!CL_VideoRecording(&afdMain)) { overf = 0.0; } } // it is possible to miscount buffers if it has wrapped twice between // calls to S_Update. Oh well. samplepos = SNDDMA_GetDMAPos(); if (samplepos < oldsamplepos) { buffers++; // buffer wrapped //Com_Printf("swap %d\n", buffers); if (s_paintedtime > 0x40000000) { // time to chop things off to avoid 32 bit limits buffers = 0; s_paintedtime = fullsamples; S_Base_StopAllSounds (); //Com_Printf("s_paintedtime (%x) > 0x40000000\n", s_paintedtime); } } oldsamplepos = samplepos; s_soundtime = buffers*fullsamples + samplepos/dma.channels; #if 0 // check to make sure that we haven't overshot if (s_paintedtime < s_soundtime) { Com_DPrintf ("S_Update_ : overflow\n"); s_paintedtime = s_soundtime; } #endif if ( dma.submission_chunk < 256 ) { //Com_Printf("dma.submission_chunk < 256\n"); s_paintedtime = s_soundtime + s_mixPreStep->value * dma.speed; } else { s_paintedtime = s_soundtime + dma.submission_chunk; } }