From 254d5afb32ebe4ba034b0906d6825750783aac63 Mon Sep 17 00:00:00 2001 From: molivier Date: Sun, 11 Jun 2006 14:13:09 +0000 Subject: [PATCH] Fixed audio capture when the sound engine wasn't restarted right before the capture (thanks to FrikaC for reporting the bug) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6466 d7cf8633-e32d-0410-b094-e92efae38249 --- snd_main.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/snd_main.c b/snd_main.c index 53b89724..daa47057 100644 --- a/snd_main.c +++ b/snd_main.c @@ -141,7 +141,7 @@ unsigned int total_channels; snd_ringbuffer_t *snd_renderbuffer = NULL; unsigned int soundtime = 0; static unsigned int oldpaintedtime = 0; -unsigned int extrasoundtime = 0; +static unsigned int extrasoundtime = 0; static double snd_starttime = 0.0; vec3_t listener_origin; @@ -156,6 +156,8 @@ static qboolean sound_spatialized = false; qboolean simsound = false; +static qboolean recording_sound = false; + int snd_blocked = 0; static int current_swapstereo = false; static int current_channellayout = SND_CHANNELLAYOUT_AUTO; @@ -632,6 +634,7 @@ void S_Startup (void) extrasoundtime = 0; snd_renderbuffer->startframe = soundtime; snd_renderbuffer->endframe = soundtime; + recording_sound = false; } void S_Shutdown(void) @@ -1373,9 +1376,30 @@ static void S_PaintAndSubmit (void) newsoundtime += extrasoundtime; if (newsoundtime < soundtime) - Con_Printf("S_PaintAndSubmit: WARNING: newsoundtime < soundtime (%u < %u)\n", - newsoundtime, soundtime); + { + if ((cls.capturevideo_soundfile != NULL) != recording_sound) + { + unsigned int additionaltime; + + // add some time to extrasoundtime make newsoundtime higher + + // The extra time must be a multiple of the render buffer size + // to avoid modifying the current position in the buffer, + // some modules write directly to a shared (DMA) buffer + additionaltime = (soundtime - newsoundtime) + snd_renderbuffer->maxframes - 1; + additionaltime -= additionaltime % snd_renderbuffer->maxframes; + + extrasoundtime += additionaltime; + newsoundtime += additionaltime; + Con_DPrintf("S_PaintAndSubmit: new extra sound time = %u\n", + extrasoundtime); + } + else + Con_Printf("S_PaintAndSubmit: WARNING: newsoundtime < soundtime (%u < %u)\n", + newsoundtime, soundtime); + } soundtime = newsoundtime; + recording_sound = (cls.capturevideo_soundfile != NULL); // Check to make sure that we haven't overshot paintedtime = snd_renderbuffer->endframe; -- 2.39.2