2004-12-09 23:37:29 +00:00
|
|
|
#include "quakedef.h"
|
2004-12-24 08:45:56 +00:00
|
|
|
#include "winquake.h"
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
|
|
|
|
#define SOUND_BUFFER_SIZE 0x0400
|
|
|
|
|
2005-06-14 04:52:10 +00:00
|
|
|
static void SSDL_Shutdown(soundcardinfo_t *sc)
|
2004-12-09 23:37:29 +00:00
|
|
|
{
|
2005-06-14 04:52:10 +00:00
|
|
|
Con_Printf("Shutdown SDL sound\n");
|
|
|
|
SDL_CloseAudio();
|
|
|
|
Con_Printf("buffer\n");
|
|
|
|
if (sc->sn.buffer)
|
|
|
|
free(sc->sn.buffer);
|
|
|
|
sc->sn.buffer = NULL;
|
|
|
|
Con_Printf("down\n");
|
2004-12-09 23:37:29 +00:00
|
|
|
}
|
2005-06-14 04:52:10 +00:00
|
|
|
static unsigned int SSDL_GetDMAPos(soundcardinfo_t *sc)
|
2004-12-09 23:37:29 +00:00
|
|
|
{
|
2005-06-14 04:52:10 +00:00
|
|
|
sc->sn.samplepos = (sc->snd_sent / (sc->sn.samplebits/8)) % sc->sn.samples;
|
2005-01-12 08:38:31 +00:00
|
|
|
return sc->sn.samplepos;
|
|
|
|
}
|
|
|
|
|
2005-06-14 04:52:10 +00:00
|
|
|
//this function is called from inside SDL.
|
|
|
|
//transfer the 'dma' buffer into the buffer it requests.
|
|
|
|
static void SSDL_Paint(void *userdata, qbyte *stream, int len)
|
2005-01-12 08:38:31 +00:00
|
|
|
{
|
2005-06-14 04:52:10 +00:00
|
|
|
soundcardinfo_t *sc = userdata;
|
|
|
|
|
2005-01-12 08:38:31 +00:00
|
|
|
if (len > SOUND_BUFFER_SIZE)
|
|
|
|
len = SOUND_BUFFER_SIZE; //whoa nellie!
|
2005-06-14 04:52:10 +00:00
|
|
|
if (len > SOUND_BUFFER_SIZE - sc->snd_sent)
|
2005-01-12 08:38:31 +00:00
|
|
|
{ //buffer will wrap, fill in the rest
|
2005-06-14 04:52:10 +00:00
|
|
|
memcpy(stream, sc->sn.buffer + sc->snd_sent, SOUND_BUFFER_SIZE - sc->snd_sent);
|
|
|
|
len -= SOUND_BUFFER_SIZE - sc->snd_sent;
|
|
|
|
sc->snd_sent = 0;
|
2005-01-12 08:38:31 +00:00
|
|
|
} //and finish from the start
|
2005-06-14 04:52:10 +00:00
|
|
|
memcpy(stream, sc->sn.buffer + sc->snd_sent, len);
|
|
|
|
sc->snd_sent += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *SSDL_LockBuffer(soundcardinfo_t *sc)
|
|
|
|
{
|
|
|
|
SDL_LockAudio();
|
|
|
|
return sc->sn.buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SSDL_UnlockBuffer(soundcardinfo_t *sc, void *buffer)
|
|
|
|
{
|
|
|
|
SDL_UnlockAudio();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SSDL_SetUnderWater(soundcardinfo_t *sc, qboolean uw)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void SSDL_Submit(soundcardinfo_t *sc)
|
|
|
|
{
|
|
|
|
//SDL will call SSDL_Paint to paint when it's time, and the sound buffer is always there...
|
2004-12-09 23:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void S_UpdateCapture(void) //any ideas how to get microphone input?
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-06-14 04:52:10 +00:00
|
|
|
static int SDL_InitCard(soundcardinfo_t *sc, int cardnum)
|
2004-12-09 23:37:29 +00:00
|
|
|
{
|
2004-12-24 08:45:56 +00:00
|
|
|
SDL_AudioSpec desired, obtained;
|
|
|
|
|
2005-06-14 04:52:10 +00:00
|
|
|
if (cardnum)
|
2005-01-12 08:38:31 +00:00
|
|
|
{ //our init code actually calls this function multiple times, in the case that the user has multiple sound cards
|
|
|
|
return 2; //erm. SDL won't allow multiple sound cards anyway.
|
|
|
|
}
|
2005-06-14 04:52:10 +00:00
|
|
|
|
2005-01-12 08:38:31 +00:00
|
|
|
Con_Printf("SDL AUDIO INITING\n");
|
2005-02-09 19:32:09 +00:00
|
|
|
if(SDL_InitSubSystem(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE))
|
2004-12-24 08:45:56 +00:00
|
|
|
{
|
2005-09-26 08:07:26 +00:00
|
|
|
Con_Printf("Couldn't initialize SDL audio subsystem\n");
|
2004-12-24 08:45:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&desired, 0, sizeof(desired));
|
|
|
|
|
|
|
|
desired.freq = sc->sn.speed;
|
|
|
|
desired.channels = 2;
|
|
|
|
desired.samples = SOUND_BUFFER_SIZE;
|
|
|
|
desired.format = AUDIO_S16;
|
2005-06-14 04:52:10 +00:00
|
|
|
desired.callback = SSDL_Paint;
|
|
|
|
desired.userdata = sc;
|
2005-01-12 08:38:31 +00:00
|
|
|
|
|
|
|
|
2004-12-24 08:45:56 +00:00
|
|
|
if ( SDL_OpenAudio(&desired, &obtained) < 0 )
|
|
|
|
{
|
|
|
|
Con_Printf("SDL: SNDDMA_Init: couldn't open sound device (%s).\n", SDL_GetError());
|
|
|
|
return false;
|
|
|
|
}
|
2005-01-12 08:38:31 +00:00
|
|
|
sc->sn.numchannels = obtained.channels;
|
2005-11-01 23:25:15 +00:00
|
|
|
sc->sn.speed = obtained.freq;
|
2005-01-12 08:38:31 +00:00
|
|
|
sc->sn.samplebits = 16;
|
|
|
|
sc->sn.samples = SOUND_BUFFER_SIZE;
|
2005-06-14 04:52:10 +00:00
|
|
|
sc->sn.buffer = malloc(SOUND_BUFFER_SIZE*sc->sn.samplebits/8);
|
2005-01-12 08:38:31 +00:00
|
|
|
Con_Printf("Got sound %i-%i\n", obtained.freq, obtained.format);
|
2004-12-24 08:45:56 +00:00
|
|
|
SDL_PauseAudio(0);
|
2004-12-09 23:37:29 +00:00
|
|
|
|
2005-06-14 04:52:10 +00:00
|
|
|
sc->Lock = SSDL_LockBuffer;
|
|
|
|
sc->Unlock = SSDL_UnlockBuffer;
|
|
|
|
sc->SetWaterDistortion = SSDL_SetUnderWater;
|
|
|
|
sc->Submit = SSDL_Submit;
|
|
|
|
sc->Shutdown = SSDL_Shutdown;
|
|
|
|
sc->GetDMAPos = SSDL_GetDMAPos;
|
|
|
|
|
|
|
|
return true;
|
2004-12-09 23:37:29 +00:00
|
|
|
}
|
2005-01-12 08:38:31 +00:00
|
|
|
|
2005-06-14 04:52:10 +00:00
|
|
|
sounddriver pSDL_InitCard = &SDL_InitCard;
|