Re: [hatari-devel] SDL1 vs. SDL2 sound pausing

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Le 10/09/2016 à 17:45, Thomas Huth a écrit :
Am Sat, 10 Sep 2016 17:03:16 +0200
schrieb Jerome Vernet <vernet.jerome@xxxxxxxxxx>:

Le 10/09/2016 à 16:09, Nicolas Pomarède a écrit :
printf ( "audio cbk %d %d\n" , nGeneratedSamples ,
CompleteSndBufIdx )
You're right, nGeneratedSamples == 0 while in menus (or in other
thing, before emulation can be paused), and CompleteSndBufIdx stay on
the same value until the release the menu.

I guess we should simply mute audio completely if nGeneratedSamples is
0. Jerome, could you please try a patch like this:

diff -r b98a852e12f2 src/audio.c
--- a/src/audio.c	Sat Sep 10 17:39:20 2016 +0200
+++ b/src/audio.c	Sat Sep 10 17:43:52 2016 +0200
@@ -87,7 +87,13 @@
 		CompleteSndBufIdx += len;
 		nGeneratedSamples -= len;
 	}
-	else  /* Not enough samples available: */
+	else if (nGeneratedSamples == 0)
+	{
+		/* No samples - that could mean that the main thread has been
+		 * halted. Simply mute audio to avoid annoying audio loops */
+		memset(pBuffer, 0, len * 4);
+	}
+	else  /* Some, but not enough samples available: */
 	{
 		for (i = 0; i < nGeneratedSamples; i++)
 		{

Hi

I was thinking at a similar patch, but I think we should completely remove the case that mirror half of the data if we don't have enough sample ; I'm not sure that duplicating previous data will give better audio result if we don't fill Buffer fast enough, we should as well just put 0 bytes in Buffer to complete it (which will have the extra effect of silencing audio output in the case of the OSX UI)

for example :

        if (nGeneratedSamples >= len)
        {
		[keep same code]
	}
	else
        {
                for (i = 0; i < nGeneratedSamples; i++)
                {
*pBuffer++ = MixBuffer[(CompleteSndBufIdx + i) % MIXBUFFER_SIZE][0]; *pBuffer++ = MixBuffer[(CompleteSndBufIdx + i) % MIXBUFFER_SIZE][1];
                }

		/* Clear rest of buffer */
		int remaining = len - nGeneratedSamples;
		memset(pBuffer, 0, remaining * 4);

                CompleteSndBufIdx += nGeneratedSamples;
                nGeneratedSamples = 0;

        }

Nicolas



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/