mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-07 08:21:59 +00:00
Make sdl audio work. And despite claims, it's not actually bad
(except for esd, but that's not sdl's fault). I havn't tested it with other hardware or different config variables, and I've experienced the occasional hang or segfault on exit, so feedback is very welcome. :)
This commit is contained in:
parent
7eb57602a2
commit
0dee26397c
3 changed files with 37 additions and 8 deletions
|
@ -756,6 +756,7 @@ AC_ARG_ENABLE(sdl-audio,
|
||||||
if test -z "$SNDTYPE" -a "x$HAVE_SDL" = "xyes"; then
|
if test -z "$SNDTYPE" -a "x$HAVE_SDL" = "xyes"; then
|
||||||
SNDTYPE="SDL"
|
SNDTYPE="SDL"
|
||||||
SOUND_LIBS="$SDL_LIBS"
|
SOUND_LIBS="$SDL_LIBS"
|
||||||
|
SOUND_CFLAGS="$SDL_CFLAGS"
|
||||||
fi
|
fi
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1188,7 +1189,7 @@ if test "x$optimize" = xyes; then
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
AC_MSG_RESULT(no)
|
AC_MSG_RESULT(no)
|
||||||
CFLAGS="$CFLAGS -O"
|
CFLAGS="$CFLAGS "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AC_MSG_CHECKING(for packet logging)
|
AC_MSG_CHECKING(for packet logging)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
INCLUDES= -I$(top_srcdir)/include
|
INCLUDES= -I$(top_srcdir)/include $(SOUND_CFLAGS)
|
||||||
|
|
||||||
lib_LTLIBRARIES = @SND_TARGETS@
|
lib_LTLIBRARIES = @SND_TARGETS@
|
||||||
EXTRA_LTLIBRARIES = libQFsound.la
|
EXTRA_LTLIBRARIES = libQFsound.la
|
||||||
|
|
|
@ -32,11 +32,13 @@
|
||||||
|
|
||||||
#include <SDL_audio.h>
|
#include <SDL_audio.h>
|
||||||
#include <SDL_byteorder.h>
|
#include <SDL_byteorder.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "QF/cmd.h"
|
#include "QF/cmd.h"
|
||||||
#include "QF/console.h"
|
#include "QF/console.h"
|
||||||
#include "QF/qargs.h"
|
#include "QF/qargs.h"
|
||||||
#include "QF/sound.h"
|
#include "QF/sound.h"
|
||||||
|
#include "QF/sys.h"
|
||||||
|
|
||||||
static dma_t the_shm;
|
static dma_t the_shm;
|
||||||
static int snd_inited;
|
static int snd_inited;
|
||||||
|
@ -47,11 +49,27 @@ extern int desired_bits;
|
||||||
static void
|
static void
|
||||||
paint_audio (void *unused, Uint8 * stream, int len)
|
paint_audio (void *unused, Uint8 * stream, int len)
|
||||||
{
|
{
|
||||||
|
int streamsamples;
|
||||||
|
int sampleposbytes;
|
||||||
|
int samplesbytes;
|
||||||
|
|
||||||
if (shm) {
|
if (shm) {
|
||||||
shm->buffer = stream;
|
streamsamples = len / (shm->samplebits / 8);
|
||||||
shm->samplepos += len / (shm->samplebits / 8);
|
sampleposbytes = shm->samplepos * (shm->samplebits / 8);
|
||||||
// Check for samplepos overflow?
|
samplesbytes = shm->samples * (shm->samplebits / 8);
|
||||||
S_PaintChannels (shm->samplepos);
|
|
||||||
|
shm->samplepos += streamsamples;
|
||||||
|
if (shm->samplepos >= shm->samples)
|
||||||
|
shm->samplepos -= shm->samples;
|
||||||
|
S_PaintChannels (soundtime + streamsamples);
|
||||||
|
|
||||||
|
if (shm->samplepos + streamsamples <= shm->samples)
|
||||||
|
memcpy (stream, shm->buffer + sampleposbytes, len);
|
||||||
|
else {
|
||||||
|
memcpy (stream, shm->buffer + sampleposbytes, samplesbytes - sampleposbytes);
|
||||||
|
memcpy (stream + samplesbytes - sampleposbytes, shm->buffer, len - (samplesbytes - sampleposbytes));
|
||||||
|
}
|
||||||
|
soundtime += streamsamples;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +131,7 @@ SNDDMA_Init (void)
|
||||||
memcpy (&obtained, &desired, sizeof (desired));
|
memcpy (&obtained, &desired, sizeof (desired));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
SDL_LockAudio();
|
||||||
SDL_PauseAudio (0);
|
SDL_PauseAudio (0);
|
||||||
|
|
||||||
/* Fill the audio DMA information block */
|
/* Fill the audio DMA information block */
|
||||||
|
@ -121,10 +140,14 @@ SNDDMA_Init (void)
|
||||||
shm->samplebits = (obtained.format & 0xFF);
|
shm->samplebits = (obtained.format & 0xFF);
|
||||||
shm->speed = obtained.freq;
|
shm->speed = obtained.freq;
|
||||||
shm->channels = obtained.channels;
|
shm->channels = obtained.channels;
|
||||||
shm->samples = obtained.samples * shm->channels;
|
shm->samples = obtained.samples * 4;
|
||||||
shm->samplepos = 0;
|
shm->samplepos = 0;
|
||||||
shm->submission_chunk = 1;
|
shm->submission_chunk = 1;
|
||||||
shm->buffer = NULL;
|
shm->buffer = calloc(shm->samples * (shm->samplebits / 8), 1);
|
||||||
|
if (!shm->buffer)
|
||||||
|
{
|
||||||
|
Sys_Error ("Failed to allocate buffer for sound!\n");
|
||||||
|
}
|
||||||
|
|
||||||
snd_inited = 1;
|
snd_inited = 1;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -140,8 +163,11 @@ void
|
||||||
SNDDMA_Shutdown (void)
|
SNDDMA_Shutdown (void)
|
||||||
{
|
{
|
||||||
if (snd_inited) {
|
if (snd_inited) {
|
||||||
|
SDL_PauseAudio (1);
|
||||||
|
SDL_UnlockAudio ();
|
||||||
SDL_CloseAudio ();
|
SDL_CloseAudio ();
|
||||||
snd_inited = 0;
|
snd_inited = 0;
|
||||||
|
shm = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,4 +181,6 @@ SNDDMA_Shutdown (void)
|
||||||
void
|
void
|
||||||
SNDDMA_Submit (void)
|
SNDDMA_Submit (void)
|
||||||
{
|
{
|
||||||
|
SDL_UnlockAudio();
|
||||||
|
SDL_LockAudio();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue